3

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!

Gui Del Frate
  • 671
  • 1
  • 7
  • 17

2 Answers2

8

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

xapslock
  • 1,119
  • 8
  • 21
  • 2
    Thanks! I was not finding the option "Portuguese", only with the regions, BR (Brazil) or PT (Portugal). The option appeared when I deleted the existing location. Everything is working properly now, with the locations "English" and "Portuguese". – Gui Del Frate Sep 20 '12 at 04:03
  • 3
    I can confirm that although 'pt-BR' is presented as an option when adding a localization to your project, it doesn't actually work on iOS unless you use 'pt' instead! – jd. May 16 '13 at 04:09
0

Just updating @xapslock answer to Swift.

    NSLog("Language: " + NSBundle.mainBundle().preferredLocalizations[0]);
    NSLog("Region: " + (NSLocale.currentLocale().objectForKey(NSLocaleCountryCode) as! String));
Loebre
  • 615
  • 2
  • 8
  • 23