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.
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.
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.
Localizing Your App
When you are done internationalizing the app's user interface and code, begin the localization process. Export all the…
Internationalizing Your iOS App: Getting Started
In this tutorial, learn how to prepare your app to support multiple languages, including regional numeric formats…