Mobile apps are used all over the world. When you develop a mobile app, you have to think about your audience and what languages they understand. It is important that your users understand your app without any language barrier.

Not all your users may understand English, so to make your app helpful for those users who don’t understand the English language, you may consider adding support for other languages. If a user doesn’t understand your app because of a language barrier, it is called a disability.

Add support for multiple languages

Adding support for multiple languages is easy and can be done with just a few clicks. Open your project in Xcode and add a new strings file to your project. Name the file ‘Localizable.strings’, because with that name the iOS system automatically recognizes the file as a language file.

Add a Strings file to your project and name it Localizable.strings.
Add a Strings file to your project and name it Localizable.strings.

Enabling different languages

You can add a lot of different languages, like Dutch or Spanish. Adding them is easy, select your project in the project navigator, click on your project and on the info tab the languages that are currently supported are displayed. Press on the + button to add a new language. A popup may display which files you want to translate, just press finish and you’re done!

Open your Localizable.strings file in the file inspector. On the tab localization, click on ‘Localize…’ and select which language the Localizable.strings file currently is. After that, you’re able to select different languages in the file inspector.

In the project navigator, you will see that the Localizable.strings file can be unfolded after selecting multiple languages.

The Localizable.strings file can be unfolded after making it multi-language.

There are some languages that read right-to-left, like Arabic. When you add support for the Arabic language, your app will automatically add support for right-to-left alignment and gestures. If you don’t add support for the Arabic language, Arabic users are only able to use your app in left-to-right alignment, which is a bad user experience for them.

Translate your app

You can add the translations for each language in the Localizable.strings file. Each line in the strings file contains a key, following with the translated text. Every line must be closed with a semicolon.

Example

"label_hello" = "Ola!";

You are now able to use the key in your code to display the text in the correct language to the user. This can be done using NSLocalizedString. Adding a comment is required by Apple and is needed for documentation, but can be an empty string if you don’t want to use it.

Example

label.text = NSLocalizedString("label_hello", comment: "")

The object NSLocalizedString is a bit cumbersome, so most developers are using an extension on a string.

extension String {
    var localized: String {
        return NSLocalizedString(self, comment: "")
    }
}

When adding the extension above to your codebase, the localization of keys is much cleaner visible in code.

Example

label.text = "label_hello".localized

Conclusion

Supporting multiple languages is very easy with Xcode by adding a strings file and add all translations to that file. Using the string extension you get a better overview of keys that are used in the code.

Always name your strings file Localizable.strings, because otherwise, the translations won’t be visible.

🚀 Like this article? Follow me on Twitter for more iOS related news!

Categories:iOS