Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[ios, macos] Try to make darwin "resolvedLocale" BCP 47 compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLoer committed Jun 29, 2018
1 parent e5adcdb commit 4f84b7e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions platform/darwin/src/collator.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
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 {
Expand All @@ -35,7 +35,13 @@ int compare(const std::string& lhs, const std::string& rhs) const {
}

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;
Expand Down
2 changes: 1 addition & 1 deletion platform/node/test/ignores.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 4f84b7e

Please sign in to comment.