When getting the current language of the device, we usually use the following API:
1 |
[NSLocale preferredLanguages] |
or
1 |
NSLocale.preferredLanguages() |
In iOS 8 and below, the above API will returns an NSArray
of language code. For example:
"en", "ja", "es"
But in iOS 9, this changed! So if you are using this API in your code, you need to consider the new return value format. The return values are now in the format:
"<language code>-<region code>"
For example:
"en-US", "en-JP", "ja-US", "es-US"
With iOS 9, the results returned by NSLocale.preferredLanguages() can differ from previous releases. In iOS 8 and earlier, only certain language, script, and region combinations were returned by this API. However, in iOS 9, more combinations of language, script, and region are permitted.
For example, when a user has configured their iOS device with language set to English and region set to India, NSLocale.preferredLanguages() will now return [ “en-IN” ], instead of [ “en” ]. This allows for smarter language fallbacks; for this user, if an app doesn’t support en-IN as a localization, but does support en-GB, the fallback mechanism will select en-GB instead of en.
Read more at :
https://developer.apple.com/library/ios/technotes/tn2418/_index.html#//apple_ref/doc/uid/DTS40016588
There appear and interesting approach to solve for a better localization
Thank you for the link, very helpful!