How can I detect the current application language ? I am not talking about NSLocale
user preferences.
In my app there are currently two supported languages
[[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0]
would be better, because it will always return a localization that your app supports. There is no need for an additional check afterwards.
In fact, your code has a bug. If the first language in the user's preferences is not one that your app supports, iOS will continue down the list until it finds one that your app does support. So if the user's preferences were "fr", "it", "en", ...
, iOS would load the it
versions of your resources. However, your code would fall back to en
.
(This is perhaps more important on OS X, where it's easy for the user to change the language ordering. On iOS it's apparently possible to do that, but it's not as obvious how it works.)
I usually reserve a special key in Localizable.strings, such as "HTTPAcceptLanguage", which I set to "en", "fr", etc. Now telling your server the language displayed by the application is as simple as NSLocalizedString(@"HTTPAcceptLanguage", nil).