3

In a case when you want a App in a language/region/format other than selected iPhone settings value. Example a App with it's own internal language settings.

I know how to change the language, but what about the region/format?

To easily override the selected language in settings you can run this code in main

 [[NSUserDefaults standardUserDefaults]
  setObject:[NSArray arrayWithObject:@"sv"]
  forKey:@"AppleLanguages"];

To view the change in effect, let us output current settings with below code

 NSString *locale = [[NSLocale currentLocale] localeIdentifier];
 NSLog(@"current locale: %@", locale);
 NSArray* preferredLangs = [NSLocale preferredLanguages];
 NSLog(@"preferredLangs: %@", preferredLangs);

With the output coming as

 current locale: en_US
 preferredLangs: ( sv )

But I want to change this locale to sv_SE

How can i in the same way override the locale(Region/Format) in the iPhone Settings?

David Allansson
  • 384
  • 1
  • 8
  • possible duplicate of [iOS: Is there any way to fake the user's locale?](http://stackoverflow.com/questions/15396606/ios-is-there-any-way-to-fake-the-users-locale) – jrc Sep 06 '15 at 16:49

1 Answers1

0

there are two more interesting key in the user defaults. Theres 'AppleLanguages' and 'AppleLocale'. You can set them to your hearts content... :)

Just paste this somewhere early in your code, and you should get the results you're after... :)

[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObject:@"sv"]
                                          forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"sv", @"en", nil]
                                          forKey:@"NSLanguages"];
[[NSUserDefaults standardUserDefaults] setObject:@"sv_SE"
                                          forKey:@"AppleLocale"];
Alex Zak
  • 1,924
  • 2
  • 18
  • 26