Make your iOS App Multilingual (Localization)

Anjali Joshi
4 min readMar 5, 2022

You would like to support your app with different languages. For this, in iOS we have a concept called Localization. In this article, we will learn to implement Localization in our app using Swift.

Prerequisites

  1. macOS
  2. XCode

So, let’s begin by creating a new project in XCode. Click on iOS->App/Single View App->Next.

Name your project and select the language as Swift. Select a desired location and click on Create.

To start with Localization, click on your Project Name -> go to Info Tab -> Under Localizations, click on the ‘+’ button.

Add the Languages, that you would like your App to support. I am going to add French and German to my project.

Once you select the language, a similar kind of popup will appear. Check both the checkboxes (Main.storyboard and LaunchScreen.storyboard) and click on Finish.

Now, in Project Navigator you can see different files under Main.storyboard and LaunchScreen.storyboard. Also, in File Inspector, under Localization section select all the languages that you had added in the Info tab.

Now, we will create a new .Strings file. For that, right-click on your Project -> New File -> search for ‘strings’ -> Select Strings File -> name the file as Localizable.strings -> Create.

NOTE: Name the file as Localizable.strings only.

Once the Strings file is created, click on the Localizable.strings file and in the File Inspector, click on the Localize button.

On clicking the Localize button, a similar popup will appear. Click on Localize.

Now, go to File Inspector again and under Localization, select all the languages that you had added.

This will create different Strings file for different languages under Localizable.strings file. We will be adding keys and their values to these files.

Now create a UI in Main.storyboard. In my project, I have used a UIPickerView to select a language and based on the language selected, I’m displaying title and data.

After you create your UI, go to Localizable files and create some keys and assign the values to the keys that you will be displaying on your UI.

NOTE: Use the same keys in all the Localizable.strings files.

Refer the below code snippets and add the sentences that you will be displaying on your UI in a key-value type.

Paste in Localizable.strings file — English
Paste in Localizable.strings file — French
Paste in Localizable.strings file — German

As you can see in all the above code snippets, I have kept the keys as “title” and “info”. Its important to keep the keys same in all the files as that will be used to fetch the sentences from the Strings files.

Now go to ViewController.swift file. Here, we will first create an extension of String.

We have created the above extension to reduce number of lines in the code. The above code will search for the ‘lproj’ directory which contains the Localizable.strings file as per the language selected.

Next, we will create a function as shown below. Paste the code in ViewController.swift file.

In the above function, I’m assigning the data fetched from the keys to lblTitle and txtInfo respectively. As per the language selected, the data will be fetched from Localizable.strings file and will be assigned based on the keys.

Finally, we will call this function changeLanguage as per the language selected. I have created different buttons for the different languages.

UI Designed in Main.storyboard

Below is the entire ViewController.swift file for your reference.

Entire ViewController.swift file

Now, we are good to run the project. Run the project and change your app into different languages!

English
French
German

--

--