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 @"en_US")
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 @"en_US")
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)
You can use the displayNameForKey:value:
method of NSLocale
:
// get a French locale instance
NSLocale *frLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"fr_FR"] autorelease];
// use it to get translated display names of fr_FR and en_US
NSLog(@"%@", [frLocale displayNameForKey:NSLocaleIdentifier value:@"fr_FR"]);
NSLog(@"%@", [frLocale displayNameForKey:NSLocaleIdentifier value:@"en_US"]);
This will print out:
français (France)
anglais (États-Unis)
If you specify the same locale identifier for the initWithLocaleIdentifier:
and also the displayNameForKey:value:
method, then it will give you the native name of the language. I've discovered that if you remove the country code and use just fr
and en
, that it will also omit the country from the display name (on Mac OS X at least, not sure about iOS).