Menu

How To Localize

Christa Runge

How To Manage Localized Strings

The API function NSLocalizedString takes two string parameters:
(1) The key is a unique identifier for a specific string to be localized. Placeholders for variables are supported and should show the correct datatype (e.g. %d,%@, etc). We generally follow the convention to use the English form of the string, which keeps the source code readable, and has the nice side effect that we don’t need to spend extra effort for the English translation. However, in some cases a distinction is needed; e.g. the English form for two strings is identical, but in some other language the strings are different.
(2) The comment is free text, it should give the translator enough context to do his work. If the same string (same key) is referenced more than once in our source, it should be the same comment (although this is not strictly required).

See details in the iOS API documentation.

Extract the strings for translation

Apple provides the utility genstrings to extract all NSLocalizedStrings into a language file. We have wrapped this utility with the shell script extract_strings.sh and the perl script merge_string_files.pl.
Call

./extract_strings.sh 

from the iPhone project directory.
This will extract the strings for localisation, merge them with the already translated language files, and add our copyright header as is given in the shell script.
You may ignore the warnings that some keys are referenced with multiple comments.

Format of the language files

Each language file has the name Localizable.strings and is located in a folder xx.lproj under the karatasi folder, where xx is the language code. We currently support English (en), German (de) and Czech (cs).
The strings in the language files are sorted by key, which keeps them synchronized between all supported languages.
The comment is given as comment; in case of multiple comments for one key, all comments are given.
The key is followed by the translation.
Formatting codes for a single parameter are given directly (e.g. %d, %@, etc).
In case of multiple parameters, an indicator for the order is added.

Example:

/* startup counter */
"%d of %d" = "%1$d von %2$d";

We see the comment in the first line, the key with two placeholders for variables in the second line before the = , and the translation with the two placeholders and the order indicators in the second line after the = .
Strings which are no longer referenced are commented, and will later be collected at the bottom of the file, so that the translation is not lost.

Translate the strings

All new strings which were added in the source code after the initial translation must be translated, or the localization key will be used as default translation.
Note for the translator: our tooling assumes that the language string files are encoded as UTF-16.

Add another language

Just copy the folder en.lproj, rename it to the desired new language, and translate it.

Note: Do not check-in the temporary files Localizable.strings.tmp, Localizable.strings.utf8 and Localizable.strings.old.utf8.
We recommend to configure them as svn ignore.


Related

Wiki: How To ...