39

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?

jbssm
  • 6,861
  • 13
  • 54
  • 81
  • 1
    This [answer](http://stackoverflow.com/a/8851669/384808) to a similar question might help you. – Brian Driscoll Jun 25 '12 at 18:17
  • @BrianDriscoll Thanks, but that didn't help. – jbssm Jun 25 '12 at 18:27
  • In my case I have replaced the file name with default name `Localizable.strings`. Now it is working fine.In my project so many pods with language changes, so it is not reloading immediately, after second time reopening the app then it's working. So I have replaced with default file name `Localizable.strings`. – Naresh Dec 19 '22 at 16:47

13 Answers13

82

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...

jbssm
  • 6,861
  • 13
  • 54
  • 81
  • 5
    Is this only a problem for the simulator or will users on App Store also have to delete the app to get the new language to work? Thanks. – geekinit May 04 '13 at 18:51
  • @geekinit I didn't test the app in a physical device, so I don't know the answer to that question. I would like to know the answer if you get it tough. – jbssm May 05 '13 at 19:34
  • 2
    Thanks for this. Deleting the app, cleaning and re-installing it worked for me. – Brian Boyle Aug 21 '13 at 10:41
  • In my case all other cases did not work at all. And complier does not show any warning/error in Localizable.strings file. Then I have started my key value format as "key" = "value"; And I found some my stupid mistake which was in format that was "key"; = "value"; Note : there was a extra semicolon (*) after key . After removed that I localisation works like a charm. Very easy way to catch your format. Just comment entire file's key value pairs. Then just put a key value and run the code. I think you will get know what is the actual issue. Thanks Guys. – Ravi Jul 10 '17 at 19:50
  • I have tries all things, Deleted app and reinstalled it and also check the entire file there no problem of semicolon though i don't get the arabic string in some places. @jbssm – Parth Barot Aug 20 '18 at 14:05
  • Thanks mate, that was exactly that worked for me ! – Sangsom Oct 25 '21 at 13:02
42

Be sure that:

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

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 #)
samwize
  • 25,675
  • 15
  • 141
  • 186
14

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

irmakoz
  • 1,166
  • 2
  • 12
  • 21
5

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

Blazej SLEBODA
  • 8,936
  • 7
  • 53
  • 93
3

@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

Community
  • 1
  • 1
yonix
  • 11,665
  • 7
  • 34
  • 52
2

I found 1 answer myself.

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

Hrushikesh Betai
  • 2,227
  • 5
  • 33
  • 63
  • 8
    Your project will not compile when there is a ';' missing – Jasper Aug 04 '15 at 09:01
  • 1
    This answer is correct for those who use storyboard localizations. If you have a missing `;` in your storyboard localizations , project will compile fine but won't load localizations at runtime. However if you are using localizable.strings it will give an error if there's a missing `;` – Rukshan Jun 11 '16 at 11:29
2

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

Aron
  • 3,419
  • 3
  • 30
  • 42
0

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.

phatmann
  • 18,161
  • 7
  • 61
  • 51
0

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

karim
  • 15,408
  • 7
  • 58
  • 96
0
  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.

user3108511
  • 209
  • 2
  • 7
0

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

Chuck Boris
  • 1,275
  • 1
  • 11
  • 9
-1

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
slobodans
  • 859
  • 1
  • 17
  • 23