Exporting and importing localization files for translators in Xcode

Let Xcode find localization strings and compile them into files for easier translation

Jianyuan Chen
4 Minute Swift
4 min readMay 11, 2021

--

Localization illustration by Esther from Pexels

Xcode had evolved a lot, making it easier than ever to make your app support multiple languages. This post will focus on exporting and importing localization files using Xcode and assumes you have enough knowledge about the process of localization or internalization.

If you need more information on implementing localizations, here are my article recommendations:

  1. Long and thorough: Internationalizing Your iOS App: Getting Started from raywenderlich.com (25-minute read)
  2. Short: Localizations in Swift by Doyen (4-minute read)

Disclaimer:

The content in this article requires you to be familiar with the process of internationalization in Xcode.

Follow any of the articles and you will have learned enough about the processes of making your app support multiple languages.

However, I find them (and many of the other articles online) missing an essential topic: exporting localization string files for translators and importing the translated files back to the project.

The Painful Experience

For example, Doyeon relies on Xcode to generate the string files for both languages (English and Korean) but manually copies the strings in the English strings file to the Korean strings file. The author of the Raywenderlich article adopts the same procedure.

Keeping your language files in sync manually is fine for small projects when you only support 2 languages and your app contains only a few predefined labels. This can quickly get tedious once you start adding more labels and more languages.

The Correct Way

There is actually a lesser-known functionality built into Xcode to simplify the process for us.

All you need to do is use NSLocalizedString for all your strings you wish to support localization:

  1. Select Product -> Export Localization -> Your Target
Choose export for your target

If you can’t find the option, on earlier versions of Xcode, try the following:

  1. Focus on your project and select either the project or Target (This step is very important as the Editor tab will display different options depending on where you are in your project navigator. See picture below)
  2. Editor -> Export Localization

This allows Xcode to automatically find all the strings that you marked as to be localized (both in storyboards and code). You just fill in your development language while you are developing, and no more copy strings in strings files.

2. Then you will be prompted to save the files. Choose the languages you wish to localize. All locales are selected by default.

Choose the language to export

3. Locate the result of the export. Files are in the following structure:

The folder structure represents the locales that you are supporting. Do not change the name of the folder and any of the files, as Xcode relies on them for import later. The files and folder structure are identical for each locale.

File structure after export

Normally, you would develop in one language, and that language will be your development language (see the picture in step 2). The development language does not need to be translated since you already filled in the value as you are developing.

Now, many third-party tools make it easier to work with .xliff files. I’m using a free one XLIFFTool. There are some paid options too which promise better UI and additional features. But if you are just filling in the blanks, XLIFFTool gets the job done at no cost.

4. Open the .xliff file in your xliff editor.

The exact procedure differs by tools. But for XLIFFTool mentioned above, drag the zh-Hans.xliff file onto the XLIFFTool icon and it will open the file automatically.

5. Put your translation in and save the file.

6. Last but not least, find Import Localizations in the Xcode menu.

If you can’t find the option, see step 1 to make sure your Xcode is focused on your project name.

7. Choose the entire folder and click Import.

Run the app and switch the locale of your device to see the change!

--

--