Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSLocalizedString shows raw key instead of loading a string from another language

I'm having trouble using NSLocalizedString(key, comment: "") to load strings from Localizable.strings when the key is missing for the current language. NSLocalizedString returns a raw key

For instance, when string is present for English localization, but is missing for Russian:

"config.updating" = "Update in progress...";

Calling NSLocalizedString when iOS language set to Russian returns "config.updating"

NSLocalizedString("config.updating", comment: "") // "config.updating"

Shouldn't NSLocalizedString access the "AppleLanguages" key in NSUserDefaults to determine what the user's settings are and pick some other string?

like image 900
Laevand Avatar asked Nov 26 '14 09:11

Laevand


1 Answers

No, the documentation for NSLocalizedString(key,comment) is pretty clear -

The initial value for key in the strings file will be key. Use the NSLocalizedStringWithDefaultValue macro to specify another value for key.

What else would you expect it to return? The code simply looks up the key in a dictionary. It has no idea what message is associated with the key, let alone how to translate that message into Russian.

like image 148
Paulw11 Avatar answered Oct 23 '22 21:10

Paulw11