summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLloyd Sheng <i@lloydsheng.com>2018-07-18 13:20:47 +0800
committerLloyd Sheng <i@lloydsheng.com>2018-07-18 13:20:47 +0800
commit70cac0e43d86047cc25a95c53b829b2b5c8c2af4 (patch)
tree7f7d10ba15eeaaf278080abb4107f95511e8b266
parent9f4eda28c24a76531c3fbce282ae38ccc93abf84 (diff)
downloadqtlocation-mapboxgl-upstream/lloyd-label-localization.tar.gz
Add a fallback for `name_zh-Hant`upstream/lloyd-label-localization
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.mm22
-rw-r--r--platform/darwin/test/MGLExpressionTests.mm16
-rw-r--r--platform/ios/CHANGELOG.md2
3 files changed, 18 insertions, 22 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm
index ddc46a6ea7..0104828454 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.mm
+++ b/platform/darwin/src/NSExpression+MGLAdditions.mm
@@ -1507,23 +1507,25 @@ NSDictionary<NSNumber *, NSExpression *> *MGLLocalizedStopDictionary(NSDictionar
localizedKeyPath = [NSString stringWithFormat:@"name_%@", preferredLanguage];
}
}
- // If the keypath is `name` or `name_en`, no need to fallback
- if ([localizedKeyPath isEqualToString:@"name"] || [localizedKeyPath isEqualToString:@"name_en"]) {
+ // If the keypath is `name`, no need to fallback
+ if ([localizedKeyPath isEqualToString:@"name"]) {
return [NSExpression expressionForKeyPath:localizedKeyPath];
}
- // If the keypath is `name_zh-Hans`, fallback to `name_zh`. If `name_zh` is empty, fallback to `name`
+ // If the keypath is `name_zh-Hans`, fallback to `name_zh` to `name`
// The `name_zh-Hans` field was added since Mapbox Streets v7
// See the documentation of name fields for detail https://www.mapbox.com/vector-tiles/mapbox-streets-v7/#overview
+ // CN tiles might using `name_zh-CN` for Simplified Chinese
if ([localizedKeyPath isEqualToString:@"name_zh-Hans"]) {
- return [NSExpression expressionWithFormat:@"mgl_coalesce(%@)",
- @[[NSExpression expressionForKeyPath:localizedKeyPath],
- [NSExpression expressionForKeyPath:@"name_zh"],
- [NSExpression expressionForKeyPath:@"name"],]];
+ return [NSExpression expressionWithFormat:@"mgl_coalesce({%K, %K, %K, %K})",
+ localizedKeyPath, @"name_zh-CN", @"name_zh", @"name"];
+ }
+ // Mapbox Streets v8 has `name_zh-Hant`, we should fallback to Simplified Chinese if the filed has no value
+ if ([localizedKeyPath isEqualToString:@"name_zh-Hant"]) {
+ return [NSExpression expressionWithFormat:@"mgl_coalesce({%K, %K, %K, %K, %K})",
+ localizedKeyPath, @"name_zh-Hans", @"name_zh-CN", @"name_zh", @"name"];
}
// Other keypath fallback to `name`
- return [NSExpression expressionWithFormat:@"mgl_coalesce(%@)",
- @[[NSExpression expressionForKeyPath:localizedKeyPath],
- [NSExpression expressionForKeyPath:@"name"],]];
+ return [NSExpression expressionWithFormat:@"mgl_coalesce({%K, %K})", localizedKeyPath, @"name"];
}
return self;
}
diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm
index 210c8c50eb..89553b317b 100644
--- a/platform/darwin/test/MGLExpressionTests.mm
+++ b/platform/darwin/test/MGLExpressionTests.mm
@@ -1054,7 +1054,7 @@ using namespace std::string_literals;
}
{
NSExpression *original = [NSExpression expressionForKeyPath:@"name_en"];
- NSExpression *expected = original;
+ NSExpression *expected = [NSExpression expressionWithFormat:@"mgl_coalesce({%K, %K})", @"name_en", @"name"];
XCTAssertEqualObjects([original mgl_expressionLocalizedIntoLocale:nil], expected);
}
{
@@ -1064,17 +1064,13 @@ using namespace std::string_literals;
}
{
NSExpression *original = [NSExpression expressionForKeyPath:@"name_en"];
- NSExpression *expected = [NSExpression expressionWithFormat:@"mgl_coalesce(%@)",
- @[[NSExpression expressionForKeyPath:@"name_fr"],
- [NSExpression expressionForKeyPath:@"name"]]];
+ NSExpression *expected = [NSExpression expressionWithFormat:@"mgl_coalesce({%K, %K})", @"name_fr", @"name"];
XCTAssertEqualObjects([original mgl_expressionLocalizedIntoLocale:[NSLocale localeWithLocaleIdentifier:@"fr-CA"]], expected);
}
{
NSExpression *original = [NSExpression expressionForKeyPath:@"name_en"];
- NSExpression *expected = [NSExpression expressionWithFormat:@"mgl_coalesce(%@)",
- @[[NSExpression expressionForKeyPath:@"name_zh-Hans"],
- [NSExpression expressionForKeyPath:@"name_zh"],
- [NSExpression expressionForKeyPath:@"name"]]];
+ NSExpression *expected = [NSExpression expressionWithFormat:@"mgl_coalesce({%K, %K, %K, %K})",
+ @"name_zh-Hans", @"name_zh-CN", @"name_zh", @"name"];
XCTAssertEqualObjects([original mgl_expressionLocalizedIntoLocale:[NSLocale localeWithLocaleIdentifier:@"zh-Hans"]], expected);
}
{
@@ -1091,9 +1087,7 @@ using namespace std::string_literals;
NSExpression *expected = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, short, %@)", @{
@1: [NSExpression expressionForKeyPath:@"abbr"],
@2: @"…",
- @3: [NSExpression expressionWithFormat:@"mgl_coalesce(%@)",
- @[[NSExpression expressionForKeyPath:@"name_es"],
- [NSExpression expressionForKeyPath:@"name"]]]
+ @3: [NSExpression expressionWithFormat:@"mgl_coalesce({%K, %K})", @"name_es", @"name"]
}];
XCTAssertEqualObjects([original mgl_expressionLocalizedIntoLocale:[NSLocale localeWithLocaleIdentifier:@"es-PR"]], expected);
}
diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md
index bfcf6249fc..d980d8e91a 100644
--- a/platform/ios/CHANGELOG.md
+++ b/platform/ios/CHANGELOG.md
@@ -16,7 +16,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
* Added the `collator` and `resolved-locale` expression operators to more precisely compare strings in style JSON. A subset of this functionality is available through predicate options when creating an `NSPredicate`. ([#11869](https://github.com/mapbox/mapbox-gl-native/pull/11869))
* Fixed a crash when trying to parse expressions containing legacy filters. ([#12263](https://github.com/mapbox/mapbox-gl-native/pull/12263))
* Fixed a crash that occurred when creating an `MGL_MATCH` expression using non-expressions as arguments. ([#12332](https://github.com/mapbox/mapbox-gl-native/pull/12332))
-* Fixed an issue that no localized low-zoom labels when system language is Simplified Chinese ([#12164](https://github.com/mapbox/mapbox-gl-native/issues/12164))
+* Fixed an issue causing country and ocean labels to disappear after calling -[MGLStyle localizeLabelsIntoLocale:] when the system language is set to Simplified Chinese. ([#12164](https://github.com/mapbox/mapbox-gl-native/issues/12164))
### Networking and storage