Created
March 28, 2014 04:25
-
-
Save Superbil/9825403 to your computer and use it in GitHub Desktop.
let en is second chose
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ref from: http://stackoverflow.com/questions/20241256/ios-app-default-language-en-is-not-applied | |
// remove what was previously stored in NSUserDefaults (otherwise the previously selected language will be still the first one in the list and your app won't be localized in the language selected in settings) | |
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:@"AppleLanguages"]; | |
[[NSUserDefaults standardUserDefaults] synchronize]; // make the change immediate | |
// reorder the languages so English is always the default fallback | |
NSMutableArray *mutableLanguages = [[NSLocale preferredLanguages] mutableCopy]; | |
NSInteger enIndex = NSNotFound; | |
for (NSString *lang in mutableLanguages) { if ([lang isEqualToString:@"en"]) { enIndex = [mutableLanguages indexOfObject:lang]; break; } } | |
@try { | |
if ((enIndex != 0) && (enIndex != 1)) { [mutableLanguages exchangeObjectAtIndex:1 withObjectAtIndex:enIndex]; } | |
} @catch (NSException *exception) { | |
} | |
// save the changes | |
[[NSUserDefaults standardUserDefaults] setObject:mutableLanguages forKey:@"AppleLanguages"]; | |
[[NSUserDefaults standardUserDefaults] synchronize]; // to make the change immediate | |
return UIApplicationMain(argc, argv, nil, NSStringFromClass([YourAppDelegate class])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment