Apple logoLocalizing Your iOS App

You’ve built your app and released it in English only. It’s now time to localize the app and make it available in a number of different languages around the world.

There are essentially 2 areas that you need to translate in order to successfully market your app in the non-English speaking countries of the world.

Marketing Content
  • App Store Description
  • Keywords
  • Supporting Website
The App
  • User Interface
  • Help

The following sections describe how to prepare your app for translation. They will describe how to set up your Xcode project so that the entire user interface, including error messages, can be translated into multiple languages.

At the end of the exercise, you will have learned how to prepare your app so that it can be translated into any language. In addition to showing you how to localize the user interface, we’ll also explain how to translate your app name.

1. Externalizing strings

Hard-coded strings such as error messages and UI elements must be externalized from your class file in order to translate your app. Xcode provides a macro called NSLocalizedStrings() which works with a file called Localizable.strings to facilitate the externalization and localization of these strings.
  • Open your Xcode project.
  • If you do not have a file called Localizable.strings, you need to create one.
    • Choose New File from the File menu.
    • Choose Resource -> Strings File
  • Name the file Localizable.strings and store it in the root of your project.
  • Select Localizable.strings in the Project navigator.
  • Click on the File Inspector for Localizable.strings.
  • Look in the Localization panel.
  • If the panel displays “No Localizations”, click on the “+” button to make the file localizable. English will now appear in the list of languages.
  • Click on the “+” button and Chinese.
  • Localizable.strings is now set up for translation.

Now you need to externalize all of the localizable content from your class files into the file Localizable.strings.

  • Open any class file that contains content to be translated.
  • For every string literal in the file, you need to wrap the string with a call to the macro NSLocalizedString()
  • There are 2 approaches you can take as to how you manage the externalization and maintenance of these localizable UI strings
  1. Use the actual value of the string as the key in the file Localizable.strings. This will allow you to use the tool genstrings() supplied as part of Xcode to externalize the strings from your files.
  2. Replace the text in your file with a hand-generated key, and then create a key-value pair in Localizable.strings with the new key and the localizable.text.

Using genstrings()

  • Identify the text in your class file to be externalized
  • Wrap this text with a call to NSLocalizedString()
In the following function, the name of a tab bar item is initialized. The name is hard coded into this function.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
 if (self) {
 self.title = @"Flags";
 self.tabBarItem.image = [UIImage imageNamed:@"flags"];
 }
 return self;
}

To properly internationalize this code and make it localizable, use the macro NSLocalizedString() to wrap the localizable text.

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
 if (self) {
 self.title = NSLocalizedString(@"Flags", "Home button in the tab bar");
 self.tabBarItem.image = [UIImage imageNamed:@"flags"];
 }
 return self;
}
  • Note that LocalizedString(key, comment) takes 2 paramaters
  • key = the name of the key in Localizable.strings that will be loaded when the call is invoked
  • comment = developer comment that is used to convey context to the translator, and to other developer who will work on your code
Once you have wrapped all of your string literals with calls to NSLocalizedString(), you can use the genstrings() tool to extract all of the localizable content from your class files and create the key-value pairs in Localizable.strings

2. Making files localizable

 

  • Open your Xcode project.
  • Select an XIB file you wish to localize.
  • Click on the File Inspector for the file chosen.
  • Look in the Localization panel.
  • If the panel displays “No Localizations”, click on the “+” button to make the file localizable. English will now appear in the list of languages.
  • Click on the “+” button and pick Chinese (or whatever language you are interested in).
  • Your XIB file is now set up to be localized into Chinese.
  • Repeat the steps above for each of the XIB files in your project.
  • In the example project, there are 2 localizable XIB files – Home.xib and Flags.xib
  • Both files are now ready for translation into Chinese
  • You can also use the steps above to make any image files or sound files localizable.
Once all of your files are set up to be localizable into any one language, it is very easy to make all of these files localizable into other languages.
  • In the Project navigator, select your project.
  • Select your app name in the Project panel.
  • Expand the Localizations panel in the Info section.
  • You will see English and the language chosen in the steps above listed under the Language column.
  • The number of files that you made localizable will also be displayed.
  • To add further languages for all files in the project, simply click on the “+” button and choose all languages that you are interested in.
At this stage, all of the localizable files in your project should be set up correctly, with all of the appropriate languages chosen. The next step in the process will be to externalize all of the localizable text from the source code and make this localizable also.

 

3. Localizing app name

When a user switches their language on an iOS device, not only does the UI of the app change, but the name of the app also changes if it has been localized. To set up your project so that the app name can be localized, do the following 
  • Open your Xcode project.
  • If you do not have a file called InfoPlist.strings, you need to create one.
    • Choose New File from the File menu.
    • Choose Resource -> Strings File
    • Add the file InfoPlist.strings to the root of your project

  • The new empty InfoPlist.strings file appears in the project
  • Add the following entry to this file:
CFBundleDisplayName = "Demo";
  • Now make this file localizable by clicking on the Make localized… button in the Localization panel under the File Inspector
  • You will be prompted to prompted to pick the source language for this file
  • Pick English
  • The Localization panel will now look as follows
  • Note that Chinese is displayed in the list because we have already set up other files in this project to be localized into this language
  • Enable Chinese localization for this file by clicking on the checkbox next to the language name
  • You have now made InfoPlist.strings localizable into Chinese, and English
  • To change the name of the app that shows up on the iOS device for all English locales, you simply edit the value for CDBundleDisplayName in the English version of InfoPlist.strings
  • To localize the name of the app for Chinese locales, you translated the value of CFBundleDsiplayName in the Chinese version of InfoPlist.strings
will result in
The Chinese translation below
will result in