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
Translating language codes such as en_US into English (United States) is a built in feature of NSLocale
and NSLocale
does not care where you get the language codes from. So there really is no reason to implement your own translation as the accepted answer suggests.
// Example code - try changing the language codes and see what happens
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en"];
NSString *l1 = [locale displayNameForKey:NSLocaleIdentifier value:@"en"];
NSString *l2 = [locale displayNameForKey:NSLocaleIdentifier value:@"de"];
NSString *l3 = [locale displayNameForKey:NSLocaleIdentifier value:@"sv"];
NSLog(@"%@, %@, %@", l1, l2, l3);
Prints: English, German, Swedish