How to get the current iPhone Language Code
We are currently developing an iPhone App which requires localization support and I ran into an issue while trying to get currently set language.
Cocoa Touch has a class called NSLocale which let’s you query the language by writing the following code:
[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode];
At least one would expect so, but it actually gives you the language of the region format you have configured in your settings.
For example:
If you have your iPhone language set to ‘English’, but your region format is set to ‘Germany’, the call will return ‘de’ instead of ‘en’.
What you really should call is:
[[NSLocale preferredLanguages] objectAtIndex:0]
Because this gives you not the language associated with the region, but the language the device is actually configured for.
Thanks very much for your post!
Good read. You ok if i add this info to my blog ?
Thanks ALOT!
Thanks a lot man… worked fine for me!
I’m totally into this blog. It’s great!