11

I create tow Localizable.strings files one for english and the second for arabic :

/* The number 1 */
"LABEL_ONE" = "label number one";

I am using this code to get the string value:

[self.Lable1 setText:NSLocalizedString(@"LABEL_ONE", @"The number 1")];

but the app show "LABEL_ONE" instead of "label number one" ? What's the problem ? Thanks

rmaddy
  • 314,917
  • 42
  • 532
  • 579
user3648409
  • 293
  • 4
  • 10
  • possible duplicate of [NSLocalizedString only retrieves the key, not the value in Localizable.strings (IOS)](http://stackoverflow.com/questions/9251177/nslocalizedstring-only-retrieves-the-key-not-the-value-in-localizable-strings) – bummi Oct 26 '14 at 22:13
  • It might issue because of simulator. Try on iPhone device. Hope it will work. – Dnyaneshwar Wakchaure Mar 16 '17 at 07:14

9 Answers9

13

Your string files name have to be Localizable.strings.

Fkzm
  • 210
  • 2
  • 6
6

In addition to the top answer, the localization file has to be named Localizable.strings and not anything else.

aaannjjaa
  • 338
  • 3
  • 6
5

Your code is correct, so the problem is elsewhere.

Here are some possibilities:

  1. The Localized.strings file is not copied into the application bundle. To verify this focus on the Localized.strings file using the 'Project Navigator' and make sure your target is checked on the right pane under 'Target Membership'
  2. There is some syntax issues within the Localized.strings file, i.e. missing ;
  3. The code you quoted does not get executed. To verify put a breakpoint and see if it's reached or use some debug logs...
  4. The string appears in the Localized.strings for Arabic but is missing for English.
Tom Susel
  • 3,397
  • 1
  • 24
  • 25
0

Your problem is very simple:

The app doesn't find the file with translations.

So you must be sure that you create the localizable files with the correct name (for example en for english) and also that in your device (or simulator) you have set 1 of the languages prepared from you in these files.

Otherwise, the file is not found and is returned the key instead of the value.

Matteo Gobbi
  • 17,697
  • 3
  • 27
  • 41
  • I have tow files localizable.strings(English) and localisable.strings(arabic) , xcode generate this when I add localisation in the project info !! – user3648409 May 17 '14 at 21:02
  • And what language do you have set on your device? and did you write the word in both files? – Matteo Gobbi May 17 '14 at 21:56
  • now I am using the simulator not a real device ! Yes I write the word in both files – user3648409 May 17 '14 at 22:05
  • I repeat: WHAT LANGUAGE ARE YOU USING IN YOUR SIMULATOR? – Matteo Gobbi May 17 '14 at 22:07
  • you should post your text files here. Be sure that you have files added in your target as well...clean the project (product -> clean) etc...this code work so you are committing something to wrong – Matteo Gobbi May 17 '14 at 22:16
0

try this answer it is work for me I was having problems with this on the iOS Simulator. I ended up deleting the Localization.strings file in the simulator directory

( /Users/(me)/Library/Application Support/iPhone Simulator/5.0/Applications/(etc)/(project)/(application.app)

copied from here

https://stackoverflow.com/a/11657945

Community
  • 1
  • 1
Bahgat Mashaly
  • 510
  • 7
  • 15
0

In my case cleaning the project after initially introducing i18n to it solved it.

0

Check whether you added any text/character by mistake after the ; in Localizable.strings file.

It doesn't show the error while running the app but XCode ignore all the key-value pair after this character, which leads to returning the key instead of values.

I put a + by mistake in string file and wasted 2 hours for this.

Abhijith
  • 3,094
  • 1
  • 33
  • 36
0

Make sure that the Target Membership is set to include your App and any other places you may need it. In my case, the membership was only set to the test folder

Matt Jenje
  • 175
  • 1
  • 8
-1

[Answer from August, 2017. Compiler may have changed]

Search for a syntax error in your .strings File

I had the following line:

"Changed your mind?" = "¿Cambiaste de opinión?";,

And somehow that made the compilation succeed, even the command plutil -lint Localizable.strings said it was okay. After I took the same comma down from each file in that line, now the compiler is able to detect there are errors.

The problem before was the compilation succeeded, but because of the comma the .strings file was actually wrong so nothing after the comma was read. I don't know if the comma has any use in .strings files.

Note: plutil -lint Localizable.strings is used on the Terminal tu debug .strings files as Xcode cannot tell where the .strings compilation wen wrong.

Manuel BM
  • 868
  • 1
  • 13
  • 17