Localizing String Resources

An important part of the localization process is to localize all of the text strings displayed by your application. Strings located in nib files can be readily localized along with the rest of the nib file contents (as described in “Preparing Your Nib Files for Localization”). Strings embedded in your code, however, must be extracted, localized, and then reinserted back into your code.

Resource files that contain localizable strings are referred to as strings files (with the deliberate extra 's' in the word "strings") because of their filename extension, which is .strings. You can create strings files manually or programmatically depending on your needs. The standard strings file format consists of one or more key-value pairs along with optional comments. The key and value in a given pair are strings of text enclosed in double quotation marks, separated by an equal sign, and terminated by a semicolon. (You can also use a property list format for strings files. In such a case, the top-level node is a dictionary and each key-value pair of that dictionary is a string entry.) Although the inclusion of comments is optional, they do provide a useful way to communicate contextual information to the translator about how each string is used. Listing 1 shows a simple strings file with two non-localized entries for the default language.

Listing 1  A simple strings file

/* Insert Element menu item */
"Insert Element" = "Insert Element";
/* Error string used for unknown error types. */
"ErrorString_1" = "An unknown error occurred.";

A typical application has at least one strings file per localization, that is, one strings file in each of the bundle’s .lproj subdirectories. The name of the default strings file is Localizable.strings but you can create strings files with any file name you choose.

To make the maintenance of your code easier, there are tools in OS X that you can use to extract the strings from your iPhone or Mac apps and put them into strings files. For detailed information about how to create strings files using these tools, and how to prepare your code to use the strings those tools generate, see “String Resources” in Resource Programming Guide.