If you want to make worldwide-known app available in dozens of countries you should adapt your app to different languages. It is much more convenient for user to have app in his/her native language.
I want to share how to improve your iOS localization process.
Part I: Add Internationalization to your project
Enabling Base Internationalization
First off all, you should enable project localization.
- In the
Project Navigator, select the project
- Check on
Use Base Internationalization
After that you can add new languages by tapping
"+" icon (above “Use Base Internationalization”)
- Create New String File named Localizable (
File Inspector(right panel) click on
It’s your Localizable.strings file for Base language.
The syntax of this file is:
So now it’s a time to improve our localization handling!
Part II: Localizable Management
For using a localized string programmatically, you should use the
In brief, by calling the key programmatically
NSLocalizedString func returns the localized value.
But for managing all localized strings we need more type-safe approach that helps to avoid calling hardcoded strings.
First of all,
Split all localized strings by pages or by meaning, and create an enum for each part
Secondly, create LocalizableDelegate protocol which we will use in enums:
LocalizableDelegate has 3 variables.
table is the name of table where to search specific key.
localized returns a value by
rawValue located in the
table. By default
table is nil, it means that the
localizedString method attempts to use the table
The next step, is to adopt
You can use specific file for each
ViewController. In this case you have to declare
Example of usage:
I have created
Localizable enum containing all
- Type-safe approach that helps to avoid calling hardcoded strings;
- Manage all localized strings from one place;
- Simplified change of localizable value;
- You can refer to one localized string from more than one enum.
Thanks for reading.
I hope these iOS localization tips can help you improve your workflow.
You may check my apps.
If you have any questions or found any errors, please drop me a line!
Written with ❤️ by Rita