Since the last update, I can't translate the language code (en, fr, etc...) into their respective names (English, French, etc...).
It works on a real device, but not in the emulator. It was working using former versions of Xcode. I'm aware that it's written in the release notes that [NSLocale currentLocale]
may return en_US
in some situations, but that doesn't explain why they are no more "translated". I use this code:
NSString* lang = @"en";
NSLog(@"%@",
[[NSLocale currentLocale]
displayNameForKey:NSLocaleIdentifier
value:lang]
);
which displays (null)
, instead of English
.
The problem is that my app is crashing at some places because of that so I would like to know if there's a workaround.
The weird thing is that the following example, given by Apple, works really well.
NSLocale *frLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"fr_FR"];
NSString *displayNameString = [frLocale displayNameForKey:NSLocaleIdentifier value:@"fr_FR"];
NSLog(@"displayNameString fr_FR: %@", displayNameString);
displayNameString = [frLocale displayNameForKey:NSLocaleIdentifier value:@"en_US"];
NSLog(@"displayNameString en_US: %@", displayNameString);