I\'d like to show the current language that the device UI is using. What code would I use?
I want this as an NSString
in fully spelled out format. (Not
This will probably give you what you want:
NSLocale *locale = [NSLocale currentLocale];
NSString *language = [locale displayNameForKey:NSLocaleIdentifier
value:[locale localeIdentifier]];
It will show the name of the language, in the language itself. For example:
Français (France)
English (United States)
To get current language of device
NSLocale.preferredLanguages()[0] as String
To get application language
NSBundle.mainBundle().preferredLocalizations[0] as NSString
Note:
It fetches the language that you have given in CFBundleDevelopmentRegion of info.plist
if CFBundleAllowMixedLocalizations is true in info.plist then first item of CFBundleLocalizations in info.plist is returned
In Swift 4.2 and Xcode 10.1
let language = NSLocale.preferredLanguages[0]
print(language)//en
According to Apple documentation
NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
NSArray* languages = [defs objectForKey:@"AppleLanguages"];
NSString* preferredLang = [languages objectAtIndex:0];
Swift 3
let locale = Locale.current
let code = (locale as NSLocale).object(forKey: NSLocale.Key.countryCode) as! String?
print(code!)
Two letters format. Apple uses the ISO standard ISO-3166.
NSString *localeCountryCode = [[NSLocale autoupdatingCurrentLocale] objectForKey:NSLocaleCountryCode];