IPhone: NSLocalizedString, reading from an English .strings file, even if another language is installed

I have an application in which there are some files not related to US Localizable.strings. They appear in the project since I expect them to be: a Localizable.strings object and helper objects for "en", "fr", etc. Each of them is a UTF16 text file, and I checked that they are distributed in the assembly package, like the correct binary plist files.

However, when working with my application, even if the device settings are some other language, only lines from my English Localizable.strings file are returned

The preferred language from NSLocale is, for example, “fr”. And I see that the device setup somehow goes through, because the buttons of the system toolbar are translated (“cancel”, etc.).

But my lines are still in English. (Note that they come from the .strings file, as I edited this to check.)

So: the string files look fine and they are built and deployed OK.

Is there anything else I need to do to “tell” the project that other locales are supported?

Thanks!

+4
source share
5 answers

This happens (apparently) when there is a Localizable.strings file in the project’s root directory in addition to the individual .lproj directories. The application seems to always prefer if it is present. The fact that he was there was probably an artifact when he tried to find the localization working on the project.

I leave this question here if others run into this problem.

+5
source

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

+6
source

It can also help to remove the application from the simulator after localizing .NIB, since the localized version will have two (or more) new files in new locations (for example, "en.lproj", "fr.lproj",). However, when you create a simulator, it’s too stupid to know to delete the old .xib file, so it will load the old obsolete xib file, not your new localized version, until you clean the device by reinstalling the application.

+2
source

I decided this: I removed the application from the simulator and in xcode: Product -> Clean

+2
source

For a specific en_US problem that always returns, you need to request preferredLanguages for the array of preferred languages ​​at the moment, not currentLocale .

NSLocalizedString not returning key string from correct file?

In localization, you must be sure that you are changing what you think you are changing. If you change the language in the settings, this will affect the line that is returned from your localizable.strings file. If you change the settings in Region Region, then only the date, currency symbol, etc.

0
source

Source: https://habr.com/ru/post/1311824/


All Articles