0% found this document useful (0 votes)
29 views1 page

Localize Your Apps To Support Multiple Languages - IOS Localization in SwiftUI by Pranay Patel Simform Engineering Medium

Uploaded by

ppj25ftxk4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views1 page

Localize Your Apps To Support Multiple Languages - IOS Localization in SwiftUI by Pranay Patel Simform Engineering Medium

Uploaded by

ppj25ftxk4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Localize Your Apps to

Support Multiple
Languages — iOS
Localization in SwiftUI
Pranay Patel · Follow
Published in Simform Engineering
5 min read · Aug 4, 2023

Listen Share

Explore the key concepts and steps involved in


localizing your SwiftUI app.

Localization is a crucial aspect of iOS app


development that enables your app to cater to
users from different regions and languages.
In this technical blog post, we will explore the
fundamentals of iOS localization, specifically
in SwiftUI, Apple’s modern declarative UI
framework. We’ll cover the key concepts and
steps involved in localizing your SwiftUI app,
allowing you to create a more inclusive and
user-friendly experience for your global
audience.

Why is it important to support different languages


for iPhone and iPad users?
Well, not everyone who uses these devices
can read or write in English. In this blog, I’ll
demonstrate how simple it is to adapt an app
for different languages using SwiftUI, Xcode,
and the iOS API. But first, let’s understand
what internationalization means.

What is internationalization?
Internationalization, often abbreviated as
i18n (because there are 18 letters between the
“i” and the “n” in the word), refers to the
process of designing and developing
products, services, or software applications to
be adaptable and culturally sensitive for use
in multiple countries or regions. The goal of
internationalization is to ensure that a
product can be easily localized, or
customized, for different languages, cultural
conventions, and market preferences.

SwiftUI simplifies the process of localization


compared to previous frameworks, but there
are still a few steps involved in setting it up.
Here’s an overview of the steps required to
enable localization in a SwiftUI project:

Use base internationalization


1. Open the settings for your Xcode project.

2. Look for the “Localizations” section. It


may be under the “Info” tab or in a
separate “Localizations” tab, depending
on your Xcode version.

Add new language


1. In the “Localizations” section, you should
see a list of the languages currently
supported by your project.

2. To add a new language, click the “+” icon


(usually located at the bottom left or top
right of the language list).

3. A language selection menu will appear,


displaying a list of available languages.

4. Choose the language you want to add


support for by clicking on it. For this
example, I selected the German language.

Add New Language from dropdown list

In this example I added German support

Create localization resources


1. In Xcode, navigate to your project’s file
navigator or project explorer.

2. Locate your project’s folder or group


where you want to store the localization
files. It is common to have a folder named
“Resources” or “Supporting Files” for this
purpose.

3. Right-click on the folder or group, then


select “New File” from the contextual
menu. Alternatively, you can use the
“File” menu at the top of Xcode and select
“New” -> “File.”

4. In the template chooser, search for


“Strings File” or navigate to the
“Resource” section.

5. Select the “Strings File” template and click


“Next.”

6. Name the file Localizable.strings and


choose the appropriate location to save it
within your project. Make sure to select
the targets where you want the file to be
included.

7. Click “Create” to generate the


Localizable.strings file.

8. Xcode will create a default


Localizable.strings file with an empty
key-value pair.

Xcode > File > Strings File

Enable language
1. In the Localizable.strings file inspector
window, click the Localize button in the
right-side menu.

After Adding Localizable file

2. In the right-side part, you have selected a


localization and can see an additional item
named German (as you are selecting).

Before enable German language

3. You have to select German in the


localization part (on the right side).

4. Expand the Localizable.strings item in your


project to reveal the two files
Localizable.strings (English) and
Localizable.strings (German).

After enable German language

Add strings
1. Open the Localizable.strings (english)

file in a text editor or Xcode.

2. Add or update the translations for each


key-value pair in English.

“Welcome” = “Welcome!”;

After adding key-value in Localizable.strings (english)

3. Add the following strings to the


Localizable.strings (German) file:

“Welcome” = “Willkommen!”;

After adding key-value in Localizable.strings (german)

Here is the final code in SwiftUI:

Preview the localizations


This is where SwiftUI becomes really great.
Apple introduced it with environment
variables, one dedicated to region and
language, something that we can play with for
our preview.

To test your application in the preview canvas


with a specific language, you can add the
environment() modifier to the ContentView

and set the language identifier to "de" for


German.

Test localizations
Below are the two ways in which we can test
the localizations:

Changing the language on an iOS simulator


or physical iOS device

Open the “Settings” app on your iOS


device or simulator.

Scroll down and tap on “General.”

Tap on “Language & Region.”

Tap on “iPhone Language” (or “iPad


Language”).

Choose “English” or “German” from the


available languages.

Confirm the language change when


prompted.

Close the “Settings” app.

Launch your app, and it should now be


running in German.

Changing the language in Xcode

Click the active scheme from the toolbar


and select Edit Scheme.

Edit Scheme

Run > Options > Application Language, select


the language you want to debug.

Select Application Language

This is the output when testing it:

final output video

Conclusion
In this blog post, we explored the basics of
iOS localization in SwiftUI. We covered the
essential steps involved in preparing your
project for localization, creating localization
resources, and localizing SwiftUI views. By
leveraging SwiftUI’s built-in localization
support, you can create a more accessible and
inclusive app for users worldwide.

For more updates on the latest tools and


technologies, follow the Simform Engineering
blog.

Follow Us: Twitter | LinkedIn

957 1

Localization Swiftui Multilingual

IOS Swift

957 1

Follow

Written by Pranay Patel


16 Followers · Writer for Simform Engineering

Sr. Software engineer (iOS developer)

More from Pranay Patel and Simform Engineering

Ujas Majithiya in Simform Engineering

How to Find Memory Leaks in Flutter


Apps?
Mastering memory management with DevTools to
discover memory leaks in Flutter

7 min read · Apr 2, 2024

1.2K 7

Arshit Moradiya in Simform Engineering

Monitoring Made Simple: Empowering


Spring Boot Applications with…
Prometheus and Grafana
Learn how to configure and use Prometheus and
Grafana to collect metrics from your Spring Boot…
app and visualize them in various ways.
6 min read · Jul 6, 2023

314 3

Aesha Shingala in Simform Engineering

Spring Boot caching with Redis


Implementing Caching in Spring Boot Application
Using Redis

8 min read · Aug 4, 2023

665

Jay Sheth in Simform Engineering

How to implement SSR(Server Side


Rendering) in React 18
Learn how to implement the
“renderToPipeableStream” server API to render a…
React tree as HTML to a Node.js stream.
5 min read · Sep 15, 2023

825 4

See all from Pranay Patel

See all from Simform Engineering

Recommended from Medium

Ahmed Iqbal in Level Up Coding

Localization in SwiftUI
Hey all, this is a quick walkthrough of implementing
localization in SwiftUI for both LTR and RTL…
languages.
3 min read · Dec 7, 2023

1 1

Mansoor Ali

App Localization in iOS (String


Catalog)-Part 1
App Localisation has become very easy with string
catalogs in Xcode 15.

4 min read · Jan 5, 2024

Lists

Apple's Vision Pro


7 stories · 68 saves

Tech & Tools


16 stories · 225 saves

Icon Design
36 stories · 301 saves

Productivity
241 stories · 429 saves

You might also like