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.

6 Comments

  1. Reinaldo says:

    Thanks very much for your post!

  2. Good read. You ok if i add this info to my blog ?

  3. Tony says:

    Thanks ALOT!

  4. mohit says:

    Thanks a lot man… worked fine for me!

  5. I’m totally into this blog. It’s great!

  6. Alexander Barrel says:

    For localization support regarding phone apps, you could use this online tool that helps a lot in the process of translation: https://poeditor.com/.

Leave a Reply