doyeona
Published in

doyeona

Localizations in Swift

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”;

When you run it, it will work just the same as earlier steps.

Plus, when internalizing it, you can also set numbers, date, time, currencies & units, and other things depending on your iPhone setting. For more details, check out these links below.

--

--

--

Daily study logs about iOS development will be updated. Any recommendations or discussions are always welcome

Recommended from Medium

Ruler and Compass (02)

A Deep Dive Into SwiftUI Previews

A smartphone screen displaying a number of apps.

Image Cropping in Swift

Getting Started With IOS App SwiftUI — Part 1

UI Gesture Recognizer in iOS App Development

What’s New in iOS 14 — For Developers

The numeral 14 against a colored background

VIPER Architecture Implementation in Swift

CS193p Notes — Lecture 14: UIKit Integration

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Doyeon

Doyeon

Hey! I am currently studying iOS by myself, and wanna be a cool app developer 🕶 please correct me if i’m wrong or if there’s any thing that you wanna share😊✌️

More from Medium

Link old Xcode with the new SDKs

Variable Definition, Arrays, Dictionaries and Set Structures in Swift

Content Hugging & Content Compression Resistance Priority [iOS — CHCR priorities]

Swift Closures