How to localize my application using Xcode 5?

This is the next question (and answer) on How to localize my application with an Xcode 4 question? .

How to localize my application using Xcode 5.x?

+10
ios xcode internationalization localization xcode5
Apr 26 '14 at 7:55
source share
2 answers

It is quite simple as soon as you understand it.

The first thing you want to do is add a localization file to the project. To do this, simply select the main project group

main group ,

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

In 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 a localizable file, we can click the Localize... button in the File Inspector

File inspector .

Xcode will ask you if you want to localize the file, just click Localize with Base Localize? .

Now this next part is a bit complicated. We need to enter our Info project to do this, click the project file in Xcode Navigator , then on the right you will see a category called PROJECT , click on the project file under this category

Project file .

Now we can add the desired language in the Localizations category. I will add Norwegian

Languages .

It is important that we leave our Localizable.strings file in the menu that appears Localizable.strings file checked .

Now we can deploy our Localizable.strings file in Navigator to see our localized files Strings file expanded .

Now we are like our Base file (in our Localizable.strings file), which will be our "main language" of our application and our previously selected language.

It is important to know that the structure of these files must be the same. You will see what I mean in just a second.

In our Base I will add a line called it_worked and add its localization

it_workedEN .

And in our previously selected language (in my Norwegian case) I will add the same it_worked line (to save the structure), but with a different localization

<T411>.

Now that we have our localized file, we can make our application read when necessary.

I added the UILabel application to my application so that we can display localized text in our application.

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

Now, if I run the application, we will see our base language

Base Language ,

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

Other Language (NO) .

+22
Apr 26 '14 at 7:55
source share

You do not need to add uilabel and change the text by code.

You can use the advanced attributes of the Runtime User Defined Runtime:

http://cupobjc.blogspot.com.es/2014/04/interfaz-builder-localization.html

First define a new category for UILabel:

 #import "UILabel+Localized.h" @implementation UILabel (Localized) -(void) setTextLocalized:(NSString *)aText{ [self setText:NSLocalizedString(aText, nil)]; } @end 

Then, in the interface builder, custom runtime attributes:

textLocalized String of your string in localized

enter image description here

+3
Apr 26 '14 at 8:28
source share



All Articles