boreas
boreas

Reputation: 1061

xcode localized string not loaded

I have met a strange problem with the localized strings. I have only a 'Localizable.strings' in my 'en.lproj' folder and it works fine. all the strings are shown on device. but the next time i compile it and run, it shows only the ID of the strings. even if i change nothing and only click on build&debug. and the next time it works fine again and next time again shown with IDs.

so does anyone knows why this is happening? it's kind of annoying that i always need to build twice.

Upvotes: 5

Views: 6027

Answers (2)

GtotheB
GtotheB

Reputation: 2727

My SOLUTION is at bottom:

I've been running into the same problem: Alternating runs yield correct, then incorrect translations (only for English though).

Adding "-NSShowNonLocalizedStrings YES" as an argument to the app yielded:

Localizable string "MyKey" not found in strings table "Localizable" of bundle CFBundle

So, I tried loading the key file directly from the bundle as a string and dumping it. Well, the times it did NOT work correctly, it was displaying a bunch of built-in iOS messages. So, I went to the APP file that was built, opened the package contents, and viewed the en.lproj/Localizable.strings file...and voila!!! The file had been filled with Apple iOS key/value pairs. On the next build, it was filled as expected.

Of course, this has nothing to do with the encoding of the files (which should be UTF-16). I have not been able to locate anything with mention of this specific problem.

MY SOLUTION:

I copied the contents of the legitimate english Localizable.strings file FROM THE APP PACKAGE (not from my source) into an XML file (when compiled, the .strings file are converted into XML) and added to my project. I then loaded this file into a dictionary at startup, and if the call to NSLocalizedString returned the key instead of the value, I did a lookup on the dictionary I loaded. In theory, you could do this for all languages, but I was only having the problem with english.

Yes, it's not the answer to the problem, but it's a workaround.

Upvotes: 5

reggian
reggian

Reputation: 657

Check if you have more than one Localizable.strings in your project. Merging them into one solved it for me. (Check any external code you use e.g. ShareKit)

Upvotes: 3

Related Questions