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

Commit

Permalink
[ios, macos] Fix MGLSymbolStyleLayer.text localization issue. (#14405)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fabian-guerra committed Apr 15, 2019
1 parent 958f956 commit 997c575
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions platform/darwin/scripts/generate-style-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
1 change: 1 addition & 0 deletions platform/darwin/src/MGLSymbolStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions platform/darwin/src/NSExpression+MGLAdditions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,12 @@ - (NSExpression *)mgl_expressionLocalizedIntoLocale:(nullable NSLocale *)locale
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;
}
Expand Down
10 changes: 10 additions & 0 deletions platform/darwin/test/MGLExpressionTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,16 @@ - (void)testLocalization {
NSExpression *expected = original;
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"];
Expand Down

0 comments on commit 997c575

Please sign in to comment.