37
votes

I'm having this really mind breaking problem.

I created a Localizable.strings file in XCode and then 2 languages in it.

I filled up these files with the language translations, did a build/clean and then a fresh build, but there is no way the Localization strings show up in my project. If I try something like:

self.title = NSLocalizedString(@"HEAD", nil);

only "HEAD" instead of the translation shows up in the device simulator.

This is my project hierarchy:

project hierarchy

And this are the content of the English localization file: enter image description here

Any ideas?

13
This answer to a similar question might help you. - Brian Driscoll
@BrianDriscoll Thanks, but that didn't help. - jbssm

13 Answers

76
votes

I found the answer myself.

Besides cleaning and building the project again and all that I described above. You must also delete the app in the iPhone simulator and then build it again! After that it works perfectly.

Talk about making it simple Apple...

38
votes

Be sure that:

  1. The file is called: "Localizable.strings".
  2. "Localizable.strings" belongs to the target you are dealing with.
19
votes

A few checks:

  1. Make sure the filename is exactly Localizable.strings and is included in the target
  2. Every string is ended with ;
  3. Every string is double quoted with "
  4. Comments begins with // (NOT #)
12
votes

Make sure you have Localizable.strings under Build Phases, Copy Bundle Resources.

5
votes

Check the file name if the first letter is Uppercase Localizable.strings

3
votes

@jbssm's solution works, but a better way (making sure the resource will keep updating without cleaning and deleting each time) will be to add a custom script build phase that changes the access time of the Localizable.bundle.

As described in https://stackoverflow.com/a/19274844/414037

2
votes

I found 1 answer myself.

Make sure that all the values have end point with ; Otherwise,its not work..

2
votes

Besides all the tips mentioned elsewhere in this thread, Localizable.strings also has to be located in the project root folder in certain cases.

0
votes

In my case, my Localizable.strings file was not properly formatted, due to some left over text. The compiler did not complain, but all the strings after the illegal section of the file were ignored. My file looked something like this:

"Key1" = "String1";

  • A string

  • A string

  • A string

A string";

"Key2" = "String2";

So be sure to hand inspect any Localizable.strings that is not being processed properly. You cannot trust the compiler to catch all formatting errors.

0
votes

My two cents on localization. I have tweaked with the localization files, added and removed them, and had the project gone under many Xcode updates. Later find that except English none of the localization is working.

The problem was I must have a base localization, I must tick the base on the right side when I did that a file in left added and other translation comes up in the app. Surely have the strings there...

enter image description here

0
votes
  1. Replace the position of Localizable.strings
  2. Have a cross verification with Localizable.strings cut and past in note pad so that we can easily identify the hidden characters and sublime texts. resolve it the follow the bellow steps.
  3. Make sure the filename is exactly Localizable.strings and is included in the target
  4. Every string is ended with ;
  5. Every string is double quoted with "
  6. Comments begins with // (NOT #)

Also delete the app in the iPhone simulator and then build it again! After that it works perfectly.

0
votes

I also had to set the encoding of given .strings file.

To do this select the file in project navigator and then on the right panel select encoding in "Text Settings" section. I used Unicode(UTF-8).

enter image description here

-1
votes

I want to warn on one more possible problem related to UIButton, who can look like localization is not working.

In order to set text on UIButton use:

setTitle(_ title: String?, for state: UIControl.State)

Instead of:

button.titleLabel?.text