How To Internationalize an OS X/iOS App
To increase the user base, and thereby boost profits, all developers must localize their applications for iOS or OS X into multiple languages: users don’t buy and don’t use an application written in a language they don’t understand.
Making the app able to be localized to a specific market is called internationalization, and that's the topic of this article.
Step 1: Embed every literal string within the macro NSLocalizedString
We need to pull all of the hardcoded strings into a separate file so we can localize them. To do that, simply change all literal strings like this:
NSString *string = @"This is a sample string";
to this:
NSString *string = NSLocalizedString( @"This is a sample string", @"A comment for the translator");
NSLocalizedString
is a macro part of the Foundation Framework. It takes two parameters: the first one is the string which must be translated, written in the neutral language (typically English). The second parameter is a comment, i.e. an aid for the translator indicating the context where the string is used. That argument can actually be set to nil
(as it is optional), but it is always a good idea to write short texts that help the translators.
You should do this with every string a user sees.
Step 2: Create an empty Localizable.strings
for each language
Localizable.strings
is the default name for the resource files that contain the localizable strings.
To create the Localizable.strings
file in Xcode:
- Click File > New > File...
- Select “Resource” on the left
- Select “Strings File” on the right
- Name the file “
Localizable.strings
” - Select the file in the Xcode Project Navigator
- In the Utilities panel change the text encoding to “Unicode (UTF-16)”
- In the Utilities panel click on “Make localized...”
- Select “English” in the new window
- Click the “+” button under Localization, and select the languages you want to support
You should now see as many files as there are languages under the “Localizable.strings
” file:
Step 3: Extract the strings to translate
Now you can use the command line tool genstrings
, but we created a great app that simplifies the whole string extraction process. It's called Localizable Strings Merge and is available in the Mac App Store.
To fill the Localizable.strings
files:
- Drag and drop all the source files (or directly the folder containing the project) on the left side of Localizable Strings Merge:
- Drag and drop all the
Localizable.strings
files (or directly the folder containing the project) on the right side of Localizable Strings Merge:
- Now click on the button “Merge Strings”.
You've generated your Localizable.string
files!
Step 4: Translate the strings
Now, you have to translate every Localizable.string
file in the language to which it refers.
If you open a Localizable.strings
file you can find many lines like:
/* A comment for the translator */ "This is a sample string" = "This is a sample string";
As you can see the file consists of one or more key-value pairs along with optional comments. The key and the value is in double quotes followed by a semi-colon. The keys should be left unchanged, while values need to be translated:
/* A comment for the translator */ "This is a sample string" = "Questa è una stringa di esempio";
That's all! Now you have a multilingual application.
[…] See on http://www.delitestudio.com […]