Question

I am using localization in iOS 7 and have the localizable string files for German and English. When ever i select the corresponding language the localisation works perfect. But if i switch to any other language, then the display is based on the previous selection.

I want it to select english incase of any other language selections, Any thoughts would be appreciated.

Était-ce utile?

La solution

AFAIK, this behaviour is a feature, but undocumented? :)

In iOS7, users can set a sorted list of preferred languages. For instance; a French user fluent in German, but not in English, could set French, German, and English as language preference. It's a great feature!!!

So, I think you shouldn't override this feature.

Users can set English as 2nd language easily, choosing 1st English and then choosing it's preferred main language.

Autres conseils

Use the below checking in your main.m

NSString * deviceLanguage = [[NSLocale preferredLanguages] objectAtIndex:0];
NSArray *supportedLanguages = [NSArray arrayWithObjects:@"en",@"de", nil];

if ([supportedLanguages containsObject:deviceLanguage])
   [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:deviceLanguage, nil] forKey:@"AppleLanguages"];
else
   [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"en", nil] forKey:@"AppleLanguages"];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top