+ [NSLocale preferredLanguages] returns different values on iOS compared to OS X
| Originator: | RadwanAzzouz | ||
| Number: | rdar://22645639 | Date Originated: | 10-Sep-2015 01:40 PM |
| Status: | Open | Resolved: | |
| Product: | iOS | Product Version: | |
| Classification: | iOS | Reproducible: | Always |
Summary: + [NSLocale preferredLanguages] languages are prefixed by the country code when running on iOS but not when running on OS X. Please refer to the attached sample projects where we set the text (iOS) and string (OS X) properties to the same value, "preferredLanguages: \(NSLocale.preferredLanguages())”. Steps to Reproduce: 1. Build and run the “NSLocale preferredLanguages - iOS” project. 2. Build and run the “NSLocale preferredLanguages - OS X” project. Expected Results: + [NSLocale preferredLanguages] should behave in a similar fashion on both platforms. Actual Results: The languages from the iOS project are prefixed with the current locale’s country code ( NSLocale.currentLocale().objectForKey(NSLocaleCountryCode)) while on OS X they are not. Version: OS X El Capitan GM, Xcode 7 GM, iOS 9 GM Notes: We rely on + [NSLocale preferredLanguages] in our shared code between the Mac and the iOS app. And we expect that + [NSLocale preferredLanguages] does behave in a similar fashion on both platforms. In iOS 8.4.1 + [NSLocale preferredLanguages] does not append the country code to the preferred language. Configuration: OS X El Capitan GM on an Early 2015 13 inch rMBP, iOS 9 GM on an iPhone 6. Attachments: 'NSLocale preferredLanguages.zip' was successfully uploaded. https://com-agilebits-users.s3.amazonaws.com/rad/NSLocale%20preferredLanguages.zip
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
With iOS 9, the results returned by NSLocale.preferredLanguages() can differ from previous releases
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
Hi yeradis,
Thanks so much for taking the time to comment on this rdar :+1:
According to the technical note this is indeed the expected behaviour in iOS 9. However, the problem was originally reported due to the inconsistent results between iOS 9 and OS X El Capitan when using + [NSLocale preferredLanguages] in a shared code base or frameworks. Since NSLocale is a Foundation API, one would expect that such an API would return similar results on both platforms.
Thank you :-D