Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions platform/darwin/src/MGLMapSnapshotter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#import "MGLAttributionInfo_Private.h"
#import "MGLLoggingConfiguration_Private.h"
#import "MGLRendererConfiguration.h"
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
#import "MGLMapboxEvents.h"
#endif

#if TARGET_OS_IPHONE
#import "UIImage+MGLAdditions.h"
Expand Down Expand Up @@ -155,6 +158,9 @@ - (instancetype)initWithOptions:(MGLMapSnapshotOptions *)options
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:UIApplicationWillTerminateNotification object:nil];
#else
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil];
#endif
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
[MGLMapboxEvents pushTurnstileEvent];
#endif
}
return self;
Expand Down
4 changes: 2 additions & 2 deletions platform/darwin/src/MGLVectorTileSource.mm
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ @implementation MGLVectorTileSource (Private)
An array of locale codes with dedicated name fields in the Mapbox Streets
source.

https://www.mapbox.com/vector-tiles/mapbox-streets-v7/#overview
https://www.mapbox.com/vector-tiles/mapbox-streets-v8/
*/
static NSArray * const MGLMapboxStreetsLanguages = @[
@"ar", @"de", @"en", @"es", @"fr", @"ja", @"ko", @"pt", @"ru", @"zh",
Expand Down Expand Up @@ -141,7 +141,7 @@ - (BOOL)isMapboxStreets {
return NO;
}
NSArray *identifiers = [url.host componentsSeparatedByString:@","];
return [identifiers containsObject:@"mapbox.mapbox-streets-v7"] || [identifiers containsObject:@"mapbox.mapbox-streets-v6"];
return [identifiers containsObject:@"mapbox.mapbox-streets-v8"] || [identifiers containsObject:@"mapbox.mapbox-streets-v7"];
}

