Everything About iOS Localization

Why localize your app

Because it can increase your app download by 128%, according to Distimo report.

It is a fact: English is only the third largest language (after Chinese and Spanish). And there is around 1 billion people who speaks English.

Don’t ignore others.

Start using NSLocalizedString

If you are using a string that will be displayed to your user, always use the macro NSLocalizedString.

1
NSLocalizedString(@"some string", nil)

Then genstring

Thereafter, you can easily extract all the string to a .strings file.

find . -name "*.m" | xargs genstrings -o tmp

In your project, under Info > Localizations, add a new language.

Replace with the strings file generated.

Plural Support

New in Foundation, you can have a .stringsdict file alongside the .strings.

Refer to the section on Localized Property List File.

The dict looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>%d files are selected</key>
    <dict>
        <key>NSStringLocalizedFormatKey</key>
        <string>%#@[email protected] selected</string>
        <key>num_files_are</key>
        <dict>
            <key>NSStringFormatSpecTypeKey</key>
            <string>NSStringPluralRuleType</string>
            <key>NSStringFormatValueTypeKey</key>
            <string>d</string>
            <key>zero</key>
            <string>No file is</string>
            <key>one</key>
            <string>A file is</string>
            <key>other</key>
            <string>%d files are</string>
        </dict>
    </dict>
</dict>
</plist>

Upper/Lower Case

In NSString, you should use uppercaseStringWithLocale: and lowercaseStringWithLocale: methods instead.

Formatting Dates

In NSDateFormatter, you should use dateFormatFromTemplate:options:locale: instead.

Refer to the documentation. Displaying dates is much harder than you think, with the punctuation and ordering all different.

The right locale

The current system locale is [NSLocale currentLocale].

But sometimes your app only is supporting certain locale, and you want the presentation to be consistent. In that case, you should use:

1
2
NSString *localization = [NSBundle mainBundle].preferredLocalizations.firstObject;
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:localization];

You might also want to know when the locale has changed.

1
2
3
4
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(localeDidChange)
                                             name:NSCurrentLocaleDidChangeNotification
                                           object:nil];

Test on Simulator

To test, you can go to Settings app in simulator to change the language.

Or if you prefer faster way, you can set the launch arguments in Scheme > Run > Arguments, and add the following:

-AppleLanguages (zh-Hans)

The above will start the simulator in Chinese Simplified. Edit the language accordingly such as es, ko, de

Third Party Services

There are mnay services that provides translations. Apple even has a list of vendors.

I recommend: OneSky

This is because:

  • they have a free management tool that is the best (can even add screenshots)

  • it’s free to to use their crowdsource up to 5 collaborators

  • their charge of 0.10 USD/word is comparable to others

I would use OneSky to ask my friends and users to help in translation.

Google API

It’s usually terrible to translate using Google API. They probably can only get 50% right.

The other 50% is either grammatically wrong, or assumed wrong context.

But if you still want to, you can use the REST API at $20 per 1 million characters.

Or use poeditor which comes with free 10,000 character.

Or manually use the Google Translate web for free.

Comments