Localization for swift

demo

Open Xcode and click on File->New->Project… to create a new project, choose Single View Application.

Select Swift for the language project and name it as you want, personally I called it “LocalizationTutorial”

Click on your project icon (the blue icon) in your directory hierarchy on the left hand side, to “Info”.

localization-1

Now click on the “+” button in the “Localizations” section and select the language you want to add to the project.

When you got this screen, choose the default files listed and click Finish.

localization-2

Alright, since now our project is synchronized with different languages, we have to create the files which will contain the different translated copies for our app.

Localizable.strings

Go to File->New->File… and add a new Strings File.

localization-3

Call this file “Localizable.strings”.

Select this file in the project folder and click on “Localize…” in the Localization section (in the right utility panel).

localization-4

Then, select English in the localization drop down.

Now if you click on the Localizable.strings file you should be able to see that the Localization section has been updated.

Each selected language item will create an alternative version of the file for this language. You got it, you have to select “English” and the other(s) language(s) you want to use in your app.

Localizable.strings (English)

Localizable.strings (Chinese (Simplified))

Create StringExtension.swift

ViewController

How to Run

Click the button to switch languages and display the Hello World string in different languages.