How I get now the actual system language? It seems that they put regional suffix after last dash. So before cs
is now cs-DE
if the language is Czech and regional setting is German. But there are some languages which don't have the suffix like GB language is en-GB
but regional setting is German.
NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
NSArray* language = [defs objectForKey:@"AppleLanguages"];
NSString* preferredLang = [language objectAtIndex:0];
NSLog(@"localeIdentifier: %@", preferredLang);
Use the componentsFromLocaleIdentifier
method from NSLocale
class
Here is the documentation
You can do like this:
NSString* localeID = [NSLocale currentLocale].localeIdentifier;
NSDictionary* components = [NSLocale componentsFromLocaleIdentifier:localeID];
NSString* languageID = components[NSLocaleLanguageCode];
EDIT
Getting the language this way will create some issues if the language the app is currently translated in is not the device's language. Indeed,
components[NSLocaleLanguageCode]
will return the device's language.
To get the app's current language, you should use [[NSBundle mainBundle] preferredLocalizations].firstObject
.
To get the device's region, you can still use components[NSLocaleCountryCode]
I just run into this problem recently. According to Apple's documentation, you will get the locale id with region designator which for like [language designator]-[region designator]
on iOS 9.
I found a solution if you just wanna get the locale id, you could use[[NSBundle mainBundle] preferredLocalizations]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With