From 6a1c5154d0035e9440cb298809fa76d2387689de Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Fri, 21 Jul 2017 17:08:56 -0400 Subject: [PATCH 1/9] [ios] Update label localization --- platform/ios/src/MGLMapView.mm | 59 ++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 9cc4c42e5a4..14a5f2d54df 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -1128,9 +1128,68 @@ - (void)wakeGL:(__unused NSNotification *)notification [self validateLocationServices]; [MGLMapboxEvents pushEvent:MGLEventTypeMapLoad withAttributes:@{}]; + + [self updateLocalization]; + } +} + +- (void)updateLocalization +{ + NSString *mapboxLanguage = [[NSUserDefaults standardUserDefaults] stringForKey:@"MGLMapboxLanguage"]; + NSString *language = [[[NSBundle mainBundle] preferredLocalizations] firstObject]; + NSString *preferredLanguageCode = [self preferredLanguageCode]; + + if (![mapboxLanguage isEqualToString:language] && ![mapboxLanguage isEqualToString:preferredLanguageCode]) { + mapboxLanguage = preferredLanguageCode; + [[NSUserDefaults standardUserDefaults] setObject:mapboxLanguage forKey:@"MGLMapboxLanguage"]; + [self setLabelLanguage:mapboxLanguage]; + [[NSNotificationCenter defaultCenter] postNotificationName:NSCurrentLocaleDidChangeNotification object:nil]; + } +} + +- (void)setLabelLanguage:(NSString *)language +{ + NSString *preferredNameToken = [NSString stringWithFormat:@"{name_%@}", language]; + + for (MGLSymbolStyleLayer *layer in [[self style] layers]) { + if (![layer isKindOfClass:[MGLSymbolStyleLayer class]]) { + continue; + } + + if ([layer.text isKindOfClass:[MGLConstantStyleValue class]]) { + MGLConstantStyleValue *label = (MGLConstantStyleValue *)layer.text; + if ([label.rawValue hasPrefix:@"{name"]) { + layer.text = [MGLStyleValue valueWithRawValue:preferredNameToken]; + } + } else if ([layer.text isKindOfClass:[MGLCameraStyleFunction class]]) { + MGLCameraStyleFunction *function = (MGLCameraStyleFunction *)layer.text; + NSMutableDictionary *stops = function.stops.mutableCopy; + [stops enumerateKeysAndObjectsUsingBlock:^(NSNumber *zoomLevel, MGLConstantStyleValue *stop, BOOL *done) { + if ([stop.rawValue hasPrefix:@"{name"]) { + stops[zoomLevel] = [MGLStyleValue valueWithRawValue:preferredNameToken]; + } + }]; + function.stops = stops; + layer.text = function; + } } } +- (NSString *)preferredLanguageCode { + // Languages supported by Mapbox Streets v10. + NSSet *supportedLanguages = [NSSet setWithObjects:@"en", @"es", @"fr", @"de", @"ru", @"zh", nil]; + NSArray *preferredLanguages = [NSLocale preferredLanguages]; + + for (NSString *language in preferredLanguages) { + NSString *languageCode = [[NSLocale localeWithLocaleIdentifier:language] objectForKey:NSLocaleLanguageCode]; + if ([supportedLanguages containsObject:languageCode]) { + return languageCode; + } + } + + return @"en"; +} + - (void)setHidden:(BOOL)hidden { super.hidden = hidden; From 6b36d6052f5bccc59b1955909bb7384c5639d086 Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Mon, 24 Jul 2017 13:48:13 -0700 Subject: [PATCH 2/9] [ios, macos] Move MGLVectorSource+MBXAdditions.h to darwin. --- .../src}/MGLVectorSource+MBXAdditions.h | 0 .../src}/MGLVectorSource+MBXAdditions.m | 0 platform/ios/ios.xcodeproj/project.pbxproj | 12 ++++++++++++ platform/macos/macos.xcodeproj/project.pbxproj | 14 ++++++++------ 4 files changed, 20 insertions(+), 6 deletions(-) rename platform/{macos/app => darwin/src}/MGLVectorSource+MBXAdditions.h (100%) rename platform/{macos/app => darwin/src}/MGLVectorSource+MBXAdditions.m (100%) diff --git a/platform/macos/app/MGLVectorSource+MBXAdditions.h b/platform/darwin/src/MGLVectorSource+MBXAdditions.h similarity index 100% rename from platform/macos/app/MGLVectorSource+MBXAdditions.h rename to platform/darwin/src/MGLVectorSource+MBXAdditions.h diff --git a/platform/macos/app/MGLVectorSource+MBXAdditions.m b/platform/darwin/src/MGLVectorSource+MBXAdditions.m similarity index 100% rename from platform/macos/app/MGLVectorSource+MBXAdditions.m rename to platform/darwin/src/MGLVectorSource+MBXAdditions.m diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 8ecbe0c6ab1..73d2c6a1246 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -17,6 +17,10 @@ 1F7454971ECD450D00021D39 /* MGLLight_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F7454941ECD450D00021D39 /* MGLLight_Private.h */; }; 1F7454A91ED08AB400021D39 /* MGLLightTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F7454A61ED08AB400021D39 /* MGLLightTest.mm */; }; 1F95931D1E6DE2E900D5B294 /* MGLNSDateAdditionsTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F95931C1E6DE2E900D5B294 /* MGLNSDateAdditionsTests.mm */; }; + 1FDD9D6F1F26936400252B09 /* MGLVectorSource+MBXAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FDD9D6D1F26936400252B09 /* MGLVectorSource+MBXAdditions.h */; }; + 1FDD9D701F26936400252B09 /* MGLVectorSource+MBXAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FDD9D6E1F26936400252B09 /* MGLVectorSource+MBXAdditions.m */; }; + 1FDD9D711F26937A00252B09 /* MGLVectorSource+MBXAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FDD9D6D1F26936400252B09 /* MGLVectorSource+MBXAdditions.h */; }; + 1FDD9D721F26938300252B09 /* MGLVectorSource+MBXAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FDD9D6E1F26936400252B09 /* MGLVectorSource+MBXAdditions.m */; }; 30E578171DAA85520050F07E /* UIImage+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 30E578111DAA7D690050F07E /* UIImage+MGLAdditions.h */; }; 30E578181DAA85520050F07E /* UIImage+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 30E578111DAA7D690050F07E /* UIImage+MGLAdditions.h */; }; 30E578191DAA855E0050F07E /* UIImage+MGLAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 30E578121DAA7D690050F07E /* UIImage+MGLAdditions.mm */; }; @@ -547,6 +551,8 @@ 1F7454941ECD450D00021D39 /* MGLLight_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLLight_Private.h; sourceTree = ""; }; 1F7454A61ED08AB400021D39 /* MGLLightTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLLightTest.mm; path = ../../darwin/test/MGLLightTest.mm; sourceTree = ""; }; 1F95931C1E6DE2E900D5B294 /* MGLNSDateAdditionsTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLNSDateAdditionsTests.mm; path = ../../darwin/test/MGLNSDateAdditionsTests.mm; sourceTree = ""; }; + 1FDD9D6D1F26936400252B09 /* MGLVectorSource+MBXAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLVectorSource+MBXAdditions.h"; sourceTree = ""; }; + 1FDD9D6E1F26936400252B09 /* MGLVectorSource+MBXAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLVectorSource+MBXAdditions.m"; sourceTree = ""; }; 20DABE861DF78148007AC5FF /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Foundation.strings"; sourceTree = ""; }; 20DABE881DF78148007AC5FF /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = ""; }; 20DABE8A1DF78149007AC5FF /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Root.strings"; sourceTree = ""; }; @@ -1537,6 +1543,8 @@ DAD165831CF4CFED001FF4B9 /* Categories */ = { isa = PBXGroup; children = ( + 1FDD9D6D1F26936400252B09 /* MGLVectorSource+MBXAdditions.h */, + 1FDD9D6E1F26936400252B09 /* MGLVectorSource+MBXAdditions.m */, 7E016D821D9E890300A29A21 /* MGLPolygon+MGLAdditions.h */, 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */, 7E016D7C1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.h */, @@ -1727,6 +1735,7 @@ DA8848871CBB033F00AB86E3 /* Fabric.h in Headers */, 35305D4A1D22AA6A0007D005 /* NSData+MGLAdditions.h in Headers */, 359F57461D2FDDA6005217F1 /* MGLUserLocationAnnotationView_Private.h in Headers */, + 1FDD9D6F1F26936400252B09 /* MGLVectorSource+MBXAdditions.h in Headers */, 404C26E21D89B877000AA13D /* MGLTileSource.h in Headers */, DA8848841CBB033F00AB86E3 /* FABAttributes.h in Headers */, DA8847FD1CBAFA5100AB86E3 /* MGLTilePyramidOfflineRegion.h in Headers */, @@ -1803,6 +1812,7 @@ DA35A2B21CCA141D00E826B2 /* MGLCompassDirectionFormatter.h in Headers */, DAF0D8141DFE0EC500B28378 /* MGLVectorSource_Private.h in Headers */, DABFB8731CBE9A9900D62B32 /* Mapbox.h in Headers */, + 1FDD9D711F26937A00252B09 /* MGLVectorSource+MBXAdditions.h in Headers */, 357FE2DE1E02D2B20068B753 /* NSCoder+MGLAdditions.h in Headers */, 1753ED431E53CE6F00A9FD90 /* MGLConversion.h in Headers */, 354B83971D2E873E005D9406 /* MGLUserLocationAnnotationView.h in Headers */, @@ -2204,6 +2214,7 @@ DA8848251CBAFA6200AB86E3 /* MGLPointAnnotation.mm in Sources */, 35136D3C1D42272500C20EFD /* MGLCircleStyleLayer.mm in Sources */, DD9BE4F81EB263C50079A3AF /* UIViewController+MGLAdditions.m in Sources */, + 1FDD9D701F26936400252B09 /* MGLVectorSource+MBXAdditions.m in Sources */, 350098DE1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.mm in Sources */, DA6408DD1DA4E7D300908C90 /* MGLVectorStyleLayer.m in Sources */, 3566C7681D4A77BA008152BC /* MGLShapeSource.mm in Sources */, @@ -2286,6 +2297,7 @@ DAA4E42E1CBB730400178DFB /* MGLAPIClient.m in Sources */, 35136D3D1D42272500C20EFD /* MGLCircleStyleLayer.mm in Sources */, DD9BE4FA1EB263F40079A3AF /* UIViewController+MGLAdditions.m in Sources */, + 1FDD9D721F26938300252B09 /* MGLVectorSource+MBXAdditions.m in Sources */, 350098DF1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.mm in Sources */, DA6408DE1DA4E7D300908C90 /* MGLVectorStyleLayer.m in Sources */, 3566C7691D4A77BA008152BC /* MGLShapeSource.mm in Sources */, diff --git a/platform/macos/macos.xcodeproj/project.pbxproj b/platform/macos/macos.xcodeproj/project.pbxproj index be33b822f2a..162f3881c5c 100644 --- a/platform/macos/macos.xcodeproj/project.pbxproj +++ b/platform/macos/macos.xcodeproj/project.pbxproj @@ -13,6 +13,8 @@ 1F7454A51ECFB00300021D39 /* MGLLight.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F7454A21ECFB00300021D39 /* MGLLight.mm */; }; 1F7454AB1ED1DDBD00021D39 /* MGLLightTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F7454AA1ED1DDBD00021D39 /* MGLLightTest.mm */; }; 1F95931B1E6DE2B600D5B294 /* MGLNSDateAdditionsTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F95931A1E6DE2B600D5B294 /* MGLNSDateAdditionsTests.mm */; }; + 1FDD9D6B1F26923400252B09 /* MGLVectorSource+MBXAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FDD9D681F26922400252B09 /* MGLVectorSource+MBXAdditions.h */; }; + 1FDD9D6C1F26924100252B09 /* MGLVectorSource+MBXAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FDD9D691F26922400252B09 /* MGLVectorSource+MBXAdditions.m */; }; 30E5781B1DAA857E0050F07E /* NSImage+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 30E578141DAA7D920050F07E /* NSImage+MGLAdditions.h */; }; 3508EC641D749D39009B0EE4 /* NSExpression+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 3508EC621D749D39009B0EE4 /* NSExpression+MGLAdditions.h */; }; 3508EC651D749D39009B0EE4 /* NSExpression+MGLAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3508EC631D749D39009B0EE4 /* NSExpression+MGLAdditions.mm */; }; @@ -233,7 +235,6 @@ DAEDC4371D606291000224FF /* MGLAttributionButtonTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DAEDC4361D606291000224FF /* MGLAttributionButtonTests.m */; }; DAF0D80E1DFE0E5D00B28378 /* MGLPointCollection_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DAF0D80D1DFE0E5D00B28378 /* MGLPointCollection_Private.h */; }; DAF0D8161DFE6B1800B28378 /* MGLAttributionInfo_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DAF0D8151DFE6B1800B28378 /* MGLAttributionInfo_Private.h */; }; - DAF0D81C1DFF567C00B28378 /* MGLVectorSource+MBXAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = DAF0D81B1DFF567C00B28378 /* MGLVectorSource+MBXAdditions.m */; }; DD0902B21DB1AC6400C5BDCE /* MGLNetworkConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = DD0902AF1DB1AC6400C5BDCE /* MGLNetworkConfiguration.m */; }; DD0902B31DB1AC6400C5BDCE /* MGLNetworkConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = DD0902B01DB1AC6400C5BDCE /* MGLNetworkConfiguration.h */; }; DD58A4C91D822C6700E1F038 /* MGLExpressionTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DD58A4C71D822C6200E1F038 /* MGLExpressionTests.mm */; }; @@ -277,6 +278,8 @@ 1F7454A21ECFB00300021D39 /* MGLLight.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLLight.mm; sourceTree = ""; }; 1F7454AA1ED1DDBD00021D39 /* MGLLightTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLLightTest.mm; sourceTree = ""; }; 1F95931A1E6DE2B600D5B294 /* MGLNSDateAdditionsTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLNSDateAdditionsTests.mm; path = ../../darwin/test/MGLNSDateAdditionsTests.mm; sourceTree = ""; }; + 1FDD9D681F26922400252B09 /* MGLVectorSource+MBXAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLVectorSource+MBXAdditions.h"; sourceTree = ""; }; + 1FDD9D691F26922400252B09 /* MGLVectorSource+MBXAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLVectorSource+MBXAdditions.m"; sourceTree = ""; }; 30E578141DAA7D920050F07E /* NSImage+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSImage+MGLAdditions.h"; path = "src/NSImage+MGLAdditions.h"; sourceTree = SOURCE_ROOT; }; 3508EC621D749D39009B0EE4 /* NSExpression+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSExpression+MGLAdditions.h"; sourceTree = ""; }; 3508EC631D749D39009B0EE4 /* NSExpression+MGLAdditions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "NSExpression+MGLAdditions.mm"; sourceTree = ""; }; @@ -568,8 +571,6 @@ DAEDC4361D606291000224FF /* MGLAttributionButtonTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLAttributionButtonTests.m; sourceTree = ""; }; DAF0D80D1DFE0E5D00B28378 /* MGLPointCollection_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLPointCollection_Private.h; sourceTree = ""; }; DAF0D8151DFE6B1800B28378 /* MGLAttributionInfo_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAttributionInfo_Private.h; sourceTree = ""; }; - DAF0D81A1DFF567C00B28378 /* MGLVectorSource+MBXAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLVectorSource+MBXAdditions.h"; sourceTree = ""; }; - DAF0D81B1DFF567C00B28378 /* MGLVectorSource+MBXAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLVectorSource+MBXAdditions.m"; sourceTree = ""; }; DAFBD0D51E3FA969000CD6BF /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/Localizable.strings"; sourceTree = ""; }; DAFBD0D61E3FA983000CD6BF /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/Foundation.strings"; sourceTree = ""; }; DD0902AF1DB1AC6400C5BDCE /* MGLNetworkConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLNetworkConfiguration.m; sourceTree = ""; }; @@ -740,8 +741,6 @@ DA839E9E1CC2E3400062CAFB /* MapDocument.xib */, DACB0C371E18DFFD005DDBEA /* MGLStyle+MBXAdditions.h */, DACB0C381E18DFFD005DDBEA /* MGLStyle+MBXAdditions.m */, - DAF0D81A1DFF567C00B28378 /* MGLVectorSource+MBXAdditions.h */, - DAF0D81B1DFF567C00B28378 /* MGLVectorSource+MBXAdditions.m */, DAE6C2E91CC3050F00DB3429 /* OfflinePackNameValueTransformer.h */, DAE6C2EA1CC3050F00DB3429 /* OfflinePackNameValueTransformer.m */, DAA48EFB1D6A4731006A7E36 /* StyleLayerIconTransformer.h */, @@ -920,6 +919,8 @@ DAD1657F1CF4CF50001FF4B9 /* Categories */ = { isa = PBXGroup; children = ( + 1FDD9D681F26922400252B09 /* MGLVectorSource+MBXAdditions.h */, + 1FDD9D691F26922400252B09 /* MGLVectorSource+MBXAdditions.m */, 408AA8601DAEED3300022900 /* MGLPolygon+MGLAdditions.h */, 408AA85C1DAEED3300022900 /* MGLPolygon+MGLAdditions.m */, 408AA8611DAEED3300022900 /* MGLPolyline+MGLAdditions.h */, @@ -1161,6 +1162,7 @@ 3538AA231D542685008EC33D /* MGLStyleLayer.h in Headers */, DAE6C35C1CC31E0400DB3429 /* MGLGeometry.h in Headers */, DAE6C35A1CC31E0400DB3429 /* MGLAccountManager.h in Headers */, + 1FDD9D6B1F26923400252B09 /* MGLVectorSource+MBXAdditions.h in Headers */, DA551B821DB496AC0009AFAF /* MGLTileSource.h in Headers */, 35602C001D3EA9B40050646F /* MGLForegroundStyleLayer.h in Headers */, DAE6C35D1CC31E0400DB3429 /* MGLMapCamera.h in Headers */, @@ -1378,7 +1380,6 @@ DACB0C391E18DFFD005DDBEA /* MGLStyle+MBXAdditions.m in Sources */, DA839E9A1CC2E3400062CAFB /* main.m in Sources */, DA839E971CC2E3400062CAFB /* AppDelegate.m in Sources */, - DAF0D81C1DFF567C00B28378 /* MGLVectorSource+MBXAdditions.m in Sources */, DAE6C2F01CC3050F00DB3429 /* OfflinePackNameValueTransformer.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1431,6 +1432,7 @@ DAE6C3911CC31E2A00DB3429 /* MGLPolygon.mm in Sources */, 35C6DF851E214C0400ACA483 /* MGLDistanceFormatter.m in Sources */, DAE6C39B1CC31E2A00DB3429 /* NSProcessInfo+MGLAdditions.m in Sources */, + 1FDD9D6C1F26924100252B09 /* MGLVectorSource+MBXAdditions.m in Sources */, DAA998FC1E9F545C002E6EA6 /* MGLFillExtrusionStyleLayer.mm in Sources */, DAE6C38F1CC31E2A00DB3429 /* MGLOfflineStorage.mm in Sources */, DAED38601D62CED700D7640F /* NSURL+MGLAdditions.m in Sources */, From 8c2e18e66bbe437e6605539664e01abe8bb43808 Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Mon, 24 Jul 2017 15:40:14 -0700 Subject: [PATCH 3/9] [ios, macos] Adapt Mapbox Streets to the user preferred language. --- platform/darwin/src/MGLStyle.h | 10 ++++++ platform/darwin/src/MGLStyle.mm | 56 +++++++++++++++++++++++++++++++ platform/ios/src/MGLMapView.mm | 59 --------------------------------- 3 files changed, 66 insertions(+), 59 deletions(-) diff --git a/platform/darwin/src/MGLStyle.h b/platform/darwin/src/MGLStyle.h index 8ffd7db2b2b..19b4ce8b14a 100644 --- a/platform/darwin/src/MGLStyle.h +++ b/platform/darwin/src/MGLStyle.h @@ -610,6 +610,16 @@ MGL_EXPORT */ @property (nonatomic, strong) MGLLight *light; +#pragma mark Managing Style's localization + +/** + Set to true to determine the localization according to the languages + supported by Mapbox Streets, + it will look for the Preferred Language Order setting in the Language & Region section of Settings. + If it doesn't fing a match it will fall back to english localization. + */ +@property (nonatomic, getter=isLocalizingLabels) BOOL localizingLabels; + @end NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index eb838085d72..b19ed1c4f1d 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -21,6 +21,7 @@ #import "MGLSource.h" #import "MGLTileSource_Private.h" #import "MGLVectorSource.h" +#import "MGLVectorSource+MBXAdditions.h" #import "MGLRasterSource.h" #import "MGLShapeSource.h" @@ -609,4 +610,59 @@ - (NSString *)description self.URL ? [NSString stringWithFormat:@"\"%@\"", self.URL] : self.URL]; } +#pragma mark Style language preferences + +- (void)setLocalizingLabels:(BOOL)localizingLabels +{ + _localizingLabels = localizingLabels; + + if (localizingLabels) { + NSString *preferredLanguage = [MGLVectorSource preferredMapboxStreetsLanguage]; + NSMutableDictionary *localizedKeysByKeyBySourceIdentifier = [NSMutableDictionary dictionary]; + for (MGLSymbolStyleLayer *layer in self.layers) { + if (![layer isKindOfClass:[MGLSymbolStyleLayer class]]) { + continue; + } + + MGLVectorSource *source = (MGLVectorSource *)[self sourceWithIdentifier:layer.sourceIdentifier]; + if (![source isKindOfClass:[MGLVectorSource class]] || !source.mapboxStreets) { + continue; + } + + NSDictionary *localizedKeysByKey = localizedKeysByKeyBySourceIdentifier[layer.sourceIdentifier]; + if (!localizedKeysByKey) { + localizedKeysByKey = localizedKeysByKeyBySourceIdentifier[layer.sourceIdentifier] = [source localizedKeysByKeyForPreferredLanguage:preferredLanguage]; + } + + NSString *(^stringByLocalizingString)(NSString *) = ^ NSString * (NSString *string) { + NSMutableString *localizedString = string.mutableCopy; + [localizedKeysByKey enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSString * _Nonnull localizedKey, BOOL * _Nonnull stop) { + NSAssert([key isKindOfClass:[NSString class]], @"key is not a string"); + NSAssert([localizedKey isKindOfClass:[NSString class]], @"localizedKey is not a string"); + [localizedString replaceOccurrencesOfString:[NSString stringWithFormat:@"{%@}", key] + withString:[NSString stringWithFormat:@"{%@}", localizedKey] + options:0 + range:NSMakeRange(0, localizedString.length)]; + }]; + return localizedString; + }; + + if ([layer.text isKindOfClass:[MGLConstantStyleValue class]]) { + NSString *textField = [(MGLConstantStyleValue *)layer.text rawValue]; + layer.text = [MGLStyleValue valueWithRawValue:stringByLocalizingString(textField)]; + } + else if ([layer.text isKindOfClass:[MGLCameraStyleFunction class]]) { + MGLCameraStyleFunction *function = (MGLCameraStyleFunction *)layer.text; + NSMutableDictionary *stops = function.stops.mutableCopy; + [stops enumerateKeysAndObjectsUsingBlock:^(NSNumber *zoomLevel, MGLConstantStyleValue *stop, BOOL *done) { + NSString *textField = stop.rawValue; + stops[zoomLevel] = [MGLStyleValue valueWithRawValue:stringByLocalizingString(textField)]; + }]; + function.stops = stops; + layer.text = function; + } + } + } +} + @end diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 14a5f2d54df..9cc4c42e5a4 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -1128,68 +1128,9 @@ - (void)wakeGL:(__unused NSNotification *)notification [self validateLocationServices]; [MGLMapboxEvents pushEvent:MGLEventTypeMapLoad withAttributes:@{}]; - - [self updateLocalization]; - } -} - -- (void)updateLocalization -{ - NSString *mapboxLanguage = [[NSUserDefaults standardUserDefaults] stringForKey:@"MGLMapboxLanguage"]; - NSString *language = [[[NSBundle mainBundle] preferredLocalizations] firstObject]; - NSString *preferredLanguageCode = [self preferredLanguageCode]; - - if (![mapboxLanguage isEqualToString:language] && ![mapboxLanguage isEqualToString:preferredLanguageCode]) { - mapboxLanguage = preferredLanguageCode; - [[NSUserDefaults standardUserDefaults] setObject:mapboxLanguage forKey:@"MGLMapboxLanguage"]; - [self setLabelLanguage:mapboxLanguage]; - [[NSNotificationCenter defaultCenter] postNotificationName:NSCurrentLocaleDidChangeNotification object:nil]; - } -} - -- (void)setLabelLanguage:(NSString *)language -{ - NSString *preferredNameToken = [NSString stringWithFormat:@"{name_%@}", language]; - - for (MGLSymbolStyleLayer *layer in [[self style] layers]) { - if (![layer isKindOfClass:[MGLSymbolStyleLayer class]]) { - continue; - } - - if ([layer.text isKindOfClass:[MGLConstantStyleValue class]]) { - MGLConstantStyleValue *label = (MGLConstantStyleValue *)layer.text; - if ([label.rawValue hasPrefix:@"{name"]) { - layer.text = [MGLStyleValue valueWithRawValue:preferredNameToken]; - } - } else if ([layer.text isKindOfClass:[MGLCameraStyleFunction class]]) { - MGLCameraStyleFunction *function = (MGLCameraStyleFunction *)layer.text; - NSMutableDictionary *stops = function.stops.mutableCopy; - [stops enumerateKeysAndObjectsUsingBlock:^(NSNumber *zoomLevel, MGLConstantStyleValue *stop, BOOL *done) { - if ([stop.rawValue hasPrefix:@"{name"]) { - stops[zoomLevel] = [MGLStyleValue valueWithRawValue:preferredNameToken]; - } - }]; - function.stops = stops; - layer.text = function; - } } } -- (NSString *)preferredLanguageCode { - // Languages supported by Mapbox Streets v10. - NSSet *supportedLanguages = [NSSet setWithObjects:@"en", @"es", @"fr", @"de", @"ru", @"zh", nil]; - NSArray *preferredLanguages = [NSLocale preferredLanguages]; - - for (NSString *language in preferredLanguages) { - NSString *languageCode = [[NSLocale localeWithLocaleIdentifier:language] objectForKey:NSLocaleLanguageCode]; - if ([supportedLanguages containsObject:languageCode]) { - return languageCode; - } - } - - return @"en"; -} - - (void)setHidden:(BOOL)hidden { super.hidden = hidden; From d5949862213fc241ceee3017b5ce24cab4c2d64f Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Tue, 25 Jul 2017 16:37:28 -0700 Subject: [PATCH 4/9] [ios, macos] Clarify style localization documentation. --- platform/darwin/src/MGLStyle.h | 14 ++++++++------ platform/darwin/src/MGLStyle.mm | 6 +++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/platform/darwin/src/MGLStyle.h b/platform/darwin/src/MGLStyle.h index 19b4ce8b14a..c5c2500ebbd 100644 --- a/platform/darwin/src/MGLStyle.h +++ b/platform/darwin/src/MGLStyle.h @@ -613,12 +613,14 @@ MGL_EXPORT #pragma mark Managing Style's localization /** - Set to true to determine the localization according to the languages - supported by Mapbox Streets, - it will look for the Preferred Language Order setting in the Language & Region section of Settings. - If it doesn't fing a match it will fall back to english localization. - */ -@property (nonatomic, getter=isLocalizingLabels) BOOL localizingLabels; + Enable it to determine the localization according to the languages + supported by the Vector Style source + Mapbox Streets, it will look for the Preferred Language Order setting in + the system's Language & Region section of Settings. If it doesn't find a + match it will fall back to english localization. + */ +@property (nonatomic, getter=isLocalizeLabels) BOOL localizeLabels; @end diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index b19ed1c4f1d..909da23c51d 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -612,11 +612,11 @@ - (NSString *)description #pragma mark Style language preferences -- (void)setLocalizingLabels:(BOOL)localizingLabels +- (void)setLocalizeLabels:(BOOL)localizeLabels { - _localizingLabels = localizingLabels; + _localizeLabels = localizeLabels; - if (localizingLabels) { + if (_localizeLabels) { NSString *preferredLanguage = [MGLVectorSource preferredMapboxStreetsLanguage]; NSMutableDictionary *localizedKeysByKeyBySourceIdentifier = [NSMutableDictionary dictionary]; for (MGLSymbolStyleLayer *layer in self.layers) { From f54923d1f1d69cdd28bb4dcce7209acfd9c5b092 Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Tue, 25 Jul 2017 16:59:19 -0700 Subject: [PATCH 5/9] [ios, macos] Update localization examples --- platform/ios/app/MBXViewController.m | 40 +---------------------- platform/macos/app/MapDocument.m | 47 +--------------------------- 2 files changed, 2 insertions(+), 85 deletions(-) diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index d3927374a7a..1ac51465276 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -1274,12 +1274,7 @@ - (void)styleRasterSource -(void)styleCountryLabelsLanguage { - NSArray *labelLayers = @[ - @"country-label-lg", - @"country-label-md", - @"country-label-sm", - ]; - [self styleLabelLanguageForLayersNamed:labelLayers]; + [self.mapView.style setLocalizeLabels:YES]; } - (void)styleRouteLine @@ -1362,39 +1357,6 @@ - (void)stylePolygonWithDDS { [self.mapView.style addLayer:fillStyleLayer]; } -- (void)styleLabelLanguageForLayersNamed:(NSArray *)layers -{ - _usingLocaleBasedCountryLabels = !_usingLocaleBasedCountryLabels; - NSString *bestLanguageForUser = [NSString stringWithFormat:@"{name_%@}", [self bestLanguageForUser]]; - NSString *language = _usingLocaleBasedCountryLabels ? bestLanguageForUser : @"{name}"; - - for (NSString *layerName in layers) { - MGLSymbolStyleLayer *layer = (MGLSymbolStyleLayer *)[self.mapView.style layerWithIdentifier:layerName]; - - if ([layer isKindOfClass:[MGLSymbolStyleLayer class]]) { - if ([layer.text isKindOfClass:[MGLConstantStyleValue class]]) { - MGLConstantStyleValue *label = (MGLConstantStyleValue *)layer.text; - if ([label.rawValue hasPrefix:@"{name"]) { - layer.text = [MGLStyleValue valueWithRawValue:language]; - } - } - else if ([layer.text isKindOfClass:[MGLCameraStyleFunction class]]) { - MGLCameraStyleFunction *function = (MGLCameraStyleFunction *)layer.text; - NSMutableDictionary *stops = function.stops.mutableCopy; - [stops enumerateKeysAndObjectsUsingBlock:^(NSNumber *zoomLevel, MGLConstantStyleValue *stop, BOOL *done) { - if ([stop.rawValue hasPrefix:@"{name"]) { - stops[zoomLevel] = [MGLStyleValue valueWithRawValue:language]; - } - }]; - function.stops = stops; - layer.text = function; - } - } else { - NSLog(@"%@ is not a symbol style layer", layerName); - } - } -} - - (NSString *)bestLanguageForUser { // https://www.mapbox.com/vector-tiles/mapbox-streets-v7/#overview diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m index 59844d363e9..e17db07bbf5 100644 --- a/platform/macos/app/MapDocument.m +++ b/platform/macos/app/MapDocument.m @@ -344,52 +344,7 @@ - (IBAction)setLabelLanguage:(NSMenuItem *)sender { } - (void)updateLabels { - MGLStyle *style = self.mapView.style; - NSString *preferredLanguage = _isLocalizingLabels ? [MGLVectorSource preferredMapboxStreetsLanguage] : nil; - NSMutableDictionary *localizedKeysByKeyBySourceIdentifier = [NSMutableDictionary dictionary]; - for (MGLSymbolStyleLayer *layer in style.layers) { - if (![layer isKindOfClass:[MGLSymbolStyleLayer class]]) { - continue; - } - - MGLVectorSource *source = (MGLVectorSource *)[style sourceWithIdentifier:layer.sourceIdentifier]; - if (![source isKindOfClass:[MGLVectorSource class]] || !source.mapboxStreets) { - continue; - } - - NSDictionary *localizedKeysByKey = localizedKeysByKeyBySourceIdentifier[layer.sourceIdentifier]; - if (!localizedKeysByKey) { - localizedKeysByKey = localizedKeysByKeyBySourceIdentifier[layer.sourceIdentifier] = [source localizedKeysByKeyForPreferredLanguage:preferredLanguage]; - } - - NSString *(^stringByLocalizingString)(NSString *) = ^ NSString * (NSString *string) { - NSMutableString *localizedString = string.mutableCopy; - [localizedKeysByKey enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSString * _Nonnull localizedKey, BOOL * _Nonnull stop) { - NSAssert([key isKindOfClass:[NSString class]], @"key is not a string"); - NSAssert([localizedKey isKindOfClass:[NSString class]], @"localizedKey is not a string"); - [localizedString replaceOccurrencesOfString:[NSString stringWithFormat:@"{%@}", key] - withString:[NSString stringWithFormat:@"{%@}", localizedKey] - options:0 - range:NSMakeRange(0, localizedString.length)]; - }]; - return localizedString; - }; - - if ([layer.text isKindOfClass:[MGLConstantStyleValue class]]) { - NSString *textField = [(MGLConstantStyleValue *)layer.text rawValue]; - layer.text = [MGLStyleValue valueWithRawValue:stringByLocalizingString(textField)]; - } - else if ([layer.text isKindOfClass:[MGLCameraStyleFunction class]]) { - MGLCameraStyleFunction *function = (MGLCameraStyleFunction *)layer.text; - NSMutableDictionary *stops = function.stops.mutableCopy; - [stops enumerateKeysAndObjectsUsingBlock:^(NSNumber *zoomLevel, MGLConstantStyleValue *stop, BOOL *done) { - NSString *textField = stop.rawValue; - stops[zoomLevel] = [MGLStyleValue valueWithRawValue:stringByLocalizingString(textField)]; - }]; - function.stops = stops; - layer.text = function; - } - } + [self.mapView.style setLocalizeLabels:YES]; } - (void)applyPendingState { From 110757c7f34e3fe30c6088507be7ab19d075e344 Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Wed, 26 Jul 2017 16:34:17 -0700 Subject: [PATCH 6/9] [ios, macos] Add style language reset to original. --- platform/darwin/src/MGLStyle.h | 19 +++++----- platform/darwin/src/MGLStyle.mm | 54 +++++++++++++++++++++++++--- platform/ios/app/MBXViewController.m | 2 +- platform/macos/app/MapDocument.m | 2 +- 4 files changed, 62 insertions(+), 15 deletions(-) diff --git a/platform/darwin/src/MGLStyle.h b/platform/darwin/src/MGLStyle.h index c5c2500ebbd..eb69915b222 100644 --- a/platform/darwin/src/MGLStyle.h +++ b/platform/darwin/src/MGLStyle.h @@ -613,14 +613,17 @@ MGL_EXPORT #pragma mark Managing Style's localization /** - Enable it to determine the localization according to the languages - supported by the Vector Style source - Mapbox Streets, it will look for the Preferred Language Order setting in - the system's Language & Region section of Settings. If it doesn't find a - match it will fall back to english localization. - */ -@property (nonatomic, getter=isLocalizeLabels) BOOL localizeLabels; + A Boolean value that determines whether the style attempts to localize labels in + the style into the system’s preferred language. + + When this property is enabled, the style automatically modifies the text property + of any symbol style layer whose source is the + Mapbox + Streets source. On iOS, the user can set the system’s preferred language in + Settings, General Settings, Language & Region. On macOS, the user can set the + system’s preferred language in the Language & Region pane of System Preferences. + */ +@property (nonatomic) BOOL localizesLabels; @end diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index 909da23c51d..8e2137b1244 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -54,6 +54,7 @@ @interface MGLStyle() @property (nonatomic, readwrite, weak) MGLMapView *mapView; @property (readonly, copy, nullable) NSURL *URL; @property (nonatomic, readwrite, strong) NS_MUTABLE_DICTIONARY_OF(NSString *, MGLOpenGLStyleLayer *) *openGLLayers; +@property (nonatomic) NS_MUTABLE_DICTIONARY_OF(NSString *, NS_DICTIONARY_OF(NSString *, NSString*) *) *localizedLayersByIdentifier; @end @@ -117,6 +118,7 @@ - (instancetype)initWithMapView:(MGLMapView *)mapView { if (self = [super init]) { _mapView = mapView; _openGLLayers = [NSMutableDictionary dictionary]; + _localizedLayersByIdentifier = [NSMutableDictionary dictionary]; } return self; } @@ -612,11 +614,15 @@ - (NSString *)description #pragma mark Style language preferences -- (void)setLocalizeLabels:(BOOL)localizeLabels +- (void)setLocalizesLabels:(BOOL)localizesLabels { - _localizeLabels = localizeLabels; + if (_localizesLabels != localizesLabels) { + _localizesLabels = localizesLabels; + } else { + return; + } - if (_localizeLabels) { + if (_localizesLabels) { NSString *preferredLanguage = [MGLVectorSource preferredMapboxStreetsLanguage]; NSMutableDictionary *localizedKeysByKeyBySourceIdentifier = [NSMutableDictionary dictionary]; for (MGLSymbolStyleLayer *layer in self.layers) { @@ -649,19 +655,57 @@ - (void)setLocalizeLabels:(BOOL)localizeLabels if ([layer.text isKindOfClass:[MGLConstantStyleValue class]]) { NSString *textField = [(MGLConstantStyleValue *)layer.text rawValue]; - layer.text = [MGLStyleValue valueWithRawValue:stringByLocalizingString(textField)]; + NSString *localizingString = stringByLocalizingString(textField); + if (![textField isEqualToString:localizingString]) { + [self.localizedLayersByIdentifier setObject:@{ textField : localizingString } forKey:layer.identifier]; + layer.text = [MGLStyleValue valueWithRawValue:localizingString]; + } + } + else if ([layer.text isKindOfClass:[MGLCameraStyleFunction class]]) { + MGLCameraStyleFunction *function = (MGLCameraStyleFunction *)layer.text; + NSMutableDictionary *stops = function.stops.mutableCopy; + [stops enumerateKeysAndObjectsUsingBlock:^(NSNumber *zoomLevel, MGLConstantStyleValue *stop, BOOL *done) { + NSString *textField = stop.rawValue; + NSString *localizingString = stringByLocalizingString(textField); + if (![textField isEqualToString:localizingString]) { + [self.localizedLayersByIdentifier setObject:@{ textField : localizingString } forKey:layer.identifier]; + stops[zoomLevel] = [MGLStyleValue valueWithRawValue:localizingString]; + } + + }]; + function.stops = stops; + layer.text = function; + } + } + } else { + for (NSString *identifier in self.localizedLayersByIdentifier) { + MGLSymbolStyleLayer *layer = (MGLSymbolStyleLayer *)[self.mapView.style layerWithIdentifier:identifier]; + NSDictionary *languages = [self.localizedLayersByIdentifier objectForKey:identifier]; + NSString *originalLanguage = [languages allKeys].firstObject; + NSString *changedLanguage = [languages objectForKey:originalLanguage]; + + if ([layer.text isKindOfClass:[MGLConstantStyleValue class]]) { + NSString *textField = [(MGLConstantStyleValue *)layer.text rawValue]; + if ([changedLanguage isEqualToString:textField]) { + layer.text = [MGLStyleValue valueWithRawValue:originalLanguage]; + } + } else if ([layer.text isKindOfClass:[MGLCameraStyleFunction class]]) { MGLCameraStyleFunction *function = (MGLCameraStyleFunction *)layer.text; NSMutableDictionary *stops = function.stops.mutableCopy; [stops enumerateKeysAndObjectsUsingBlock:^(NSNumber *zoomLevel, MGLConstantStyleValue *stop, BOOL *done) { NSString *textField = stop.rawValue; - stops[zoomLevel] = [MGLStyleValue valueWithRawValue:stringByLocalizingString(textField)]; + if ([changedLanguage isEqualToString:textField]) { + stops[zoomLevel] = [MGLStyleValue valueWithRawValue:originalLanguage]; + } + }]; function.stops = stops; layer.text = function; } } + self.localizedLayersByIdentifier = [NSMutableDictionary dictionary]; } } diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 1ac51465276..7d9f3cbd31b 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -1274,7 +1274,7 @@ - (void)styleRasterSource -(void)styleCountryLabelsLanguage { - [self.mapView.style setLocalizeLabels:YES]; + [self.mapView.style setLocalizesLabels:YES]; } - (void)styleRouteLine diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m index e17db07bbf5..c73771611d7 100644 --- a/platform/macos/app/MapDocument.m +++ b/platform/macos/app/MapDocument.m @@ -344,7 +344,7 @@ - (IBAction)setLabelLanguage:(NSMenuItem *)sender { } - (void)updateLabels { - [self.mapView.style setLocalizeLabels:YES]; + [self.mapView.style setLocalizesLabels:YES]; } - (void)applyPendingState { From e42a5993364392cb68d6fa69a088c09247b64f2b Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Wed, 26 Jul 2017 17:25:24 -0700 Subject: [PATCH 7/9] [ios, macos] Update changelogs. --- platform/darwin/src/MGLStyle.h | 2 +- platform/macos/CHANGELOG.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/platform/darwin/src/MGLStyle.h b/platform/darwin/src/MGLStyle.h index eb69915b222..c3a97322424 100644 --- a/platform/darwin/src/MGLStyle.h +++ b/platform/darwin/src/MGLStyle.h @@ -610,7 +610,7 @@ MGL_EXPORT */ @property (nonatomic, strong) MGLLight *light; -#pragma mark Managing Style's localization +#pragma mark Style's localization /** A Boolean value that determines whether the style attempts to localize labels in diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md index f69f7e1b5db..b9b87fee7a7 100644 --- a/platform/macos/CHANGELOG.md +++ b/platform/macos/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog for Mapbox macOS SDK +## 0.5.1 + +* Added support to adapt Mapbox Streets–sourced layers for user preferred language. ([#9582](https://github.com/mapbox/mapbox-gl-native/pull/9582)) + ## 0.5.0 This version of the Mapbox macOS SDK corresponds to version 3.6.0 of the Mapbox iOS SDK. From 5ececfb35e04f4976bfb10da02387f68478bfbf0 Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Thu, 27 Jul 2017 09:47:02 -0700 Subject: [PATCH 8/9] [ios, macos] Rename Vector Source Additions to MGL standard. --- platform/darwin/src/MGLStyle.mm | 2 +- ...tions.h => MGLVectorSource+MGLAdditions.h} | 2 +- ...tions.m => MGLVectorSource+MGLAdditions.m} | 4 ++-- platform/ios/ios.xcodeproj/project.pbxproj | 24 +++++++++---------- platform/macos/app/MapDocument.m | 2 +- .../macos/macos.xcodeproj/project.pbxproj | 16 ++++++------- 6 files changed, 25 insertions(+), 25 deletions(-) rename platform/darwin/src/{MGLVectorSource+MBXAdditions.h => MGLVectorSource+MGLAdditions.h} (88%) rename platform/darwin/src/{MGLVectorSource+MBXAdditions.m => MGLVectorSource+MGLAdditions.m} (96%) diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index 8e2137b1244..d7e0197c359 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -21,7 +21,7 @@ #import "MGLSource.h" #import "MGLTileSource_Private.h" #import "MGLVectorSource.h" -#import "MGLVectorSource+MBXAdditions.h" +#import "MGLVectorSource+MGLAdditions.h" #import "MGLRasterSource.h" #import "MGLShapeSource.h" diff --git a/platform/darwin/src/MGLVectorSource+MBXAdditions.h b/platform/darwin/src/MGLVectorSource+MGLAdditions.h similarity index 88% rename from platform/darwin/src/MGLVectorSource+MBXAdditions.h rename to platform/darwin/src/MGLVectorSource+MGLAdditions.h index 1e25ee5a601..43b0aba747a 100644 --- a/platform/darwin/src/MGLVectorSource+MBXAdditions.h +++ b/platform/darwin/src/MGLVectorSource+MGLAdditions.h @@ -2,7 +2,7 @@ NS_ASSUME_NONNULL_BEGIN -@interface MGLVectorSource (MBXAdditions) +@interface MGLVectorSource (MGLAdditions) + (NSString *)preferredMapboxStreetsLanguage; diff --git a/platform/darwin/src/MGLVectorSource+MBXAdditions.m b/platform/darwin/src/MGLVectorSource+MGLAdditions.m similarity index 96% rename from platform/darwin/src/MGLVectorSource+MBXAdditions.m rename to platform/darwin/src/MGLVectorSource+MGLAdditions.m index 323bc74366c..a3053881176 100644 --- a/platform/darwin/src/MGLVectorSource+MBXAdditions.m +++ b/platform/darwin/src/MGLVectorSource+MGLAdditions.m @@ -1,6 +1,6 @@ -#import "MGLVectorSource+MBXAdditions.h" +#import "MGLVectorSource+MGLAdditions.h" -@implementation MGLVectorSource (MBXAdditions) +@implementation MGLVectorSource (MGLAdditions) + (NS_SET_OF(NSString *) *)mapboxStreetsLanguages { // https://www.mapbox.com/vector-tiles/mapbox-streets-v7/#overview diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 73d2c6a1246..83b267df43a 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -17,10 +17,10 @@ 1F7454971ECD450D00021D39 /* MGLLight_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F7454941ECD450D00021D39 /* MGLLight_Private.h */; }; 1F7454A91ED08AB400021D39 /* MGLLightTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F7454A61ED08AB400021D39 /* MGLLightTest.mm */; }; 1F95931D1E6DE2E900D5B294 /* MGLNSDateAdditionsTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F95931C1E6DE2E900D5B294 /* MGLNSDateAdditionsTests.mm */; }; - 1FDD9D6F1F26936400252B09 /* MGLVectorSource+MBXAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FDD9D6D1F26936400252B09 /* MGLVectorSource+MBXAdditions.h */; }; - 1FDD9D701F26936400252B09 /* MGLVectorSource+MBXAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FDD9D6E1F26936400252B09 /* MGLVectorSource+MBXAdditions.m */; }; - 1FDD9D711F26937A00252B09 /* MGLVectorSource+MBXAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FDD9D6D1F26936400252B09 /* MGLVectorSource+MBXAdditions.h */; }; - 1FDD9D721F26938300252B09 /* MGLVectorSource+MBXAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FDD9D6E1F26936400252B09 /* MGLVectorSource+MBXAdditions.m */; }; + 1FB7DAAF1F2A4DBD00410606 /* MGLVectorSource+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FDD9D6D1F26936400252B09 /* MGLVectorSource+MGLAdditions.h */; }; + 1FB7DAB01F2A4DC200410606 /* MGLVectorSource+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FDD9D6D1F26936400252B09 /* MGLVectorSource+MGLAdditions.h */; }; + 1FB7DAB11F2A4DC800410606 /* MGLVectorSource+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FDD9D6E1F26936400252B09 /* MGLVectorSource+MGLAdditions.m */; }; + 1FB7DAB21F2A4DC900410606 /* MGLVectorSource+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FDD9D6E1F26936400252B09 /* MGLVectorSource+MGLAdditions.m */; }; 30E578171DAA85520050F07E /* UIImage+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 30E578111DAA7D690050F07E /* UIImage+MGLAdditions.h */; }; 30E578181DAA85520050F07E /* UIImage+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 30E578111DAA7D690050F07E /* UIImage+MGLAdditions.h */; }; 30E578191DAA855E0050F07E /* UIImage+MGLAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 30E578121DAA7D690050F07E /* UIImage+MGLAdditions.mm */; }; @@ -551,8 +551,8 @@ 1F7454941ECD450D00021D39 /* MGLLight_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLLight_Private.h; sourceTree = ""; }; 1F7454A61ED08AB400021D39 /* MGLLightTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLLightTest.mm; path = ../../darwin/test/MGLLightTest.mm; sourceTree = ""; }; 1F95931C1E6DE2E900D5B294 /* MGLNSDateAdditionsTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLNSDateAdditionsTests.mm; path = ../../darwin/test/MGLNSDateAdditionsTests.mm; sourceTree = ""; }; - 1FDD9D6D1F26936400252B09 /* MGLVectorSource+MBXAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLVectorSource+MBXAdditions.h"; sourceTree = ""; }; - 1FDD9D6E1F26936400252B09 /* MGLVectorSource+MBXAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLVectorSource+MBXAdditions.m"; sourceTree = ""; }; + 1FDD9D6D1F26936400252B09 /* MGLVectorSource+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLVectorSource+MGLAdditions.h"; sourceTree = ""; }; + 1FDD9D6E1F26936400252B09 /* MGLVectorSource+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLVectorSource+MGLAdditions.m"; sourceTree = ""; }; 20DABE861DF78148007AC5FF /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Foundation.strings"; sourceTree = ""; }; 20DABE881DF78148007AC5FF /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = ""; }; 20DABE8A1DF78149007AC5FF /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Root.strings"; sourceTree = ""; }; @@ -1543,8 +1543,8 @@ DAD165831CF4CFED001FF4B9 /* Categories */ = { isa = PBXGroup; children = ( - 1FDD9D6D1F26936400252B09 /* MGLVectorSource+MBXAdditions.h */, - 1FDD9D6E1F26936400252B09 /* MGLVectorSource+MBXAdditions.m */, + 1FDD9D6D1F26936400252B09 /* MGLVectorSource+MGLAdditions.h */, + 1FDD9D6E1F26936400252B09 /* MGLVectorSource+MGLAdditions.m */, 7E016D821D9E890300A29A21 /* MGLPolygon+MGLAdditions.h */, 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */, 7E016D7C1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.h */, @@ -1650,6 +1650,7 @@ 350098DC1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.h in Headers */, DA8848231CBAFA6200AB86E3 /* MGLOfflineStorage_Private.h in Headers */, 404326891D5B9B27007111BD /* MGLAnnotationContainerView_Private.h in Headers */, + 1FB7DAAF1F2A4DBD00410606 /* MGLVectorSource+MGLAdditions.h in Headers */, DA88483B1CBAFB8500AB86E3 /* MGLCalloutView.h in Headers */, 35E0CFE61D3E501500188327 /* MGLStyle_Private.h in Headers */, 3510FFF01D6D9D8C00F413B2 /* NSExpression+MGLAdditions.h in Headers */, @@ -1735,7 +1736,6 @@ DA8848871CBB033F00AB86E3 /* Fabric.h in Headers */, 35305D4A1D22AA6A0007D005 /* NSData+MGLAdditions.h in Headers */, 359F57461D2FDDA6005217F1 /* MGLUserLocationAnnotationView_Private.h in Headers */, - 1FDD9D6F1F26936400252B09 /* MGLVectorSource+MBXAdditions.h in Headers */, 404C26E21D89B877000AA13D /* MGLTileSource.h in Headers */, DA8848841CBB033F00AB86E3 /* FABAttributes.h in Headers */, DA8847FD1CBAFA5100AB86E3 /* MGLTilePyramidOfflineRegion.h in Headers */, @@ -1812,7 +1812,6 @@ DA35A2B21CCA141D00E826B2 /* MGLCompassDirectionFormatter.h in Headers */, DAF0D8141DFE0EC500B28378 /* MGLVectorSource_Private.h in Headers */, DABFB8731CBE9A9900D62B32 /* Mapbox.h in Headers */, - 1FDD9D711F26937A00252B09 /* MGLVectorSource+MBXAdditions.h in Headers */, 357FE2DE1E02D2B20068B753 /* NSCoder+MGLAdditions.h in Headers */, 1753ED431E53CE6F00A9FD90 /* MGLConversion.h in Headers */, 354B83971D2E873E005D9406 /* MGLUserLocationAnnotationView.h in Headers */, @@ -1829,6 +1828,7 @@ 35136D4D1D4277FC00C20EFD /* MGLSource.h in Headers */, DA35A2BC1CCA9A6900E826B2 /* MGLClockDirectionFormatter.h in Headers */, 35D13AC41D3D19DD00AFB4E0 /* MGLFillStyleLayer.h in Headers */, + 1FB7DAB01F2A4DC200410606 /* MGLVectorSource+MGLAdditions.h in Headers */, DABFB86E1CBE9A0F00D62B32 /* MGLCalloutView.h in Headers */, 1F7454971ECD450D00021D39 /* MGLLight_Private.h in Headers */, DABFB8601CBE99E500D62B32 /* MGLMapCamera.h in Headers */, @@ -2207,6 +2207,7 @@ 9620BB3A1E69FE1700705A1D /* MGLSDKUpdateChecker.mm in Sources */, 354B83981D2E873E005D9406 /* MGLUserLocationAnnotationView.m in Sources */, DA88485D1CBAFB9800AB86E3 /* MGLFaux3DUserLocationAnnotationView.m in Sources */, + 1FB7DAB11F2A4DC800410606 /* MGLVectorSource+MGLAdditions.m in Sources */, DAD165701CF41981001FF4B9 /* MGLFeature.mm in Sources */, 30E578191DAA855E0050F07E /* UIImage+MGLAdditions.mm in Sources */, 40EDA1C11CFE0E0500D9EA68 /* MGLAnnotationContainerView.m in Sources */, @@ -2214,7 +2215,6 @@ DA8848251CBAFA6200AB86E3 /* MGLPointAnnotation.mm in Sources */, 35136D3C1D42272500C20EFD /* MGLCircleStyleLayer.mm in Sources */, DD9BE4F81EB263C50079A3AF /* UIViewController+MGLAdditions.m in Sources */, - 1FDD9D701F26936400252B09 /* MGLVectorSource+MBXAdditions.m in Sources */, 350098DE1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.mm in Sources */, DA6408DD1DA4E7D300908C90 /* MGLVectorStyleLayer.m in Sources */, 3566C7681D4A77BA008152BC /* MGLShapeSource.mm in Sources */, @@ -2290,6 +2290,7 @@ 9620BB3B1E69FE1700705A1D /* MGLSDKUpdateChecker.mm in Sources */, DAA4E4221CBB730400178DFB /* MGLPointAnnotation.mm in Sources */, DAED38661D62D0FC00D7640F /* NSURL+MGLAdditions.m in Sources */, + 1FB7DAB21F2A4DC900410606 /* MGLVectorSource+MGLAdditions.m in Sources */, DAD165711CF41981001FF4B9 /* MGLFeature.mm in Sources */, 30E5781A1DAA855E0050F07E /* UIImage+MGLAdditions.mm in Sources */, 40EDA1C21CFE0E0500D9EA68 /* MGLAnnotationContainerView.m in Sources */, @@ -2297,7 +2298,6 @@ DAA4E42E1CBB730400178DFB /* MGLAPIClient.m in Sources */, 35136D3D1D42272500C20EFD /* MGLCircleStyleLayer.mm in Sources */, DD9BE4FA1EB263F40079A3AF /* UIViewController+MGLAdditions.m in Sources */, - 1FDD9D721F26938300252B09 /* MGLVectorSource+MBXAdditions.m in Sources */, 350098DF1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.mm in Sources */, DA6408DE1DA4E7D300908C90 /* MGLVectorStyleLayer.m in Sources */, 3566C7691D4A77BA008152BC /* MGLShapeSource.mm in Sources */, diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m index c73771611d7..0cda78b5fa6 100644 --- a/platform/macos/app/MapDocument.m +++ b/platform/macos/app/MapDocument.m @@ -5,7 +5,7 @@ #import "DroppedPinAnnotation.h" #import "MGLStyle+MBXAdditions.h" -#import "MGLVectorSource+MBXAdditions.h" +#import "MGLVectorSource+MGLAdditions.h" #import diff --git a/platform/macos/macos.xcodeproj/project.pbxproj b/platform/macos/macos.xcodeproj/project.pbxproj index 162f3881c5c..00cb6ce975f 100644 --- a/platform/macos/macos.xcodeproj/project.pbxproj +++ b/platform/macos/macos.xcodeproj/project.pbxproj @@ -13,8 +13,8 @@ 1F7454A51ECFB00300021D39 /* MGLLight.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F7454A21ECFB00300021D39 /* MGLLight.mm */; }; 1F7454AB1ED1DDBD00021D39 /* MGLLightTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F7454AA1ED1DDBD00021D39 /* MGLLightTest.mm */; }; 1F95931B1E6DE2B600D5B294 /* MGLNSDateAdditionsTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F95931A1E6DE2B600D5B294 /* MGLNSDateAdditionsTests.mm */; }; - 1FDD9D6B1F26923400252B09 /* MGLVectorSource+MBXAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FDD9D681F26922400252B09 /* MGLVectorSource+MBXAdditions.h */; }; - 1FDD9D6C1F26924100252B09 /* MGLVectorSource+MBXAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FDD9D691F26922400252B09 /* MGLVectorSource+MBXAdditions.m */; }; + 1FCDF1421F2A4F3600A46694 /* MGLVectorSource+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FCDF1401F2A4F3600A46694 /* MGLVectorSource+MGLAdditions.h */; }; + 1FCDF1431F2A4F3600A46694 /* MGLVectorSource+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FCDF1411F2A4F3600A46694 /* MGLVectorSource+MGLAdditions.m */; }; 30E5781B1DAA857E0050F07E /* NSImage+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 30E578141DAA7D920050F07E /* NSImage+MGLAdditions.h */; }; 3508EC641D749D39009B0EE4 /* NSExpression+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 3508EC621D749D39009B0EE4 /* NSExpression+MGLAdditions.h */; }; 3508EC651D749D39009B0EE4 /* NSExpression+MGLAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3508EC631D749D39009B0EE4 /* NSExpression+MGLAdditions.mm */; }; @@ -278,8 +278,8 @@ 1F7454A21ECFB00300021D39 /* MGLLight.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLLight.mm; sourceTree = ""; }; 1F7454AA1ED1DDBD00021D39 /* MGLLightTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLLightTest.mm; sourceTree = ""; }; 1F95931A1E6DE2B600D5B294 /* MGLNSDateAdditionsTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLNSDateAdditionsTests.mm; path = ../../darwin/test/MGLNSDateAdditionsTests.mm; sourceTree = ""; }; - 1FDD9D681F26922400252B09 /* MGLVectorSource+MBXAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLVectorSource+MBXAdditions.h"; sourceTree = ""; }; - 1FDD9D691F26922400252B09 /* MGLVectorSource+MBXAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLVectorSource+MBXAdditions.m"; sourceTree = ""; }; + 1FCDF1401F2A4F3600A46694 /* MGLVectorSource+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLVectorSource+MGLAdditions.h"; sourceTree = ""; }; + 1FCDF1411F2A4F3600A46694 /* MGLVectorSource+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLVectorSource+MGLAdditions.m"; sourceTree = ""; }; 30E578141DAA7D920050F07E /* NSImage+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSImage+MGLAdditions.h"; path = "src/NSImage+MGLAdditions.h"; sourceTree = SOURCE_ROOT; }; 3508EC621D749D39009B0EE4 /* NSExpression+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSExpression+MGLAdditions.h"; sourceTree = ""; }; 3508EC631D749D39009B0EE4 /* NSExpression+MGLAdditions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "NSExpression+MGLAdditions.mm"; sourceTree = ""; }; @@ -919,8 +919,8 @@ DAD1657F1CF4CF50001FF4B9 /* Categories */ = { isa = PBXGroup; children = ( - 1FDD9D681F26922400252B09 /* MGLVectorSource+MBXAdditions.h */, - 1FDD9D691F26922400252B09 /* MGLVectorSource+MBXAdditions.m */, + 1FCDF1401F2A4F3600A46694 /* MGLVectorSource+MGLAdditions.h */, + 1FCDF1411F2A4F3600A46694 /* MGLVectorSource+MGLAdditions.m */, 408AA8601DAEED3300022900 /* MGLPolygon+MGLAdditions.h */, 408AA85C1DAEED3300022900 /* MGLPolygon+MGLAdditions.m */, 408AA8611DAEED3300022900 /* MGLPolyline+MGLAdditions.h */, @@ -1155,6 +1155,7 @@ DAE6C3601CC31E0400DB3429 /* MGLOfflineRegion.h in Headers */, DAE6C3681CC31E0400DB3429 /* MGLTilePyramidOfflineRegion.h in Headers */, DA35A2CF1CCAAED300E826B2 /* NSValue+MGLAdditions.h in Headers */, + 1FCDF1421F2A4F3600A46694 /* MGLVectorSource+MGLAdditions.h in Headers */, DAE6C3A61CC31E9400DB3429 /* MGLMapViewDelegate.h in Headers */, DAE6C38B1CC31E2A00DB3429 /* MGLOfflinePack_Private.h in Headers */, 558DE7A61E56161C00C7916D /* MGLFoundation_Private.h in Headers */, @@ -1162,7 +1163,6 @@ 3538AA231D542685008EC33D /* MGLStyleLayer.h in Headers */, DAE6C35C1CC31E0400DB3429 /* MGLGeometry.h in Headers */, DAE6C35A1CC31E0400DB3429 /* MGLAccountManager.h in Headers */, - 1FDD9D6B1F26923400252B09 /* MGLVectorSource+MBXAdditions.h in Headers */, DA551B821DB496AC0009AFAF /* MGLTileSource.h in Headers */, 35602C001D3EA9B40050646F /* MGLForegroundStyleLayer.h in Headers */, DAE6C35D1CC31E0400DB3429 /* MGLMapCamera.h in Headers */, @@ -1395,6 +1395,7 @@ 40B77E461DB11BCD003DA2FE /* NSArray+MGLAdditions.mm in Sources */, DAE6C38C1CC31E2A00DB3429 /* MGLOfflinePack.mm in Sources */, 35D65C5B1D65AD5500722C23 /* NSDate+MGLAdditions.mm in Sources */, + 1FCDF1431F2A4F3600A46694 /* MGLVectorSource+MGLAdditions.m in Sources */, DD0902B21DB1AC6400C5BDCE /* MGLNetworkConfiguration.m in Sources */, 1F7454A51ECFB00300021D39 /* MGLLight.mm in Sources */, DAE6C3B11CC31EF300DB3429 /* MGLAnnotationImage.m in Sources */, @@ -1432,7 +1433,6 @@ DAE6C3911CC31E2A00DB3429 /* MGLPolygon.mm in Sources */, 35C6DF851E214C0400ACA483 /* MGLDistanceFormatter.m in Sources */, DAE6C39B1CC31E2A00DB3429 /* NSProcessInfo+MGLAdditions.m in Sources */, - 1FDD9D6C1F26924100252B09 /* MGLVectorSource+MBXAdditions.m in Sources */, DAA998FC1E9F545C002E6EA6 /* MGLFillExtrusionStyleLayer.mm in Sources */, DAE6C38F1CC31E2A00DB3429 /* MGLOfflineStorage.mm in Sources */, DAED38601D62CED700D7640F /* NSURL+MGLAdditions.m in Sources */, From 2c77056fa142bf8a3ac3d9f4e7e001e5a892322d Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Mon, 31 Jul 2017 17:14:32 -0400 Subject: [PATCH 9/9] [ios, macos] Add suport for stop localization. --- platform/darwin/src/MGLStyle.h | 2 +- platform/darwin/src/MGLStyle.mm | 70 +++++++++++++++++++++------- platform/ios/CHANGELOG.md | 6 ++- platform/ios/app/MBXViewController.m | 5 +- platform/macos/CHANGELOG.md | 2 +- platform/macos/app/MapDocument.m | 2 +- 6 files changed, 64 insertions(+), 23 deletions(-) diff --git a/platform/darwin/src/MGLStyle.h b/platform/darwin/src/MGLStyle.h index c3a97322424..8c009d22c61 100644 --- a/platform/darwin/src/MGLStyle.h +++ b/platform/darwin/src/MGLStyle.h @@ -610,7 +610,7 @@ MGL_EXPORT */ @property (nonatomic, strong) MGLLight *light; -#pragma mark Style's localization +#pragma mark Localizing Map Content /** A Boolean value that determines whether the style attempts to localize labels in diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index d7e0197c359..1e0a2e02b76 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -49,12 +49,34 @@ #import "NSImage+MGLAdditions.h" #endif +/** + Model class for localization changes. + */ +@interface MGLTextLanguage: NSObject +@property (strong, nonatomic) NSString *originalTextField; +@property (strong, nonatomic) NSString *updatedTextField; + +- (instancetype)initWithTextLanguage:(NSString *)originalTextField updatedTextField:(NSString *)updatedTextField; + +@end + +@implementation MGLTextLanguage +- (instancetype)initWithTextLanguage:(NSString *)originalTextField updatedTextField:(NSString *)updatedTextField +{ + if (self = [super init]) { + _originalTextField = originalTextField; + _updatedTextField = updatedTextField; + } + return self; +} +@end + @interface MGLStyle() @property (nonatomic, readwrite, weak) MGLMapView *mapView; @property (readonly, copy, nullable) NSURL *URL; @property (nonatomic, readwrite, strong) NS_MUTABLE_DICTIONARY_OF(NSString *, MGLOpenGLStyleLayer *) *openGLLayers; -@property (nonatomic) NS_MUTABLE_DICTIONARY_OF(NSString *, NS_DICTIONARY_OF(NSString *, NSString*) *) *localizedLayersByIdentifier; +@property (nonatomic) NS_MUTABLE_DICTIONARY_OF(NSString *, NS_DICTIONARY_OF(NSObject *, MGLTextLanguage *) *) *localizedLayersByIdentifier; @end @@ -657,54 +679,68 @@ - (void)setLocalizesLabels:(BOOL)localizesLabels NSString *textField = [(MGLConstantStyleValue *)layer.text rawValue]; NSString *localizingString = stringByLocalizingString(textField); if (![textField isEqualToString:localizingString]) { - [self.localizedLayersByIdentifier setObject:@{ textField : localizingString } forKey:layer.identifier]; + MGLTextLanguage *textLanguage = [[MGLTextLanguage alloc] initWithTextLanguage:textField + updatedTextField:localizingString]; + [self.localizedLayersByIdentifier setObject:@{ textField : textLanguage } forKey:layer.identifier]; layer.text = [MGLStyleValue valueWithRawValue:localizingString]; } } else if ([layer.text isKindOfClass:[MGLCameraStyleFunction class]]) { MGLCameraStyleFunction *function = (MGLCameraStyleFunction *)layer.text; NSMutableDictionary *stops = function.stops.mutableCopy; + NSMutableDictionary *cameraStops = [NSMutableDictionary dictionary]; [stops enumerateKeysAndObjectsUsingBlock:^(NSNumber *zoomLevel, MGLConstantStyleValue *stop, BOOL *done) { NSString *textField = stop.rawValue; NSString *localizingString = stringByLocalizingString(textField); if (![textField isEqualToString:localizingString]) { - [self.localizedLayersByIdentifier setObject:@{ textField : localizingString } forKey:layer.identifier]; + MGLTextLanguage *textLanguage = [[MGLTextLanguage alloc] initWithTextLanguage:textField + updatedTextField:localizingString]; + [cameraStops setObject:textLanguage forKey:zoomLevel]; stops[zoomLevel] = [MGLStyleValue valueWithRawValue:localizingString]; } }]; + if (cameraStops.count > 0) { + [self.localizedLayersByIdentifier setObject:cameraStops forKey:layer.identifier]; + } function.stops = stops; layer.text = function; } } } else { - for (NSString *identifier in self.localizedLayersByIdentifier) { + + [self.localizedLayersByIdentifier enumerateKeysAndObjectsUsingBlock:^(NSString *identifier, NSDictionary *textFields, BOOL *done) { MGLSymbolStyleLayer *layer = (MGLSymbolStyleLayer *)[self.mapView.style layerWithIdentifier:identifier]; - NSDictionary *languages = [self.localizedLayersByIdentifier objectForKey:identifier]; - NSString *originalLanguage = [languages allKeys].firstObject; - NSString *changedLanguage = [languages objectForKey:originalLanguage]; if ([layer.text isKindOfClass:[MGLConstantStyleValue class]]) { NSString *textField = [(MGLConstantStyleValue *)layer.text rawValue]; - if ([changedLanguage isEqualToString:textField]) { - layer.text = [MGLStyleValue valueWithRawValue:originalLanguage]; - } - + [textFields enumerateKeysAndObjectsUsingBlock:^(NSObject *originalLanguage, MGLTextLanguage *textLanguage, BOOL *done) { + if ([textLanguage.updatedTextField isEqualToString:textField]) { + layer.text = [MGLStyleValue valueWithRawValue:textLanguage.originalTextField]; + } + }]; + } else if ([layer.text isKindOfClass:[MGLCameraStyleFunction class]]) { MGLCameraStyleFunction *function = (MGLCameraStyleFunction *)layer.text; NSMutableDictionary *stops = function.stops.mutableCopy; - [stops enumerateKeysAndObjectsUsingBlock:^(NSNumber *zoomLevel, MGLConstantStyleValue *stop, BOOL *done) { - NSString *textField = stop.rawValue; - if ([changedLanguage isEqualToString:textField]) { - stops[zoomLevel] = [MGLStyleValue valueWithRawValue:originalLanguage]; + [textFields enumerateKeysAndObjectsUsingBlock:^(NSObject *zoomKey, MGLTextLanguage *textLanguage, BOOL *done) { + if ([zoomKey isKindOfClass:[NSNumber class]]) { + NSNumber *zoomLevel = (NSNumber*)zoomKey; + MGLConstantStyleValue *stop = [stops objectForKey:zoomLevel]; + NSString *textField = stop.rawValue; + if ([textLanguage.updatedTextField isEqualToString:textField]) { + stops[zoomLevel] = [MGLStyleValue valueWithRawValue:textLanguage.originalTextField]; + } } - }]; + function.stops = stops; layer.text = function; } - } + + }]; + self.localizedLayersByIdentifier = [NSMutableDictionary dictionary]; } } diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index 43df49a9aca..55790577cdc 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -2,7 +2,11 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONTRIBUTING.md](../../CONTRIBUTING.md) to get started. -## 3.6.1 +## 3.6.2 + +* Added an MGLStyle.localizesLabels property, off by default, that localizes any Mapbox Streets–sourced symbol layer into the user’s preferred language. ([#9582](https://github.com/mapbox/mapbox-gl-native/pull/9582)) + +## 3.6.1 - July 28, 2017 * Reduced the size of the dynamic framework by optimizing symbol visibility. ([#7604](https://github.com/mapbox/mapbox-gl-native/pull/7604)) * Fixed an issue where the attribution button would have its custom tint color reset when the map view received a tint color change notification, such as when an alert controller was presented. ([#9598](https://github.com/mapbox/mapbox-gl-native/pull/9598)) diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 7d9f3cbd31b..ebbc218017c 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -343,7 +343,7 @@ - (void)dismissSettings:(__unused id)sender @"Update Shape Source: Features", @"Style Vector Source", @"Style Raster Source", - [NSString stringWithFormat:@"Label Countries in %@", (_usingLocaleBasedCountryLabels ? @"Local Language" : [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:[self bestLanguageForUser]])], + [NSString stringWithFormat:@"Show Labels in %@", (_usingLocaleBasedCountryLabels ? @"Local Language" : [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:[self bestLanguageForUser]])], @"Add Route Line", @"Dynamically Style Polygon", ]]; @@ -1274,7 +1274,8 @@ - (void)styleRasterSource -(void)styleCountryLabelsLanguage { - [self.mapView.style setLocalizesLabels:YES]; + _usingLocaleBasedCountryLabels = !_usingLocaleBasedCountryLabels; + self.mapView.style.localizesLabels = _usingLocaleBasedCountryLabels; } - (void)styleRouteLine diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md index b9b87fee7a7..1af3c03d688 100644 --- a/platform/macos/CHANGELOG.md +++ b/platform/macos/CHANGELOG.md @@ -2,7 +2,7 @@ ## 0.5.1 -* Added support to adapt Mapbox Streets–sourced layers for user preferred language. ([#9582](https://github.com/mapbox/mapbox-gl-native/pull/9582)) +* Added an MGLStyle.localizesLabels property, off by default, that localizes any Mapbox Streets–sourced symbol layer into the user’s preferred language. ([#9582](https://github.com/mapbox/mapbox-gl-native/pull/9582)) ## 0.5.0 diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m index 0cda78b5fa6..1d22295f50a 100644 --- a/platform/macos/app/MapDocument.m +++ b/platform/macos/app/MapDocument.m @@ -344,7 +344,7 @@ - (IBAction)setLabelLanguage:(NSMenuItem *)sender { } - (void)updateLabels { - [self.mapView.style setLocalizesLabels:YES]; + self.mapView.style.localizesLabels = _isLocalizingLabels; } - (void)applyPendingState {