@end
21 changes: 12 additions & 9 deletions platform/darwin/src/NSExpression+MGLAdditions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1398,12 +1398,16 @@ - (id)mgl_jsonHasExpressionObject {
- (NSExpression *)mgl_expressionLocalizedIntoLocale:(nullable NSLocale *)locale {
switch (self.expressionType) {
case NSConstantValueExpressionType: {
NSDictionary *stops = self.constantValue;
if ([stops isKindOfClass:[NSDictionary class]]) {
NSDictionary *localizedStops = MGLLocalizedStopDictionary(stops, locale);
if (localizedStops != stops) {
if ([self.constantValue isKindOfClass:[NSDictionary class]]) {
NSDictionary *localizedStops = MGLLocalizedStopDictionary(self.constantValue, locale);
if (localizedStops != self.constantValue) {
return [NSExpression expressionForConstantValue:localizedStops];
}
} else if ([self.constantValue isKindOfClass:[NSArray class]]) {
NSArray *localizedValues = MGLLocalizedCollection(self.constantValue, locale);
if (localizedValues != self.constantValue) {
return [NSExpression expressionForConstantValue:localizedValues];
}
}
return self;
}
Expand All @@ -1422,19 +1426,18 @@ - (NSExpression *)mgl_expressionLocalizedIntoLocale:(nullable NSLocale *)locale
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 the keypath is `name_zh-Hans`, fallback to `name_zh` to `name`.
// 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
// Mapbox Streets v8 has `name_zh-Hant`, we should fallback to Simplified Chinese if the field 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"];
}
Expand Down
13 changes: 11 additions & 2 deletions platform/darwin/test/MGLExpressionTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1072,10 +1072,19 @@ - (void)testLocalization {
}
{
NSExpression *original = [NSExpression expressionForKeyPath:@"name_en"];
NSExpression *expected = [NSExpression expressionWithFormat:@"mgl_coalesce({%K, %K, %K, %K})",
@"name_zh-Hans", @"name_zh-CN", @"name_zh", @"name"];
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);
}
{
NSExpression *original = [NSExpression expressionWithFormat:@"mgl_coalesce({%K, %K})", @"name_en", @"name"];
NSExpression *expected = [NSExpression expressionWithFormat:@"mgl_coalesce:({mgl_coalesce:({name_en, name}), mgl_coalesce:({name_en, name})})"];
XCTAssertEqualObjects([original mgl_expressionLocalizedIntoLocale:nil], expected);
}
{
NSExpression *original = [NSExpression expressionWithFormat:@"mgl_coalesce({%K, %K})", @"name_en", @"name"];
NSExpression *expected = [NSExpression expressionWithFormat:@"mgl_coalesce:({mgl_coalesce:({name_ja, name}), mgl_coalesce:({name_ja, name})})"];
XCTAssertEqualObjects([original mgl_expressionLocalizedIntoLocale:[NSLocale localeWithLocaleIdentifier:@"ja-JP"]], expected);
}
{
NSExpression *original = [NSExpression expressionForKeyPath:@"name_en"];
NSExpression *expected = [NSExpression expressionForKeyPath:@"name"];
Expand Down
1 change: 1 addition & 0 deletions platform/ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
* Added an `-[MGLStyle removeSource:error:]` method that returns a descriptive error if the style fails to remove the source, whereas `-[MGLStyle removeSource:]` fails silently. ([#13399](https://github.com/mapbox/mapbox-gl-native/pull/13399))
* Added the `MGLFillExtrusionStyleLayer.fillExtrusionHasVerticalGradient` property. ([#13463](https://github.com/mapbox/mapbox-gl-native/pull/13463))
* Added support for setting `MGLCollisionBehaviorPre4_0` in `NSUserDefaults`. ([#13426](https://github.com/mapbox/mapbox-gl-native/pull/13426))
* `-[MGLStyle localizeLabelsIntoLocale:]` and `-[NSExpression(MGLAdditions) mgl_expressionLocalizedIntoLocale:]` can automatically localize styles that use version 8 of the Mapbox Streets source. ([#13481](https://github.com/mapbox/mapbox-gl-native/pull/13481))

### Map snapshots

Expand Down
9 changes: 4 additions & 5 deletions platform/ios/app/MBXViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ - (void)performActionForSettingAtIndexPath:(NSIndexPath *)indexPath
switch (indexPath.row)
{
case MBXSettingsMiscellaneousLocalizeLabels:
[self styleCountryLabelsLanguage];
[self toggleStyleLabelsLanguage];
break;
case MBXSettingsMiscellaneousWorldTour:
[self startWorldTour];
Expand Down Expand Up @@ -1432,7 +1432,7 @@ - (void)updateAnimatedImageSource:(NSTimer *)timer {
}
}

-(void)styleCountryLabelsLanguage
-(void)toggleStyleLabelsLanguage
{
_localizingLabels = !_localizingLabels;
[self.mapView.style localizeLabelsIntoLocale:_localizingLabels ? [NSLocale localeWithLocaleIdentifier:@"mul"] : nil];
Expand Down Expand Up @@ -1538,8 +1538,8 @@ - (void)addLatLonGrid

- (NSString *)bestLanguageForUser
{
// https://www.mapbox.com/vector-tiles/mapbox-streets-v7/#overview
NSArray *supportedLanguages = @[ @"ar", @"en", @"es", @"fr", @"de", @"pt", @"ru", @"zh", @"zh-Hans" ];
// https://www.mapbox.com/vector-tiles/mapbox-streets-v8/#name-text--name_lang-code-text
NSArray *supportedLanguages = @[ @"ar", @"de", @"en", @"es", @"fr", @"ja", @"ko", @"pt", @"ru", @"zh", @"zh-Hans", @"zh-Hant" ];
NSArray<NSString *> *preferredLanguages = [NSBundle preferredLocalizationsFromArray:supportedLanguages forPreferences:[NSLocale preferredLanguages]];
NSString *mostSpecificLanguage;

Expand Down Expand Up @@ -1920,7 +1920,6 @@ - (IBAction)cycleStyles:(__unused id)sender
[MGLStyle darkStyleURL],
[MGLStyle satelliteStyleURL],
[MGLStyle satelliteStreetsStyleURL]

];
NSAssert(styleNames.count == styleURLs.count, @"Style names and URLs don’t match.");

Expand Down
7 changes: 5 additions & 2 deletions platform/ios/src/MGLMapAccessibilityElement.mm
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ - (instancetype)initWithAccessibilityContainer:(id)container feature:(id<MGLFeat
NSMutableArray *facts = [NSMutableArray array];

// Announce the kind of place or POI.
if (attributes[@"type"]) {
NSString *languageCode = [MGLVectorTileSource preferredMapboxStreetsLanguage];
NSString *categoryAttribute = [NSString stringWithFormat:@"category_%@", languageCode];
if (attributes[categoryAttribute]) {
[facts addObject:attributes[categoryAttribute]];
} else if (attributes[@"type"]) {
// FIXME: Unfortunately, these types aren’t a closed set that can be
// localized, since they’re based on OpenStreetMap tags.
NSString *type = [attributes[@"type"] stringByReplacingOccurrencesOfString:@"_"
Expand All @@ -88,7 +92,6 @@ - (instancetype)initWithAccessibilityContainer:(id)container feature:(id<MGLFeat
// Announce the kind of airport, rail station, or mountain based on its
// Maki image name.
else if (attributes[@"maki"]) {
// TODO: Localize Maki image names.
[facts addObject:attributes[@"maki"]];
}

Expand Down
1 change: 1 addition & 0 deletions platform/macos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Added an `-[MGLStyle removeSource:error:]` method that returns a descriptive error if the style fails to remove the source, whereas `-[MGLStyle removeSource:]` fails silently. ([#13399](https://github.com/mapbox/mapbox-gl-native/pull/13399))
* Added the `MGLFillExtrusionStyleLayer.fillExtrusionHasVerticalGradient` property. ([#13463](https://github.com/mapbox/mapbox-gl-native/pull/13463))
* Added support for setting `MGLCollisionBehaviorPre4_0` in `NSUserDefaults`. ([#13426](https://github.com/mapbox/mapbox-gl-native/pull/13426))
* Added support for automatic localization of version 8 of the Mapbox Streets source. ([#13481](https://github.com/mapbox/mapbox-gl-native/pull/13481))

### Other changes

Expand Down