Question

I'm having a strange problem with the localization of an app. It was working fine in a previous version, but it somehow stopped working recently, with no discernible changes to the localization files (I did add one language, but that is all).

When I install a build using the Xcode Organizer (Xcode 3.2.5), the localization only works sometimes. Changing the language setting around in the OS doesn't seem to do anything. Uninstalling from the Xcode Organizer, and then re-installing doesn't help.

It seems that the localization APIs cannot find my resources. I added some NSLog() statements to one of my ViewControllers to print out a string that should be localized, using this function:

NSLog(@"Value: %@", [[NSBundle mainBundle] localizedStringForKey:@"MY_KEY" value:@"none found" table:nil]);

When localization is working, this prints out the expected result. When localization is not working, this prints out "none found". I have checked the contents of the bundle, and the .lproj files are all there. What am I missing?

Edit: I have discovered that after I build, some of the resulting *.lproj/Localizable.strings files for the various languages are not created properly - sometimes. I can touch the German file and it will get generated correctly, but the next time I run a build it's not right. The encoding for all of the Localizable.strings files is currently set to UTF-16, and I have tried switching to UTF-8 with no luck. I do not see any warnings or errors in the build log to indicate a problem with the strings files.

Was it helpful?

Solution

I have seen this happen before due to having more than one localizable.strings file in your project. This can easily happen if you drop an open source library into your solution (such as ShareKit, which comes with its own localizable.strings file). See the question at Localisation strings not always work having ShareKit in a project for more on this possible cause for your problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top