How to set the language and region of iPhone applications in main.h, overriding the settings value

In case you want to use the application in a language / region / format other than the selected iPhone settings value. An example application with its own internal language settings.

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

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

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

To view the change in action, let's display the current settings below the code

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

When exiting as

 current locale: en_US
 preferredLangs: ( sv )

But I want to change this language to sv_SE

How can I override the locale (region / format) in the iPhone settings in the same way?

+3
source share
1 answer

. "AppleLanguages" Theres "AppleLocale". ...:)

- , , ...:)

[[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"];
0

All Articles