When browsing the App Store, users are likely to scroll right past apps that don't support the language they speak. Like any business, one way we can improve the sales of our apps is to make them useful to new, large groups of people.

Today we'll begin learning about localizing our apps. We'll start by setting up our Xcode project to be localized, then try a simple example using NSLocalizedString.

Let's dive in:

First, we'll head over to our Project's settings **and add a new **Localization language. We'll choose French, then Finish.
This will modify our project (and a few files) to make it localizable.

Image 1 of 10 from bite #181: App Localization Basics

Image 2 of 10 from bite #181: App Localization Basics

Next, we'll go to File > New > File… and add a new Strings file called Localizable to help us localize strings in our code.

Image 3 of 10 from bite #181: App Localization Basics

Image 4 of 10 from bite #181: App Localization Basics

Yep, it has to be named exactly like that. πŸ˜’

We'll select this new file and head over to the File Inspector panel. We'll click the Localize… button, then the French checkbox.

Image 5 of 10 from bite #181: App Localization Basics

Image 6 of 10 from bite #181: App Localization Basics

Image 7 of 10 from bite #181: App Localization Basics

Now we can edit both versions of our .strings file, adding translate-able strings using a special key/value syntax:

// Localizable.strings (Base)
search-spaceships = "Search spaceships...";
globe = "🌎";
// Localizable.strings (French)
search-spaceships = "Recherche vaisseaux spatiaux...";
globe = "🌍";

Then, we can reference those keys in our code using NSLocalizedString:

searchBar.placeholder = NSLocalizedString("search-spaceships", comment: "Search Placeholder")

We can specify a language to test by editing the Application Language setting of our Scheme's Options.

Image 8 of 10 from bite #181: App Localization Basics

Success!

Image 9 of 10 from bite #181: App Localization Basics

Image 10 of 10 from bite #181: App Localization Basics

Download the example project from this bite right here.