Categories

Preparing your iOS app for localization in Xcode

Since Xcode 5, Apple has enabled by default something called base internationalization. Here's how it works.

Introduction to Base Internationalization

The idea behind base internationalization is to extract the text a user sees in your app from Interface Builder and other resources. All of those buttons names and text labels need to be translated, after all. Each piece of text is placed in a simple text format called a .strings file. Base internationalization helps collect those texts from .storyboard and .xib files. You can also include images and other resources that you may want to localize. Xcode moves or duplicates all of these resources into a Base.lproj folder in your project. It also creates separate folders for each language you want to translate into in order to store the localized version of these resources.

Enabling Base Internationalization in Xcode 6

Turn on Base Internationalization.
Recent versions of Xcode turn on base internationalization by default, but let's just make sure your project is using it. Select your project in Xcode's file navigator. (Make sure you're looking at the Project, not the target, and that the Info panel is highlighted blue.) This is the screen to verify or enable base internationalization, there at the bottom.

Add any resource files you plan to localize into your Base.lproj folder. When you check the Base Internationalization checkbox the first time, Xcode will ask which resources to use as well as your default language (usually English). Xcode will create a Base.lproj folder if it isn't already there, and add any resource files you select. It also creates a language folder for the development language (for English, it's called en.lproj).

Add languages using the menu command Editor > Add Localization. Or right from the Info panel, press the button and choose the language you want to add. Xcode will again ask which resources you plan to localize, and create a [language code].lproj folder for each.

Finally, enable Auto Layout in your views. Why? Other languages are going to take up either less or (more likely) much more space than your current language. German words take up about 30% more room than English, and Chinese takes about 15% less. Eliminate all fixed origins, widths, and heights in your views so that the localized text can reflow automatically when the language or locale changes. Auto Layout is enabled by default since Xcode 5 for new projects, but for existing projects you can enable it for any view. See also: Apple's Auto Layout Guide.

Hint: Add more resources at any time using the File inspector. Just press the button or check the boxes for the languages you'd like. This is useful if you want to include a localized image for a PNG file that has some text in it, for example, or perhaps you want to show a particular country's flag based on the user's language.

Note: Xcode will actually create a .strings file for each and every .xib resource. Xcode includes many placeholders that say "Label" and "Button" that you probably never intended to pay a translator to translate! Consider deleting these from the final files you send your translators.

Extract your hard-coded app strings for iOS localization

Xcode's Base Internationalization not only helps you get the xibs, but also the hard-coded strings using the NSLocalizedString macro.

Change hard-coded strings to NSLocalizedString.

Not every text a user sees comes from your .storyboard or .xib files, of course. What about those error messages and user prompts that are buried inside your code? Xcode can help you externalize your coded texts for iOS app localization too.

Any string your user will see needs to be wrapped in the NSLocalizedString macro. Let's begin by making sure your coded strings are ready for iPhone localization. That means changing:

Always include a helpful comment for the translators. Since you will need to add the NSLocalizedString call to every string a user sees, take an extra moment to tell the translators what this string is for. Remember, they'll be seeing it totally out of context and your helpful hint here is all they have! Knowing that a text is a title or a button, a noun or a verb, can be very helpful.

Advanced users: Xcode 6 has decided to hide the Localizable.strings file for your English strings by default. This seems to be what Apple meant by "implicit .strings" files in the Xcode release notes. While you see the Localizable.strings file for, say, your French translation in the fr.lproj folder (only AFTER you import the French XLIFF file), the English one is not in the en.lproj folder.

You can, however, change this behavior by creating your own Localizable.strings file, or using the helpful
genstrings
command. Open
Terminal
and navigate to your project's home directory. Then run this command:
find . -name \*.m | xargs genstrings -o en.lproj

This creates a strings file called Localizable.strings that extracts all NSLocalizedString calls into a single file in the en.lproj localization directory. You can then modify the .strings file directly, and it will be exported along with the XLIFF file. This is useful if you want to use keys instead of the full English string. Do NOT rename Localizable.strings files. Otherwise Xcode won't find them.

