Strings File
Dan Tobias (Talk | contribs) |
Dan Tobias (Talk | contribs) |
||
Line 32: | Line 32: | ||
[[Category:Macintosh]] | [[Category:Macintosh]] | ||
[[Category:iOS]] | [[Category:iOS]] | ||
+ | [[Category:Development]] |
Revision as of 22:31, 16 March 2016
A strings file is used in Mac OS X or iOS apps for localization of text. There can be several versions of the strings file for different languages, and the program code of the app references named strings from that file instead of the literal string values, so the actual text can change based on the user configuration.
There are several different formats this file can take. They can be encoded as Property Lists (with a dictionary as the top-level node, and the name/value pairs of the strings file as its entries), or they can be stored in a "native" strings-file format consisting of name/value pairs as follows:
"NMSTR" = "Name"; "DTSTR" = "Date";
The names and values are each enclosed in double quotes (the straight ASCII variety), and separated by an equal sign. The line is ended with a semicolon. Extra whitespace outside the quotes is ignored. Also, comments enclosed in /* and */ are ignored (they may span multiple lines).
Strings can then be referenced within Objective-C code by using:
NSLocalizedString(@"NMSTR", nil)
(using the name of the desired string) in place of a literal string.
Within OS X apps (inside the .app "file", which is actually a directory and contains multiple items, though the Mac Finder treats it as a single file), you may find .strings files named Localizable.strings or InfoPlist.strings in the Resources subdirectory, or in multiple subdirectories for different-language localizations if there are any. These are stored in the UTF-16 character encoding (so if you open them in a viewer/editor not supporting UTF-16, they may appear to have blank spaces in between characters, since ASCII characters end up having two-byte encodings in which one byte is null (00) and the other is equal to the ASCII value). They are little-endian, with a Byte Order Mark (U+FEFF, which shows up as the bytes FF FE) at the beginning. Line breaks are done with linefeed (U+000A).
Within iOS apps, the structure and filenames are similar, but the format is Property List/Binary.
When you are building a project for either an OS X or iOS app in Xcode, the editing of .strings files is done in UTF-8 in the native name/value format described above (at least in the default configuration; this is configurable to other character encodings and to the different line-break conventions of CR, LF, or CRLF); the files are then converted to the appropriate format for the target platform when the app is built.