From 10a6d1bf23db91a29dc420466175171d9de50c11 Mon Sep 17 00:00:00 2001 From: Chris Loer Date: Thu, 28 Jun 2018 12:57:24 -0700 Subject: [ios, macos] Try to make darwin "resolvedLocale" BCP 47 compliant --- platform/darwin/src/collator.mm | 18 ++++++++++++------ platform/node/test/ignores.json | 2 +- 2 files changed, 13 insertions(+), 7 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 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; diff --git a/platform/node/test/ignores.json b/platform/node/test/ignores.json index f3fad90ea8..148469ef3a 100644 --- a/platform/node/test/ignores.json +++ b/platform/node/test/ignores.json @@ -1,7 +1,7 @@ { "expression-tests/collator/accent-equals-de": "Locale-specific behavior changes based on platform.", "expression-tests/is-supported-script/default": "This tests RTL text plugin behavior specific to GL JS", - "expression-tests/resolved-locale/basic": "https://github.com/mapbox/mapbox-gl-native/issues/11692", + "expression-tests/resolved-locale/basic": "Even the 'en' locale may not be present on some test systems.", "query-tests/geometry/multilinestring": "needs investigation", "query-tests/geometry/multipolygon": "needs investigation", "query-tests/geometry/polygon": "needs investigation", -- cgit v1.2.1