summaryrefslogtreecommitdiff
path: root/platform/darwin
diff options
context:
space:
mode:
authorChris Loer <chris.loer@gmail.com>2018-06-28 12:57:24 -0700
committerChris Loer <chris.loer@mapbox.com>2018-07-03 10:03:05 -0700
commit10a6d1bf23db91a29dc420466175171d9de50c11 (patch)
tree7a7ab169d7e220d8551f831115e0b94669e6c590 /platform/darwin
parenta5b0fe8a75a7e354593d8fb7a031a5e64a39b80f (diff)
downloadqtlocation-mapboxgl-10a6d1bf23db91a29dc420466175171d9de50c11.tar.gz
[ios, macos] Try to make darwin "resolvedLocale" BCP 47 compliant
Diffstat (limited to 'platform/darwin')
-rw-r--r--platform/darwin/src/collator.mm18
1 files changed, 12 insertions, 6 deletions
diff --git a/platform/darwin/src/collator.mm b/platform/darwin/src/collator.mm
index 5a87ab3c9a..6b6519d4b1 100644
--- a/platform/darwin/src/collator.mm
+++ b/platform/darwin/src/collator.mm
@@ -11,11 +11,11 @@ namespace expression {
class Collator::Impl {
public:
Impl(bool caseSensitive, bool diacriticSensitive, optional<std::string> locale_)
- : options((caseSensitive ? 0 : NSCaseInsensitiveSearch) |
- (diacriticSensitive ? 0 : NSDiacriticInsensitiveSearch))
- , locale(locale_ ?
- [[NSLocale alloc] initWithLocaleIdentifier:@((*locale_).c_str())] :
- [NSLocale currentLocale])
+ : options((caseSensitive ? 0 : NSCaseInsensitiveSearch) |
+ (diacriticSensitive ? 0 : NSDiacriticInsensitiveSearch))
+ , locale(locale_ ?
+ [[NSLocale alloc] initWithLocaleIdentifier:@((*locale_).c_str())] :
+ [NSLocale currentLocale])
{}
bool operator==(const Impl& other) const {
@@ -35,7 +35,13 @@ public:
}
std::string resolvedLocale() const {
- return [locale localeIdentifier].UTF8String;
+ // Following documentation at:
+ // https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPInternational/LanguageandLocaleIDs/LanguageandLocaleIDs.html#//apple_ref/doc/uid/10000171i-CH15-SW9
+ // We expect NSLocale to accept BCP 47 tags as localeIdentifier inputs, but the output format
+ // may append the region tag with an "_". Changing that to a "-" makes the identifier BCP 47 compliant.
+ // Experimentally, "zh-Hans-HK" and "zh-Hans_HK" both round trip -- if the second is used by
+ // `currentLocale`, we don't want to return the underscore.
+ return [[locale localeIdentifier] stringByReplacingOccurrencesOfString:@"_" withString:@"-"].UTF8String;
}
private:
NSStringCompareOptions options;