tutorial

How easy is it to localise^ your iOS or macOS apps using Get Local? I'd say it is fairly easy, and in a few steps you'll have as many localisations in your app as you want!

In this tutorial, I've set up a demo app which has a title, a button, and some descriptive text.

Demo app code
Demo app code

Inside the Project Settings > Info you can see there is only Base and English localisations.

Project Settings > Info > Localisations
Project Settings > Info > Localisations

Exporting your xcloc localisation file

  1. Go to the MenuBar > Product > Export Localizations...
  1. Xcode will prompt you for a location to save your exported localisation files
  1. Once exported, you will see the en.xcloc file in the directory

Translating with Get Local 🎉

  1. Download Get Local from the Mac App Store and open it
  1. Drag the en.xcloc file into the window, or select Open file and navigate to it from the window
  1. Select from over 100 target languages - we'll choose French for this example
  1. Because our original en.xcloc file has target translations, we can press the Clear Text button to empty the column of the selected items. Confirm the clear on the confirmation box
  1. Press Translate and instantly see all the selected rows translate into your selected language
  1. Press Export all to save all the translated text ready to import into Xcode

You will see an exported .xliff file. It is prefixed with get-local and the ISO country code
eg. get-local-fr.xliff

Importing your xliff localisation file

  1. Go to the MenuBar > Product > Import Localizations...
  1. Xcode will prompt you to select your .xliff file
  1. Inside the Project Settings > Info you will see your newly localised language

Seeing the imported localisation

  1. In the Navigator pane you will see .strings files. These are the key to value representation of your translations
  1. If you want to do a quick little edit, you can do it here

Somethings wrong...

Sometimes when we're building our apps we forget about localisation until the end. When this happens, we often forget to look at some of the computed variables or functions that output to Strings.

As a result, when we localise our app, these do not get translated.

In our example app, we had a computed property called timesWordPlural which would output the word time or times depending on the number of button taps.

Changing String to LocalizedStringKey

  1. Let's first look at the issue code lines where we are using a String return

We'll change that into something better:

// change from this:
var timesWordPlural: String {
  numberOfTimesTapped == 1 ? "time" : "times"
}

// to this:
var timesWordPlural: LocalizedStringKey {
  numberOfTimesTapped == 1 ? "time" : "times"
}
  1. Because we were using StringInterpolation, we need to break our text up into an HStack
  1. Now we need to re-localise our text so we can include the words time and times
  1. Export your localisation just as you did before - MenuBar > Product > Export Localizations...
  1. Select the ouput location. You don't have to select all the target languages since Get Local can translate from any source to target language
  1. Once exported, you will see the new en.xcloc file in the directory
  1. Re-import it into Get Local, and this time you will see there are two extra items for time and times
  1. Translate it again into your target language, and re-import it into Xcode (I won't bore you by showing that again)
  1. Once completed, you will see that the .strings files have been updated. It now has the extra translations

Testing your localisations

As important as it is to localise your apps, so is testing them.

  1. Bring up the Edit Scheme... menu. You can do this by:
    1. Option + click on the run button - that is, ⌥ + click on the ▶︎ button;
    2. Go to Product > Scheme > Edit Scheme... from the MenuBar; or
    3. Command + Shift + , - that is ⌘ + ⇧ + ,
  1. Change the App Language from System language to one of the languages you have localised into
  1. Press Run and see your app operate in the desired language

If you made it this far

I hope this tutorial shows you how easy it is to localise your apps and that Get Local should be an essential part of your development toolkit.

Download on the
Mac App Store

Footnote

^ Note that I'm from Australia so I use localisation (with an "s" not a "z"). So anytime I may use an "s" instead of a "z" just forgive me 🥺