How to Quickly Add and Use Localization to your SwiftUI Projects

Mark Moeykens
May 29, 2021

Do you want to support more than one language for your SwiftUI app?
It's easier than you think!

Step 1 - Add A New Language

  • In Xcode, click on your root project.
  • Then click on the PROJECT (not TARGET).
  • There's a section called "Localizations". This is where you want to add a second language in addition to what is already there. In my case, my development language is English.

For this example, I'm going to add German:

Step 2 - Add A Localization File For Your Translations

  • Add a new file to your Xcode project
  • Scroll down to the "Resource" section and select the "Strings File" template.
  • Name the file "Localizable.strings".


Step 3 - Add Your Translations

Before you do anything else, add some text you will need to get started on your first view in your project.

The format is:
"Key"="Value";

For example:
"hello.world"="Hello, World";

(Don't forget the semi-colon at the end.)


  • The key is the part you use in your code and the value is the part that will be displayed on the screen.

Step 4 - Auto-Generate All Language Strings Files

  • Xcode can auto-generate the extra files you need for you.
  • Select your Localizable.strings file.
  • Show the File inspector page on the right side.

Click the "Localize..." button and select "German" from the modal popup.

And finally, make sure both languages are selected:


You can see that the Localizable.strings is now a group that contains two different languages:


Step 5 - Add the Translations

If you select the "Localizable.strings (German)" file, you will notice it looks like an exact duplicate of the English file. That's because it is!

This is why you want to try to get all of your original language keys and values added. When you localize the strings file, Xcode will duplicate the original file so all you have to do is update the values.

Update the English values with German values:


Step 6 - Reference the Keys in SwiftUI

You will notice SwiftUI controls that show strings will usually have a parameter called "LocalizedStringKey". This is the key from your Localizable.strings files.

For example, this is what you might see when adding a Text view:


And here is what you might see adding a Button view:


Step 7 - Preview the Different Languages

You can also add a modifier to your preview view to see it displayed in a different language.

In this example, I'm also adding a display name of the language:


Here is how the preview looks in English:

And here is the same view in German:


Pretty simple, right?
So what will be the next language you add to your app?

By: Big Mountain Studio - Your source for SwiftUI reference materials