1

If you have a localized version of your app in several languages but if the user is not using any of the languages the app is localize.
How to set a default language? Or what will be the best practice to define a default language in this case?

Here are the scenarios I was trying to tackle:

  • The application has be localize in en/fr/es but if language locale is not en/fr/es how you define a default?

  • In case the the language locale is either one of this en/fr/es and the user whants to use a different language define on there NSUserDefaults. Let's say is using english as NSUserDefaults but wants to use the fr localized version of the aplication. There is a way to overwrite the language on NSUserDefaults ?

Forge
  • 6,538
  • 6
  • 44
  • 64
Juan
  • 627
  • 2
  • 9
  • 27

2 Answers2

1

write the NSUserDefaults before the apps start

question1 : you can set your prefer order as below.

[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"de", @"en", @"fr", nil] forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];

Question2: force to use fr

[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"de", nil] forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];
Atwood Wong
  • 51
  • 1
  • 2
0

I'm finding this no longer works in iOS 9 (and probably 10). We have several targets in our code base. For a couple of them I always want it to come up in English even though localized strings may be present in the bundle.

[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"en", nil] forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];

I have added the above code in main(). The first time the app runs it comes up in the user's chosen language. On subsequent runs it will come up in English as desired.

Can anyone confirm this doesn't work in iOS 9 and suggest an alternative? I'd rather not delete the other lproj entries if I don't have to.

btschumy
  • 1,435
  • 1
  • 18
  • 35