summaryrefslogtreecommitdiff
path: root/platform/darwin/src/NSExpression+MGLAdditions.mm
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2018-04-12 19:05:20 -0700
committerMinh Nguyễn <mxn@1ec5.org>2018-04-16 14:46:51 -0700
commita53cd10a68a6aaebaa1d8e0f5407ab819b2042bb (patch)
tree0495070cc3d2f7413110832786848d8779729830 /platform/darwin/src/NSExpression+MGLAdditions.mm
parent4f2367a16bd325c24c864cc8ce38aa198d4132da (diff)
downloadqtlocation-mapboxgl-a53cd10a68a6aaebaa1d8e0f5407ab819b2042bb.tar.gz
[ios, macos] Test token replacement, localization
Added unit tests of token replacement and localization of expressions. Only NSExpression is responsible for resolving the preferred language now, since NSLocale tends to tack a region code onto the locale identifier and the NSExpression method can be called independently anyways. Added a private variation of +[MGLVectorTileSource preferredMapboxStreetsLanguage] that takes an array of preferred languages. Fixed localization of non-expressions in stop dictionaries.
Diffstat (limited to 'platform/darwin/src/NSExpression+MGLAdditions.mm')
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.mm12
1 files changed, 10 insertions, 2 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm
index 4c6e04ffc0..b18391018c 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.mm
+++ b/platform/darwin/src/NSExpression+MGLAdditions.mm
@@ -10,6 +10,7 @@
#endif
#import "NSPredicate+MGLAdditions.h"
#import "NSValue+MGLStyleAttributeAdditions.h"
+#import "MGLVectorTileSource_Private.h"
#import <objc/runtime.h>
@@ -1245,6 +1246,9 @@ NS_ARRAY_OF(NSExpression *) *MGLLocalizedCollection(NS_ARRAY_OF(NSExpression *)
NS_DICTIONARY_OF(NSNumber *, NSExpression *) *MGLLocalizedStopDictionary(NS_DICTIONARY_OF(NSNumber *, NSExpression *) *stops, NSLocale * _Nullable locale) {
__block NSMutableDictionary *localizedStops;
[stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomLevel, NSExpression * _Nonnull value, BOOL * _Nonnull stop) {
+ if (![value isKindOfClass:[NSExpression class]]) {
+ value = [NSExpression expressionForConstantValue:value];
+ }
NSExpression *localizedValue = [value mgl_expressionLocalizedIntoLocale:locale];
if (localizedValue != value) {
if (!localizedStops) {
@@ -1273,8 +1277,12 @@ NS_DICTIONARY_OF(NSNumber *, NSExpression *) *MGLLocalizedStopDictionary(NS_DICT
case NSKeyPathExpressionType: {
if ([self.keyPath isEqualToString:@"name"] || [self.keyPath hasPrefix:@"name_"]) {
NSString *localizedKeyPath = @"name";
- if (locale && ![locale.localeIdentifier isEqualToString:@"mul"]) {
- localizedKeyPath = [NSString stringWithFormat:@"name_%@", locale.localeIdentifier];
+ if (![locale.localeIdentifier isEqualToString:@"mul"]) {
+ NSArray *preferences = locale ? @[locale.localeIdentifier] : [NSLocale preferredLanguages];
+ NSString *preferredLanguage = [MGLVectorTileSource preferredMapboxStreetsLanguageForPreferences:preferences];
+ if (preferredLanguage) {
+ localizedKeyPath = [NSString stringWithFormat:@"name_%@", preferredLanguage];
+ }
}
return [NSExpression expressionForKeyPath:localizedKeyPath];
}