Localizable.strings not working in iOS
Asked Answered
P

13

41

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?

Pietrek answered 25/6, 2012 at 18:14 Comment(3)
This answer to a similar question might help you.Weariless
@BrianDriscoll Thanks, but that didn't help.Pietrek
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.Morality
P
84

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

Pietrek answered 25/6, 2012 at 18:58 Comment(6)
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.Ouster
@Ouster 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.Pietrek
Thanks for this. Deleting the app, cleaning and re-installing it worked for me.Resin
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.Alidis
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. @PietrekLavery
Thanks mate, that was exactly that worked for me !Protohuman
S
43

Be sure that:

  1. The file is called: "Localizable.strings".
  2. "Localizable.strings" belongs to the target you are dealing with.
Smallsword answered 26/1, 2015 at 19:58 Comment(4)
Thanks :) This solved my issue. Had the file named Lozalizable.strings. Wouldnt notice it without your post!Rolo
I LOL'd at "Lozalizable"Snuff
Yes, be sure that your file name IS NOT "Localization.string", I had the same problem and after I changed it to "Localizable.string" it worked fine :)Tripletail
In my case, The Localizable.strings is not assigned to the Target,Thanks!Lipski
S
22

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 #)
Symons answered 3/9, 2016 at 10:23 Comment(0)
T
14

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

Tapir answered 16/10, 2014 at 11:33 Comment(1)
Actually i was missing this, thanks! this should be upvotedEocene
D
5

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

Designed answered 14/10, 2015 at 11:59 Comment(0)
C
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://mcmap.net/q/392222/-resource-files-not-updating-with-xcode-5

Cupid answered 22/1, 2014 at 15:36 Comment(0)
T
2

I found 1 answer myself.

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

Tindall answered 29/1, 2014 at 8:9 Comment(2)
Your project will not compile when there is a ';' missingPunke
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 ;Bread
H
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.

Heliostat answered 28/8, 2018 at 16:7 Comment(0)
A
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.

Alba answered 30/8, 2016 at 15:37 Comment(1)
Got same error. Use the following command in terminal to find the line: plutil -lint <file>Howund
B
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

Brakpan answered 16/8, 2017 at 12:47 Comment(0)
M
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.

Myers answered 3/7, 2018 at 7:34 Comment(0)
W
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

Worden answered 19/7, 2019 at 9:50 Comment(0)
A
-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
Apopemptic answered 22/10, 2019 at 9:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.