Localize your Apps to Support Multiple Languages — iOS Localization
Why do we need to support multiple languages? Because not all iPhone and iPad users read or write in English. In this blog, I will show you, how easy it is to localize an app and make it available in multiple languages by using Xcode and iOS API.
Localization is a process of making your apps to support multiple languages. Xcode has build-in support for localizations. Some people think localization is just doing translation, that’s correct, but localization also includes other elements like image, sound, etc. Also, you have to handle display formats of different numerical values, date and time.
Before starting the localization work, make sure you Internationalize your app.
What is Internationalization?
Internationalization is the process of making your app adapt to different languages, regions and cultures. Because a single language can be used in different parts of the world and your app should adapt to the regional and cultural conventions of where a person resides.
Use Base Internationalization — separates user-facing strings from .storyboard
and .xib
files.
Adding New Language
Add new language support using, click “+” button under Localizations section in Project Info tab. Then choose a language you want to support.
Here we are adding Russian support.
Now, you can see the new language in the .storyboard
Exporting Texts for Translation
Now we have to export the texts that we used inside the application for translation. For this, we have an option inside the Editor Menu.
The texts used in the storyboard will automatically be exported. For the texts used inside the controllers, we have to change the strings with the NSLocalizedString method. once we have changed the strings with NSLocalizedString, Xcode will automatically create a file called Localizable.strings for the text that are used inside the controllers.
In the result of export for localization, we will get a .xliff (XML Localisation Interchange File Format) file for translation. There are a lot of online services that we can use for translation and edit the .xliff file. also, we have Mac apps that are used for xliff file editing. ex:- Xliff Editor
Once you get the translated .xliff file from translator you can easily import to the project using Import Localization option inside Editor menu.
Localize strings
Additionally, we should get our code ready for localization. First, we need to separate user-facing text from code using the NSLocalizedString macros. In this example, I obtain localized strings for the alert title, message, and buttons.
let localizedTitle = NSLocalizedString("Welcome", comment: "")let localizedContent = NSLocalizedString("Thanks you for download this app", comment: "")let alert = UIAlertController(title: localizedTitle, message: localizedContent, preferredStyle: .alert)alert.addAction(UIAlertAction(title: NSLocalizedString("Ok", comment: ""), style: .default, handler: nil))self.present(alert, animated: true, completion: nil)
Test Your App
Testing your app with localization using a variety of techniques, during development and after localization.
- In Interface Builder, preview the user interface using pseudolanguages.
- Run the app using different pseudolanguages.
Preview the localizations
After you import localizations, you can preview the localization using interface builder
Run the App
How do you test if the localized strings are displaying correctly? You can of course manually switch the language of your simulator or device, but there’s an easier way.
Click the active scheme from the toolbar and select Edit Scheme
Run > Options > Application Language , select the language you want to debug
That’s all!!!
Check out sample project on my Github repo.
If you have any questions, let me know in comments. If you find it useful, please clap 👏🏻 for recommendations 😊