Localization is the process of making your apps work with multiple languages.

This is surprisingly a lot simpler than it sounds, and is achieved by calling special functions and through built-in Xcode support.

Download the starter project to begin.

Localizing Strings

The first step in localizing an app is to separate all the text from the code. We will move all hard-coded strings to a special .strings file. You should name this file Localizable.strings so that your app knows where to look for it. Otherwise, you’ll have to add an entry to your .plist file.

The format for each entry in the file is "Key" = "Value";.

You can then read and use this data in your app using the NSLocalizedString macro.

You can now localize this file for the English language.

  1. Select the Localizable.strings file from the Project Navigator (on the left).
  2. Click on the Make localized… button in the File Inspector (on the right).
  3. Select English as the initial localization from the menu that pops up.

Repeat the process for the hello.jpg file.

If you examine the project files in the Finder, you will notice that both files have been moved inside a folder called en.lproj. You can localize your app in 40 languages, each identified with a 2-letter code.

You can add a French localization to the app from the project’s Info tab.

Xcode will ask you which files to include in the new localization. Select all but the Storyboard.

This will copy the selected files into an fr.lproj folder.

Rename allo.jpg to hello.jpg, and replace the version in fr.lproj.

Back in Xcode, you will notice that you can now edit two versions of the localized files. Replace the contents of Localizable.strings by their French counterparts.

You can now run your app on a French language device, and it will automatically load the correct text and resources.

You can also localize the app name by adding an entry for the CFBundleDisplayName key of the InfoPlist.strings file.

Note that sometimes changes won’t load while testing because of caching issues. Make sure to delete the app from the Simulator and to clean the project in Xcode if you encounter any refresh problems.

Comments are closed.