Localization in Swift (support multi language)

Amna Ahmed
3 min readNov 7, 2020

what is localization?

is a process of making your app support multiple languages.

First lets start with static elements in main storyboard

Storyboard Localization

Simple login Screen before and after localization

1- Choose language

after add your localized language for me (Arabic (ar) language)

xcode allow you to choose files and reference language to create localization .

by default will create localized file for

1-Main.storyboard

2-LaunchScreen.storyboard

2- Edit Main.strings file (translate words)

Before change to localized text
After change to localized text

3- Test your application

if your run application in simulator you need to change system language to localized language in my case it will be Arabic.

if you run application in your device you also need to change your device language to test application

open simulator Run options
change simulator language

Now you are ready to run your app ^_^

what if i want to add a new localized object to storyboard?

in this case you all you need to go to Main.strings
“ObjectID.property” = “text”

in Main.strings

as we see this way used with static data, what about dynamic data?

NSLocalizedString for Localization

dynamic way to use localization can used with (Alert-data from API-dynamic text or text than depend on code … etc )

Let’s see simple example with lable and you can apply the same way with different cases.

We will use the concept of key and value pairs you can access the string using a key.
“key” = “value”

Let’s start
1- Create Localizable.strings file

this file will contain key and value of string

File > New > File

now you will see empty file called Localizable.strings
you need localizable file for each language Xcode will create them for you all you need to do select Localizable.strings file will choose language in that way

2- Select Localizable languages

After check localization language X-code will generate file for each language.

3- Edit each file

All you need to use the same key in all files but with appropriate value according language

Localization.strings(English)
Localization.strings(Arabic)

4- Use in my code (NSLocalizedString)

now you can use dynamic localization and test it.

--

--