summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Guerra Soto <fabian.guerra@mapbox.com>2019-04-15 13:54:53 -0700
committerFabian Guerra <fabian.guerra@mapbox.com>2019-04-15 13:57:35 -0700
commit997c57501f66cac71efeb89fa1fd5cbb030d5067 (patch)
treee6d6078794c29a914eb9aba709055316f26be1db
parent958f95648fae7aeee22e8a90f32a0ef97aa99c6e (diff)
downloadqtlocation-mapboxgl-upstream/fabian-cp-14393.tar.gz
[ios, macos] Fix MGLSymbolStyleLayer.text localization issue. (#14405)upstream/fabian-cp-14393
Fixed an MGLSymbolStyleLayer.text localization bug caused by the introduction of MGLAttributedExpression object. The localization parsing was ignoring the latter. * [ios, macos] Fix a localization issue. * [ios, macos] Add formating expressions localization test. * [ios, macos] Update MGLSymbolStyleLayer.text documentation.
-rwxr-xr-xplatform/darwin/scripts/generate-style-code.js3
-rw-r--r--platform/darwin/src/MGLSymbolStyleLayer.h1
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.mm6
-rw-r--r--platform/darwin/test/MGLExpressionTests.mm10
4 files changed, 20 insertions, 0 deletions
diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js
index 2eabd0a92b..20ad86382c 100755
--- a/platform/darwin/scripts/generate-style-code.js
+++ b/platform/darwin/scripts/generate-style-code.js
@@ -356,6 +356,9 @@ global.propertyDoc = function (propertyName, property, layerType, kind) {
doc += '* Constant array, whose each element is any of the following constant string values:\n';
doc += Object.keys(property.values).map(value => ' * `' + value + '`: ' + property.values[value].doc).join('\n') + '\n';
}
+ if (property.type === 'formatted') {
+ doc += '* Formatted expressions.\n';
+ }
doc += '* Predefined functions, including mathematical and string operators\n' +
'* Conditional expressions\n' +
'* Variable assignments and references to assigned variables\n';
diff --git a/platform/darwin/src/MGLSymbolStyleLayer.h b/platform/darwin/src/MGLSymbolStyleLayer.h
index cf2c1466e7..5c12b28544 100644
--- a/platform/darwin/src/MGLSymbolStyleLayer.h
+++ b/platform/darwin/src/MGLSymbolStyleLayer.h
@@ -1086,6 +1086,7 @@ MGL_EXPORT
You can set this property to an expression containing any of the following:
* Constant string values
+ * Formatted expressions.
* Predefined functions, including mathematical and string operators
* Conditional expressions
* Variable assignments and references to assigned variables
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm
index 4b1fdb818e..9dad00e56e 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.mm
+++ b/platform/darwin/src/NSExpression+MGLAdditions.mm
@@ -1471,6 +1471,12 @@ NSDictionary<NSNumber *, NSExpression *> *MGLLocalizedStopDictionary(NSDictionar
if (localizedValues != self.constantValue) {
return [NSExpression expressionForConstantValue:localizedValues];
}
+ } else if ([self.constantValue isKindOfClass:[MGLAttributedExpression class]]) {
+ MGLAttributedExpression *attributedExpression = (MGLAttributedExpression *)self.constantValue;
+ NSExpression *localizedExpression = [attributedExpression.expression mgl_expressionLocalizedIntoLocale:locale];
+ MGLAttributedExpression *localizedAttributedExpression = [MGLAttributedExpression attributedExpression:localizedExpression attributes:attributedExpression.attributes];
+
+ return [NSExpression expressionForConstantValue:localizedAttributedExpression];
}
return self;
}
diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm
index 306379d844..db4f869129 100644
--- a/platform/darwin/test/MGLExpressionTests.mm
+++ b/platform/darwin/test/MGLExpressionTests.mm
@@ -1201,6 +1201,16 @@ using namespace std::string_literals;
XCTAssertEqualObjects([original mgl_expressionLocalizedIntoLocale:nil], expected);
}
{
+ NSExpression *keyExpression = [NSExpression expressionForKeyPath:@"name_en"];
+ MGLAttributedExpression *attributedExpression = [MGLAttributedExpression attributedExpression:keyExpression attributes:@{}];
+ NSExpression *original = [NSExpression expressionForConstantValue:attributedExpression];
+
+ NSExpression *coalesceExpression = [NSExpression expressionWithFormat:@"mgl_coalesce({%K, %K})", @"name_en", @"name"];
+ MGLAttributedExpression *expectedAttributedExpression = [MGLAttributedExpression attributedExpression:coalesceExpression attributes:@{}];
+ NSExpression *expected = [NSExpression expressionForConstantValue:expectedAttributedExpression];
+ XCTAssertEqualObjects([original mgl_expressionLocalizedIntoLocale:nil], expected);
+ }
+ {
NSExpression *original = [NSExpression expressionForKeyPath:@"name_en"];
NSExpression *expected = [NSExpression expressionWithFormat:@"mgl_coalesce({%K, %K})", @"name_en", @"name"];
XCTAssertEqualObjects([original mgl_expressionLocalizedIntoLocale:nil], expected);