Apple’s mobile operating system iOS has experienced extraordinary global growth over the last years, so much so that according to Apple, there are now over 150 countries where the iOS App Store is available and there are more than 40 languages that iOS devices support.
Internationalization (i18n) is the process of making your app adaptable to different languages and cultures. Localization (l10n) in iOS, on the other hand, is the process of translating your app into multiple different languages for a particular locale.
Note » Oftentimes developers—iOS developers in particular—use both of these terms—Internationalization and Localization—interchangeably, but in reality, both are different but interconnected concepts.
Therefore, we’ve divided this tutorial-based article into two subsections:
- Internationalization in iOS
- Localization in iOS
Did you know? » Internationalization and Localization are often abbreviated to i18n and l10n respectively. The 18 in i18n represents the number of characters in-between “i” and “n” of Internationalization, whereas the 10 in l10n represents the numbers of characters in-between “l” and “n” of Localization. Fancy stuff, no?
Before going deep into the subsections mentioned-above, let us first have a look at some required steps.
In this section, we will be familiarizing ourselves with the required steps to perform i18n and l10n in an iOS application.
You will require the following tool:
- Xcode (Latest version). Right now, I am using Xcode 9.
Programming Language (iOS)
We are going to do programming using the following language:
Before doing internationalization and localization practically, you need to first decide what regions (locales) you want to target, and what languages those regions have. This preliminary step is crucial to target your audience. In this article, I am going to use English as the base language, French, Chinese (Traditional), and German as the other languages for localization. You can add as many languages as you want in your app depending on your requirements and your target audience. The steps for adding other languages would exactly be the same.
Term to know » Regions or countries are referred as locales, especially when we deal with internationalization and localization. Wherever you find the word “locale”, it simply means a certain country or a region. Bookish term, no?
Now that we have discussed these basics, it is the time to dive into the subsections mentioned before.
Internationalization (i18n) in iOS
As I mentioned before, i18n is the process of making your app adaptable to different locales. From an iOS developer’s perspective, it is the process of making strings externally editable—be it in a storyboard or in code. Furthermore, in order to set dates, numbers etc. according to the respective locale, you have to use different build-in classes. For example, we can use the “formatting” class to format the dates according to the region, numbers according to preferred language and so on. For now, we are going to use the simple setup to get used to of the internationalization process.
Recommendation » Always do Internationalization and Localization steps after completing the design and the coding part of your application. Why? Because Xcode will save most of your time by adding strings automatically in the localizable files. If you do these steps before writing the code for your application, you have to manually add all of the strings in their designated files (for localization). Bottom-line is that you should do all the steps of internationalization at the very end.
You, an iOS developer, need to take the following steps in order to internationalize your app:
Setting-up the project for i18n
Once you make a new project, or you have an existing application that you want to internationalize, make sure that you have the property named “Use Base Internationalization” checked in the project info settings (as shown below) in Xcode:
As you can see in the above picture, there are three boxes: red, black and blue.
- From the Navigator panel, you should first select the root file (.xcodeproj) of your project (in red box shown above).
- Select the type project. As you can see, there are two options available. Targets is the default option. You need to change it to Project (in the black box shown above).
- Make sure to check the option “Use Base Internationalization” option (in the blue box shown above).
What is “Use Base Internationalization” in Xcode? » Upon creation of the new project, Xcode automatically generates files related to localization. When you check Use Base Internationalization option, Xcode transfers the Main.storyboard and LaunchScreen.storyboard into the “Base.lproj” folder for the default language. Our Base language in the tutorial is English, as mentioned in the Decisions section.
Once you have done this basic step, you need to add different languages that you want your application to support. In this tutorial, we are going to use three languages—French, Chinese (Traditional) and German—for localization representing different locales, as discussed in the Decisions section. Let us add the support for these three languages!
Adding Languages for Localization
In order to add languages in your application for Localization (l10n), you need to go to the project Info settings again, and click the “+” button (as shown below):
Xcode will present you the list of languages you want to localize for. Let us choose French first! Upon selecting any language (in our case French), Xcode will ask you to choose files and reference language to create your desired language localization (French, in our case) as shown below:
In the above picture, two things require your attention:
- Reference Language—the Base language in which we have designed our application, which is by-default English (leave it as is!).
- File Types—make sure that all files are set to Localizable Strings.
Furthermore, as you can see there are two storyboards—Main.storyboard and LaunchScreen.storyboard—which we are going to make localizable since we have selected both. Click Finish!
Changes in the Project after Language Support
Upon adding support for the French language localization, you will see the following three changes in your project files:
- Xcode will create a folder named “fr.lproj” in your project since we have added support for the French language.
- In that folder, Xcode will create two string files associated with the storyboards that we have selected in the previous step.
- The third change, however, depends upon when you add localization support to your application. If you followed my recommendation mentioned at the top regarding when to internationalize and localize your application, you would see the labels (if any) presented in your Main.storyboard and LaunchScreen.storyboard will be given the Object-IDs and added to the Main.strings and LaunchScreen.strings files.
We have only one label “Hello” in Main.storyboard, and LaunchScreen.storyboard is empty. It means that we must have one “Hello” object in Main.strings (French) file as well with an object-ID as shown below:
The left half of the image shows the user interface (in Main.storyboard), which contains only one label, whereas the right half shows the string file associated with it.
Add Chinese (Traditional) and German languages as well by following the aforementioned steps.
Now we are going to look at the localization part of the application.
Localization(l10n) in iOS
Localization, in iOS, is basically the translating process. There are two methods you can use to translate your application.
- Directly in the Xcode (by the developer)
- Exporting Localizable Files (in XLIFF format) for translators
Let’s discuss both of these methods one by one!
In the Internationalization part, we have generated “Main.strings” localizable files for different languages (as shown below), and they all contain one label with the text “Hello.” Now go through each of the localizable string files and change the text “Hello” into the respective file’s language.
In our case, the LaunchScreen.storyboard does not contain any element, and hence it would be empty.
The translated file(s) would look like this:
Now if you preview the application by setting your iOS-device’s locale to either one of these languages, you would get the translated user-interface (as shown below):
Exporting Localizable Files for translators
In this method, we shall see how to export localizable files for the localizers (translators). To do so, first create a separate folder for l10n (as shown below):
As you can see, there are two folders within “L10n” folder. “To Localizers” is the folder, where we, being the developers, export our localizable files for translators. “From Localizers” is the folder, from where we would import the localized files from translators to our project.
After creating the folders, go back to the Xcode project and open the Project’s Info settings again. Make sure you are on the Info Settings page in order to get the “Export for Localization” option in the Editor’s menu.
Now from the Editor’s menu, click “Export for localization” as shown below:
Once you clicked the “Export for Localization” option, Xcode will ask you to save the localizable files to your specified folder as shown below:
As you can see in the above picture that all the three languages are selected and will be exported to the “To Localizers” folder in XLIFF format—XML Localization Interchange File Format.
Being a developer, your job is done here! Now you have to wait for the translators to translate the strings present in XLIFF files and send you back in the same format. Once you receive the translated XLIFF files, you should import them into your project using the same Editor’s menu(shown above), but this time, select “Import Localizations” option.
Recommended Method for Internationalization (i18n)
The first method—Within Xcode—in Localization (l10n) section apparently seems nice and dandy, but let us ask ourselves three basic questions:
- Do we, being the iOS developers, really have a command over the languages of all the locales that support Apple Services?
- Can we depend on Google Translator services for the precise translations?
- Any less time-consuming and more efficient solution?
The answer to the first question is definitely No! I can speak only four languages. How many languages do you speak? Comment down below!
Before giving you my perspective about Google Translator services, let me share a translation with you using Google Translator:
I am not a German speaker; therefore, you can take me as a test-case here. Now, I wanted to translate “Ready! Set! Go!” in German, and I got the result from Google Translator! YAY! But all of a sudden, I thought, “Why shouldn’t I reverse translate it?” Lo and Behold! We get the following translation (from German to English):
“To adjust?” Really? Confused? Hence, for the professional applications, you should not be dependent upon such services.
Now you must be wondering, “If not Google Services, then what?”
Here comes the answer to the third and the final question. Wouldn’t it be better if we would have an access to the native translators of different locales all at one place for precise translations? Wouldn’t it be awesome if you only need to export XLIFF files without worrying about the translation process? Well, PhraseApp can make your life easier! It does support XLIFF files and provides a comprehensive and developer friendly translation management solution. Learn more about PhraseApp’s Guides here and then jump right into PhraseApp’s Getting Started guide for iOS.
I hope this article helps you get the ball rolling and makes you confident about adding iOS Internationalization and Localization in your application. There is much more to cover; but for now, I’m saying goodbye… until we meet again!