Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had the same issue with one of my apps. What I did is force en as the second language in AppleLanguages and it's working now. You have to do that before the application starts (main). It's a bit of an ugly hack but works for now (NSLocalizedString is looking at that list to determine the language)... You have to be careful though, because you may get some weird stuff from NSLocale after you do that. For example if you want to use the - displayNameForKey:value: it won't be in sync and you'll have to restart the app so you get the correct result. so what you can do is initialize NSLocale with the first element in the [NSLocale preferredLanguages] (NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:[NSLocale preferredLanguages][0]];) and then it's going to return the expected results.</p> <p>Here's what you have to do to swap the languages:</p> <pre><code>// 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) &amp;&amp; (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])); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload