Reputation: 481
my app supports four different languages and I need to tell my server which one is used, so that the data from the server will be in the correct language. Which of the many language/locale classes will provide me with the information which of MY translations is currently in use.
So if the device is Russian (which I do NOT have a translation for) it will default back to English (I guess), so I need to know that "en" is currently in use. If the device is Italian (which I DO have a translation for) I obviously need to know that it is "it".
Thank you very much!
Upvotes: 0
Views: 92
Reputation: 8473
For Swift 3 you can use
let localization = Bundle.main.preferredLocalizations.first
Upvotes: 1
Reputation: 481
After some additional testing and research I could answer it myself and I found out that the following will provide the correct answer.
NSString* language = [[[NSBundle mainBundle] preferredLocalizations] firstObject];
The [[NSBundle mainBundle] preferredLocalizations]
will provide you an ordered list of languages which are also supported by your app. It will only give you the language part though. So just "en" and not "en-US".
I have not tested this across multiple versions of iOS, but it works in iOS 10.
Upvotes: 0