Вопрос

I'm trying to get my localizable.strings working properly, but I can't figure out how. My storyboard is localizable too, and works: all buttons and view controllers are shown rightly, in both languages.

But my NSLocalizedStrings loaded programmatically just appears in english. I checked my Localizable.strings, that have 2 languages: English and Brazilian-Portuguese (pt-BR), and I haven't found any problem.

How can I fix it?

Thanks in advance!

Это было полезно?

Решение

Try this to check if you use the right Language and Region:

NSLog(@"Language: %@", [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0]);
NSLog(@"Region: %@", [[NSLocale currentLocale] objectForKey:NSLocaleCountryCode]);

And if you just change the region in the Device-Settings, you have to close and restart your App!

EDIT: I think your actual problem is, you use "Brazilian-Portuguese" as Localization, you have to use "Portuguese".

UPDATE: In Xcode you can chose between many localizations, but the only options, that take effect in NSLocalizedString(), etc. are the Languages you can select on your iPhone in Settings->General->International->Language

Here the complete list at the moment:

• Arabic • Catalan • Chinese (Simplified) • Chinese (Traditional) • Croatian • Czech • Danish • Dutch • English (U.S.) • English (UK) • Finnish • French • German • Greek • Hebrew • Hungarian • Indonesian • Italian • Japanese • Korean • Malay • Norwegian • Polish • Portuguese • Portuguese (Portugal) • Romanian • Russian • Slovak • Spanish • Swedish • Thai • Turkish • Ukrainian • Vietnamese

Другие советы

Just updating @xapslock answer to Swift.

    NSLog("Language: " + NSBundle.mainBundle().preferredLocalizations[0]);
    NSLog("Region: " + (NSLocale.currentLocale().objectForKey(NSLocaleCountryCode) as! String));
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top