Localize Swift Tutorial

Creating an App for multiple languages? Let us make this easy!

It is really important to enable your App for multiple languages. By using Localize you can ensure that your App will maximize it’s

Prerequisites:

  • Some basic knowledge of creating iOS Apps

Terminology

Language Localization: The process of adapting a product into multiple languages for a country or region

Did you know

Localizing your App can supercharge your implementation. The global population consists of just 6% native English speakers.

This means that you can not only be available on multiple App Stores, but your App can be suitable for those markets too, making your App ready for the 94% of the population increasing your customer satisfaction (reviews!) and implement localization early in the development of your App to save the money that it would take to change your App to localize the content after going to production.

Implementation

Set up a new Xcode single view project

Set up a single view project through Xcode

Installing through Carthage

The easiest way to install Cathage is through Brew. (alternative installation methods are avaliable through https://github.com/Carthage/Carthage#installing-carthage)

But for brew we simply need to update brew

followed by

Once installed, at any time you can check the version of carthage

We will use vim to create our cartfile. It is possible to use your text editor of choice here, but the tutorial will use vim.

Make sure you run this from the folder with your project.

and then add the following

We can clone dependencies with the following command, and it operates on the clones as specified in the Cartfile.

Drag in the Localize_swift.framework from the Build>iOS folder to the Linked Frameworks and Libraries (available when the target is selected, and the general tab is selected).

Add the following in Build Phases, Add + on the top-left hand corner of the window and a new run script phase and add the following:

and then under input files add an entry for the framework:

Installing through CocoaPods

Perform a

and add the following to the Podfile

followed by a pod install

Import Localize_Swift

At the beginning of any class where you want to localize the content you need to import Localize_swift, using the following

Add Localizations

You can add localization files through Project>Info>Localizations

Image for post
Image for post

Towards the bottom of the screen the Use Base Internationalization tick box is checked. This is what we want so no action required here!

You may be aware that your project is already organized around a Base.lproj folder

Image for post
Image for post

This is the initial Base language, and is only used when a language is not supported in localizable.strings.

We need to press the friendly-looking + button to add extra localizations to our project. For example here we will choose Chinese (simplified)

Image for post
Image for post

Which of course can be selected from the list

Image for post
Image for post

Pressing the finish button generates new files under the target language:

Image for post
Image for post

Within our file structure we have a reassuring new folder. Because I picked Chinese(simplified) I have a new folder; zh-Hans.lproj

Image for post
Image for post

Xcode has given us files as LaunchScreen.strings and Main.strings

Which brings us to…we don’t have a localizable.strings file yet, do we?

File>New>File

to make it trivial to find, I’ve looked for all files beginning with “str”

Image for post
Image for post

Inevitably I’ve called the file Localizable.strings

Image for post
Image for post

This creates the file, but only for the Base language. To remedy this, we can press the localize… button in the File Inspector.

Image for post
Image for post

So we can then select our added language(s) and click the Localize button

Image for post
Image for post

We need to have both files (in my case English and Chinese(Simplified) by selecting all the languages in localization.

Image for post
Image for post

The only issue is that each localization needs to be ended with a semi-colon.

So my Localizable.strings(Chinese(Simplified)) looks something like:

Image for post
Image for post

And my English version can look like:

Image for post
Image for post

and we can also see the files around our Localizable.string file:

Image for post
Image for post

The Localize Swift is available at the following repository:

Want to get in contact? Use Twitter:

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store