Use Xcode's handy import/export localization features

Xcode 6 embraces the XLIFF format for handing off to your translation team

Importing and exporting localizations with XLIFF

At runtime, your iPhone or iPad app is going to use the text inside those strings files you created to swap out English text for the translations. But instead of sending dozens of .strings files to your translation team, Xcode 6 adds a quick export function that creates a single XLIFF file for each language. (XLIFF is a standard XML-format supported by most translation software, including ours.)

In the Save window that appears, choose to Include Development Language Only if you are sending your English file for translation. If you have existing translations you also want to send to your translators, choose Existing Translations, and choose from the list of available languages.

And, voilà. Your app will soon speak enough French to understand the word "voilà!" You have all the files you need to send to your iPhone localization team!

Your translators should return to you one file for each language using the language code as its name. That is, for French you'll receive an fr.xliff file, for Chinese, you'll get back something like zh-Hans.xliff.

Import the files back into Xcode using the menu command Editor > Import Localizations…. Xcode will display a window with the differences between your existing files and the ones your translators have sent you. Press the Import button to finish.

Pseudolocalization — testing you've found every string

Inventing your own language to spot mistakes.

Once you've finished preparing your .strings file you're probably having doubts that you actually managed to find every hard-coded string in your app. What about those error messages or that plug-in you use? Well, there is a quick way to check. It's called pseudolocalization.

Essentially, you use a program to substitute all the English (source) phrases with a fake language. Load up this gibberish Localizable.strings file into Xcode and then run your app. Check every screen and make sure all the text appears as the pseudo-localized text rather than your original. If you can't spot any missing strings, you're good to go.

Tip: Pseudolocalization is also a great way to make sure you've left enough room in your GUI for other languages. A common rule of thumb is that non-English languages are 30% longer, so tiny buttons and titles may not fit when you localize. Pseudolocalization can help you spot those cramped spaces too!

What to send to the translator

You've generated your .strings files, both from Interface Builder and coded strings from Xcode, and those go to the iPhone localization team you hire. That's not everything, though. You'll definitely want to have your app description for the App Store localized as well. Since iTunes Connect will also ask you for keywords, make sure you come up with a list of keywords for your translation team to localize. This ensures that users in other languages will find your app when searching their localized version of the App Store.

iPhones and iPads are multilingual out of the box, so your app's interface will appear localized for the user automatically.

Budget localizations using a free App Localization Cost Calculator

Now that you have all your text ready for translation, you're probably wondering how many words you have and how much that will cost to translate. Use Babble-on's free iPhone app localization cost calculator to find out.

Multilingual iOS application iPhone localization examples

Talk to a real translator.

Interested in professional iPhone localization from a team that cares about making apps awesome? Unlike automated or cloud translation services which will translate your "bold" text as brave and "Archive" as a noun without considering it might be a verb, Babble-on is a dedicated team of translators that put as much care into localization as you do into app development.

You can talk to us about your project the whole way through, not just upload your strings and cross your fingers.

Tips for how to localize your iOS app

Localize iOS apps into the right languages

Using iTunes Connect, you've probably already noticed users from all over the world downloading your app. How many more users can you get by translating and localizing your iOS app into another language? Into two, or more? Once you've created the .strings file using the tutorial above, it's very simple to localize your iPhone or iPad app for the iOS App Store.

Is your App Store description going to sell?

Writing a description of your app for the App Store description is often difficult for even the best developers. How do you make your app sound great without sounding like a door-to-door salesman? How will the description translate when you localize your iPhone app, and are there any issues to consider for new markets? Babble-on helps developers with both the copywriting and translation, so we know this subject very well. Ask us for help.

Tell your users in their language.

A user can set their preferred language by going to Settings -> General -> International -> Language. Once the language is set, the iPhone/iPad will display all text, including the app's name on the home screen, in the user's local language.

Professional iOS localization

We love iPhone and iPad apps and are excited to help you localize your projects and test them in multiple languages. Whether you need your iPhone app localized into Spanish, Japanese, Russian or any other language, Babble-on is ready to help.