Localizations in Swift

Doyeon
doyeona
Published in
4 min readMay 8, 2021

Have you ever wondered how to make an app which supports multiple languages for people who live in different countries? will you type every single text for them? Here’s what we called a Localization to help us translate an app into multiple languages.

But before localizing an app, we should first need to understand about Internationalization. Internalization is the process of making the app able to adapt to different languages, regions, and cultures.

what apple document says: Xcode supports localization for an app. First we internationalize the user interface and code during development. Then test the app using pseudolocalization and different region settings. When you are ready, export the localizable text using standard file formats.

sources: apple documentation

Localizing Your App

Let’s open an Xcode and get started!

1️⃣ Create String File and name it Localizable.strings

2️⃣ Click Localize on the right panel, and it will look like the right image below.

3️⃣ On the Project, find the Localizations section and click the plus icon to add languages that you want as the image below.

4️⃣ When you click the finish button, then you’ll see these files created below.

5️⃣ What we need to do is to type the text into each of the string files created. The format should be something like “text” = “text”

⚠️ Don’t forget to put semicolon at the end of the text else it will cause you an error.

string files for Eng and Kor

6️⃣ For us to test it, let’s quickly make a label and connect it to the ViewController. In viewDidLoad, or wherever you’ll be needing it, type this single line of code:

label.text = NSLocalizedString(“Hello”, comment: “first greeting word”)

7️⃣ When you run it, it will automatically give you translated words depending on your iPhone’s language setting.

Settings 👉🏻 General 👉🏻 Language & Region 👉🏻 iPhone Language

So when my iPhone’s language is in English, and Korean looks like below.

8️⃣ Doing it directly from Storyboard. Get the Object ID from the storyboard and open up Main.storyboard, and open Main.strings (Korean).

Add new keyframe something like below: “ObjectID.property” = “text”;

--

--

Doyeon
doyeona

Passionate iOS developer creating extraordinary apps. Innovative, elegant, and collaborative. Constantly pushing boundaries.Let's build the future together📱✨🚀