Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to localize my app with Xcode 5?

This is a follow up question (and answer) on the How to localize my app with Xcode 4? question.

How do I localize my app with Xcode 5.x?

like image 242
Aleksander Azizi Avatar asked Apr 26 '14 07:04

Aleksander Azizi


People also ask

How do I add localization in swift 5?

Click on iOS->App/Single View App->Next. Name your project and select the language as Swift. Select a desired location and click on Create. To start with Localization, click on your Project Name -> go to Info Tab -> Under Localizations, click on the '+' button.

How do I change localization in Xcode?

To do this, in Xcode, select Product > Scheme > Manage Schemes ... Then in the Run/debug tab, change the "Application Language" to your desired language. And now every time you build and run your app from Xcode, it will use that language as the preferred language.


1 Answers

It's quite simple once you understand it.

The first thing you want to do is add a localization file to your project. To do so, simply select your project's main group

main group,

then, from the toolbar, select File → New → File... (or just hold down ⌘N) New File.

Under the Resource category, select Strings File Select "Strings File", and name it Localizable.strings (note that it is case sensitive) localizable.strings Name.

Now that we have our localizable file, we can click on the Localize... button, in the File Inspector

File Inspector.

Xcode is going to ask you if you want to localize the file, just click on Localize with Base selected Localize?.

Now this next part is a bit tricky. We need to enter our project's Info section, to do so, click on the project file in Xcode's Navigator, then to your right you'll see a category named PROJECT, click on your project file under this category

Project File.

Now we can add our desired language under the Localizations category. I'll add Norwegian

Languages.

It's important that we only leave our Localizable.strings file checked in the menu that appears Localizable.strings file checked.

Now we can expand our Localizable.strings file in the Navigator to see our localizable files Strings file expanded.

We now how our Base file (within our Localizable.strings file), which will be our app's "main language", and our previously selected language.

It's important to know that the structure of these files needs to be identical. You'll see what I mean in just a sec.

In our Base, I'll add a string named it_worked, and add it's localization

it_workedEN.

And in our previously selected language (In my case Norwegian), i'll add the same string it_worked (to keep the structure), but with a different localization

it_workedNO.

Now that we have our localized file, we can make our app read it when needed.

I added a UILabel to my app, so that we can make our app display the localized text.

[myLabel setText:NSLocalizedString(@"it_worked", nil)];

Now if I launch my app, we'll see our base language

Base Language (EN),

and if I change the language of the simulator to Norwegian, we'll see our other language

Other Language (NO).

like image 86
Aleksander Azizi Avatar answered Oct 09 '22 15:10

Aleksander Azizi