summaryrefslogtreecommitdiff
path: root/platform/darwin
diff options
context:
space:
mode:
authorLloyd Sheng <i@lloydsheng.com>2018-07-26 13:53:12 +0800
committerGitHub <noreply@github.com>2018-07-26 13:53:12 +0800
commit9c90509750c9ae4d76f0a902036b30f7c5477ac9 (patch)
tree25a315789b67f4f34fb31574ca150697b880427d /platform/darwin
parent8400355e996a40014f774d443a0d5deab41d705e (diff)
downloadqtlocation-mapboxgl-9c90509750c9ae4d76f0a902036b30f7c5477ac9.tar.gz
[iOS] Add fallbacks for name fields (#12387)
* Add fallbacks for name fields * Add a fallback for `name_zh-Hant` * Update changelog
Diffstat (limited to 'platform/darwin')
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.mm20
-rw-r--r--platform/darwin/test/MGLExpressionTests.mm9
2 files changed, 24 insertions, 5 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm
index efd572935b..58f5816416 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.mm
+++ b/platform/darwin/src/NSExpression+MGLAdditions.mm
@@ -1401,7 +1401,25 @@ NSDictionary<NSNumber *, NSExpression *> *MGLLocalizedStopDictionary(NSDictionar
localizedKeyPath = [NSString stringWithFormat:@"name_%@", preferredLanguage];
}
}
- return [NSExpression expressionForKeyPath:localizedKeyPath];
+ // 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` 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({%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({%K, %K})", localizedKeyPath, @"name"];
}
return self;
}
diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm
index 5ae98e5244..6cb7bfdc3d 100644
--- a/platform/darwin/test/MGLExpressionTests.mm
+++ b/platform/darwin/test/MGLExpressionTests.mm
@@ -1013,7 +1013,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);
}
{
@@ -1023,12 +1023,13 @@ using namespace std::string_literals;
}
{
NSExpression *original = [NSExpression expressionForKeyPath:@"name_en"];
- NSExpression *expected = [NSExpression expressionForKeyPath:@"name_fr"];
+ 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 expressionForKeyPath:@"name_zh-Hans"];
+ 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);
}
{
@@ -1045,7 +1046,7 @@ using namespace std::string_literals;
NSExpression *expected = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, short, %@)", @{
@1: [NSExpression expressionForKeyPath:@"abbr"],
@2: @"…",
- @3: [NSExpression expressionForKeyPath:@"name_es"],
+ @3: [NSExpression expressionWithFormat:@"mgl_coalesce({%K, %K})", @"name_es", @"name"]
}];
XCTAssertEqualObjects([original mgl_expressionLocalizedIntoLocale:[NSLocale localeWithLocaleIdentifier:@"es-PR"]], expected);
}