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?
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?
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
then, from the toolbar, select
.
File → New → File...
(or just hold down⌘N
)Under the
,
and name it
.
Resource
category, selectStrings File
Localizable.strings
(note that it is case sensitive)Now that we have our localizable file, we can click on the
Localize...
button, in theFile Inspector
Xcode is going to ask you if you want to localize the file, just click on
.
Localize
withBase
selectedNow 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'sNavigator
, then to your right you'll see a category namedPROJECT
, click on your project file under this categoryNow we can add our desired language under the
Localizations
category. I'll addNorwegian
It's
.
important
that we only leave ourLocalizable.strings
file checked in the menu that appearsNow we can expand our
.
Localizable.strings
file in theNavigator
to see our localizable filesWe now how our
Base
file (within ourLocalizable.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 namedit_worked
, and add it's localizationAnd in our previously selected language (In my case
Norwegian
), i'll add the same stringit_worked
(to keep the structure), but with a different localizationNow 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.Now if I launch my app, we'll see our base language
and if I change the language of the simulator to Norwegian, we'll see our other language
You don't need to add the uilabel and change the text on code.
You can take advanced of the User Defined Runtime Attributes:
http://cupobjc.blogspot.com.es/2014/04/interfaz-builder-localization.html
First define a new category for UILabel:
Then in the interface builder, User Defined Runtime Attributes :
textLocalized String your string to localized