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.
In
Swift
:The selected answer returns the current device language, but not the actual language used in the app. If you don't provide a localization in your app for the user's preferred language, the first localization available, ordered by the user's preferred order, is used.
To discover the current language selected within your localizations use
Example:
Swift:
I tried to found out the right solution for myself. When I use
Locale.preferredLanguages.first
was returned the preferred language from your app settings.If you want get to know language from user device settings, you should the use string below:
Swift 3
To unwrap and use look at the line below:
For Swift 3.0 below code can be used to answer your question:
According to Apple documentation
For getting user device current language use the following it code it worked for me.