views:

55

answers:

2

I want to get current selected iphone language. If using "NSLocale" it returns always the same language. It seems that this is not the one you choose inside iphone settings.

NSLocale * locale = [NSLocale currentLocale];
NSString * localLanguage = [locale objectForKey:NSLocaleLanguageCode];
NSLog (@"Language : %@", localLanguage); // Returns always : "en_US"

How to obtain the current language?

A: 

Try [[NSLocale autoupdatingCurrentLocale] objectForKey:NSLocaleLanguageCode]

Steam Trout
this is also not working - it returns "en_US". It seems that Apple always returns the iphone initial language but not the one the user selected.
hhamm
The thing is, NSLocaleLanguageCode should not be even returning en_US but en only. - [NSLocale localeIdentifier] would be the one to return en_US. This is kinda odd. Maybe try CFLocale API? Sadly I don't have iDevice at hand to test it myself. Maybe anyone else can see if it works on theirs?
Steam Trout
A: 

The answer is to check the preferred language :

NSString *preferredLang = [[NSLocale preferredLanguages] objectAtIndex:0];
hhamm