0
votes

we have an app that supports English & French localization and we use NSBundle's preferred localization to retrieve the current device locale

    NSArray *prefLocalizations = [NSBundle preferredLocalizationsFromArray:[NSArray arrayWithObjects:@"English", @"French",nil]];

So for English it returns English and French returns French and the array has one element. When changing the language from French to Spanish the app is localized to English, since its not supported. The problem here is that we expected the prefLocalization to return English but instead it returns French. Any idea why this happens and how to fix it?

Edit: CFBundleDevelopmentRegion is set to en

1

1 Answers

3
votes

The reason

When you have your OS primary language set to spanish, the order of preferred languages, by default, is:

  1. Spanish
  2. French
  3. English
  4. ...

I have found the same behavior at other operating systems, like f.e. at the Xbox. I actually grew up in Spain and I have found that most people have english as secondary language, so, this doesn't really make any sense to me (maybe because spanish is closer to french than to english?).

How to fix it

At iOS 8 you can change the order of languages in Settings > General > Language and Region under the heading Preferred Language Order (See this post).

Another option would be to check the primary language and select the localization yourself:

NSString *language = [[NSLocale preferredLanguages] objectAtIndex:0];
NSString *languageToSelect;
if([language isEqualToString:@"fr"])
{
    languageToSelect=@"fr";
}
else
{
    languageToSelect=@"en";
}