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")
EDIT: For those driving on by, there are a ton of useful comments here, as the answer has evolved with new iOS releases.
The solutions provided will actually return the current region of the device - not the currently selected language. These are often one and the same. However, if I am in North America and I set my language to Japanese, my region will still be English (United States). In order to retrieve the currently selected language, you can do:
This will return a two letter code for the currently selected language. "en" for English, "es" for Spanish, "de" for German, etc. For more examples, please see this Wikipedia entry (in particular, the 639-1 column):
List of ISO 639-1 codes
Then it's a simple matter of converting the two letter codes to the string you would like to display. So if it's "en", display "English".
Hope this helps someone that's looking to differentiate between region and currently selected language.
EDIT
Worth to quote the header information from NSLocale.h:
People interested in app language take a look at @mindvision's answer
Swift
To get current language of device
To get application language
Note:
It fetches the language that you have given in CFBundleDevelopmentRegion of info.plist
if CFBundleAllowMixedLocalizations is true in info.plist then first item of CFBundleLocalizations in info.plist is returned
Swift 3
Obviously, the solutions relying, for example, on
usually work fine and return the current device language.
But it could be misleading in some cases :
If the app in which you want to get this value has already changed the language, for example with this kind of code :
In this case, [NSLocale preferredLanguages] actually returns the preferred language set (and used) in this particular app, not the current device language !
And... in this case the only way to properly get the actual current device language (and not that previously set in the app), is to firstly clear the key @"appleLanguages" in NSUserDefaults, like this :
Then, [NSLocale preferredLanguages] now returns the correct value.
Hope this help.
For Swift 3:
NSLocale.preferredLanguages[0] as String
For MonoTouch C# developers use:
Note: I know this was an iOS question, but as I am a MonoTouch developer, the answer on this page led me in the right direction and I thought I'd share the results.