Have Xcode compile Localized .strings files in binary format?

I noticed that my .strings files are compiled in my app in plain text, with my comments and whatnot still in there.


If I inspect an app like Safari and look at the .strings files on that bundle, the file is in binary format.


Is there a way I can Xcode compile .strings in binary format on release builds?

Accepted Reply

Check out the Strings file Output Encoding build setting (

STRINGS_FILE_OUTPUT_ENCODING
). It defaults to
binary
for iOS projects and
UTF-16
for macOS ones.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Replies

The Safari .strings files not "in binary" AFAICT. They appear to be text files (you can view them in TextEdit) in UTF-16 rather than UTF-8. How did you decide they were "in binary"?

There are some .string files that I cannot read in a text editor...until I convert them with plutil into XML format.....


they appear to be in the binary property list format...that's how I decided

If you read carefully here:


developer.apple.com/library/prerelease/content/documentation/Cocoa/Conceptual/LoadingResources/Strings/Strings.html


you'll see that you're supposed to create .strings files as text files (currently UTF-8 preferred, but UTF-16 was preferred in the past), but that the text file is a plist representation (the other representations being binary and XML). You may well be able to use a binary plist in your project directly, or to add a plist-conversion phase to your target, but it's not clear what's truly supported.


It's also possible that Apple reserves the binary plist form of .strings for its own use.


It ought to be possible, in current versions of Xcode, to never create .strings files manually at all, but let Xcode extract the localizable strings from your source code. AFAIK, it can do this both for Swift and Obj-C, without your needing to run genstrings any more. In that case, you can limit your profane comments to your source code, and your users will be safe.

Check out the Strings file Output Encoding build setting (

STRINGS_FILE_OUTPUT_ENCODING
). It defaults to
binary
for iOS projects and
UTF-16
for macOS ones.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

That's what I was looking for. Thanks!