Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 9 beta Language ID syntax change

I'm quite confusing, why in iOS 9 beta the return value of language code is different from iOS 8.4?

Function:

NSUserDefaults.standardUserDefaults().objectForKey("AppleLanguages")   

Just set Language to "Simple Chinese" and Region to "China".

In iOS 8.4, return "zh-Hanz" but in iOS 9 beta 4 return "zh-Hanz-CN". The Language ID syntax is much more like

"[language designator]-[script designator]-[region designator]".

Is different with apple document:

Is it a new rule in iOS 9? Can someone help me to confirm this.

Thank you for your help.

like image 635
Paul Avatar asked Aug 11 '15 03:08

Paul


2 Answers

Yes, I noticed it too while using [NSLocale preferredLanguages]

In iOS 9 beta it returned zh-Hans-US ( with region set to US and language to Chinese Simplified ) whereas in iOS 8.4 it used to return zh-Hans only.

So meanwhile I have been using [[NSBundle mainBundle] preferredLocalizations] This returns the current localization ( zh-hans ) which is without the region post-fix ( -US )

To confirm, iOS 9 adds the region post-fix ( like -US or -CN ) to all of the languages.

like image 87
ankuranand Avatar answered Nov 05 '22 14:11

ankuranand


You should use componentsFromLocaleIdentifiert to split the locale identifier and find the language code. Like here:

+ (NSString*)currentLanguage
{
    NSLocale* locale = [NSLocale currentLocale];
    NSString* identifier = locale.localeIdentifier;
    NSDictionary* components = [NSLocale componentsFromLocaleIdentifier:identifier];
    NSLog(@"components:\n%@", components);
    return [components valueForKey:NSLocaleLanguageCode];
}
like image 44
Udo Avatar answered Nov 05 '22 15:11

Udo