4

I have an app that has some non-US Localizable.strings files. They appear in the project as I expect them to: there's a Localizable.strings object, and sub objects for "en", "fr", etc. Each of those is a UTF16 text file, and I've verified that they get propagated into the build package as correct binary plist files.

When running my app, though, even when device settings are some other language, only the strings from my English Localizable.strings file come back

Preferred language from NSLocale is e.g. "fr" AND I can see that the device setting is getting through somehow, because the system toolbar buttons ("undo", etc) are translated.

But my strings are still in English. (Note that they are coming from the .strings file, as I've edited that to verify.)

So: strings files seem OK, and get built and deployed OK.

Is there something else I need to do to "tell" the project that other locales are supported?

Thanks!

Ben Zotto
  • 70,108
  • 23
  • 141
  • 204

5 Answers5

6

And if you run an application with the Localizable.strings file in the root of the project, cleaning is not enough, you also need to delete the application from the simulator.

ThomasRS
  • 8,215
  • 5
  • 33
  • 48
5

This happens (apparently) when there is a Localizable.strings file in the root of the project in addition to in the individual .lproj directories. The app seems to always prefer that if it's present. The fact that it was there was likely an artifact of mucking around trying to get the localizations working in the project.

I'm leaving this question here in case others run into this issue.

Ben Zotto
  • 70,108
  • 23
  • 141
  • 204
2

It can also help to uninstall the application from the simulator after localizing a .NIB, as the localized version will have two (or more) new files in new locations (like, 'en.lproj', 'fr.lproj'). However, when you build to the simulator, it's too stupid to know to delete the old .xib file, so it'll keep loading the old stale xib file, not your new localized version until you clean the device out by reinstalling the app.

Rob
  • 4,404
  • 2
  • 32
  • 33
2

I solved this way: I deleted the app from the simulator and in xcode: Product -> Clean

Gianluca C
  • 43
  • 1
  • 1
  • 4
0

For the particular problem of en_US always coming back, you need to be querying preferredLanguages for the array of preferred languages currently, not currentLocale.

Does NSLocalizedString does not return the keyed string from the correct file?

IN localization you have to be sure you are changing what you think you are changing. If you change Language in preferences then it will affect the string that comes back from your localizable.strings file. If you change settings under Region Format that's only date, currency symbol etc.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Adam Eberbach
  • 12,309
  • 6
  • 62
  • 114
  • Adam, thanks for the answer. When I change Language in preferences to "French", my first preferred languages is "fr" (which is right). But then NSLocalizedString returns the strings from my English .strings file. Any ideas? – Ben Zotto Jun 04 '10 at 05:11
  • Updated the question for clarity. – Ben Zotto Jun 04 '10 at 06:08
  • You are setting Language under the International heading to French, so it should get text from your "fr" file under localizable.strings. I would guess that it is falling back to English for some reason - could there be any problem with your strings file or selected encoding? I am not completely sure of this but perhaps mismatched quotes or semicolons in the strings file might cause this. And your keyed resource must be present of course. – Adam Eberbach Jun 04 '10 at 06:12
  • Yep, I agree that this should be working, and that it seems to be falling back to English. But the plist .strings files (the ones that are generated by the build itself into the app package) open fine with Property List Editor, and look reasonable. – Ben Zotto Jun 04 '10 at 06:27
  • 1
    Thanks @Cœur for the edit. That link had certainly become useless with time. – Adam Eberbach May 23 '19 at 00:09