4

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.

Rahul Raj
  • 367
  • 3
  • 17

2 Answers2

6

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.

jmontane
  • 76
  • 1
2

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"];
Anusha Kottiyal
  • 3,855
  • 3
  • 28
  • 45
  • This solution has a dangerous side-effect as explained here: http://stackoverflow.com/questions/19497047/applelanguages-value-overrides-the-value-of-language-set-in-ios-settings-preferr?rq=1 – viggio24 Nov 28 '13 at 21:07