Skip to content

Reimplement label localization atop Expression (redux)#3330

Merged
1ec5 merged 3 commits into
mainfrom
1ec5-label-l10n-upstream
Sep 16, 2021
Merged

Reimplement label localization atop Expression (redux)#3330
1ec5 merged 3 commits into
mainfrom
1ec5-label-l10n-upstream

Conversation

@1ec5
Copy link
Copy Markdown
Contributor

@1ec5 1ec5 commented Sep 7, 2021

Restored the NavigationMapView.localizeLabels() implementation for automatically localizing map labels into the user’s language. The previous implementation was removed as part of upgrading to map SDK v10 in #2808, because it relied on an NSExpression-based localization feature in map SDK v6.x. This implementation continues to be based on the map SDK’s built-in label localization functionality rather than reinventing the wheel as in #2933.

/cc @mapbox/navigation-ios @neelmistry94 @tobrun

@1ec5 1ec5 added feature New feature request. topic: localization labels Sep 7, 2021
@1ec5 1ec5 added this to the v2.0.0 (RC) milestone Sep 7, 2021
@1ec5 1ec5 self-assigned this Sep 7, 2021
@1ec5 1ec5 requested a review from a team September 7, 2021 09:38
Comment on lines 161 to 162
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I consolidated this operation with the block above. I’m pretty sure all of these style customizations need to be reapplied every time the style changes.

Comment thread Sources/MapboxNavigation/MapView.swift Outdated
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Road labels are untouched and remain in English if the original style had them in English, as does the default Mapbox Navigation Day/Night v1 style. This is due to a missing special case upstream: mapbox/mapbox-maps-ios#653. It’s a regression from v1.x.

Comment on lines 277 to 280
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Localization is currently broken for most Chinese locales, including Simplified Chinese and Hong Kong Traditional Chinese: mapbox/mapbox-maps-ios#652.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worked around this issue for now by ensuring that only supported locales make it through to the map SDK.

Comment on lines 285 to 255
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The map SDK throws a fatal error rather if we pass in an unsupported Locale: mapbox/mapbox-maps-ios#655. This is problematic because the user could have set the system language preference to some language that the Streets source doesn’t support, triggering a crash. If this issue isn’t fixed upstream, we’ll have to hard-code the same array of supported languages in the navigation SDK, making it even more difficult for the server team to add support for new language.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this issue isn’t fixed upstream, we’ll have to hard-code the same array of supported languages in the navigation SDK, making it even more difficult for the server team to add support for new language.

I wound up implementing this workaround for now. We can easily remove the workaround once the map SDK is fixed.

Comment thread Sources/MapboxNavigation/CarPlayMapViewController.swift Outdated
Comment thread Sources/MapboxNavigation/MapView.swift Outdated
Comment thread Sources/MapboxNavigation/MapView.swift Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mapbox/navigation-ios do we know if it is safe to change to onEvery?

Copy link
Copy Markdown
Contributor Author

@1ec5 1ec5 Sep 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of #3332, the only thing left using .onNext will be the call to localizeLabels(), which does need to be reapplied every time the style changes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also not sure that we should apply this change. Basically now any changes to the NavigationMapView.mapView.showsTraffic, which were made by the end user will be ignored.

Copy link
Copy Markdown
Contributor Author

@1ec5 1ec5 Sep 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any time the style changes, their change to showsTraffic would get blown away anyways. If the developer manually makes any runtime styling change to the style, they need to either respond to StyleManagerDelegate methods or use onEvery(_:handler:) – that would include showsTraffic.

Comment thread Sources/MapboxNavigation/CarPlayMapViewController.swift Outdated
Comment on lines 47 to 52
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up porting +[MGLVectorTileSource preferredMapboxStreetsLanguageForPreferences:] from map SDK v6.x to work around mapbox/mapbox-maps-ios#652 and mapbox/mapbox-maps-ios#655. I would very much like not to have to hard-code the supported Mapbox Streets source locales in this codebase, but this is the only way to work around the blanking and crashing issues for now.

Comment on lines 285 to 255
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this issue isn’t fixed upstream, we’ll have to hard-code the same array of supported languages in the navigation SDK, making it even more difficult for the server team to add support for new language.

I wound up implementing this workaround for now. We can easily remove the workaround once the map SDK is fixed.

Comment on lines 277 to 280
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worked around this issue for now by ensuring that only supported locales make it through to the map SDK.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also not sure that we should apply this change. Basically now any changes to the NavigationMapView.mapView.showsTraffic, which were made by the end user will be ignored.

Comment thread Tests/MapboxNavigationTests/MapViewTests.swift Outdated
@1ec5 1ec5 added the release blocker Needs to be resolved before the release. label Sep 14, 2021
@1ec5 1ec5 force-pushed the 1ec5-label-l10n-upstream branch from a390b3d to 6add4de Compare September 14, 2021 00:47
@1ec5

This comment has been minimized.

@S2Ler

This comment has been minimized.

@MaximAlien
Copy link
Copy Markdown
Contributor

Shall we also update changelog to mention that NavigationMapView.localizeLabels() now works?

Comment thread Sources/MapboxNavigation/CarPlayMapViewController.swift
@1ec5
Copy link
Copy Markdown
Contributor Author

1ec5 commented Sep 16, 2021

Shall we also update changelog to mention that NavigationMapView.localizeLabels() now works?

We should mention it in the next release candidate’s release notes but not the running changelog for v2.0.0, because it was already working in v1.x.

@1ec5 1ec5 force-pushed the 1ec5-label-l10n-upstream branch from 048c9f3 to 655735b Compare September 16, 2021 01:21
Ported language preference selection logic from MGLVectorTileSource in map SDK v6.x. Used this logic to ensure that the map SDK is only ever asked to localize labels into a language it supports.
@1ec5 1ec5 force-pushed the 1ec5-label-l10n-upstream branch from 655735b to 54031cf Compare September 16, 2021 19:30
@1ec5 1ec5 merged commit 5ef9335 into main Sep 16, 2021
@1ec5 1ec5 deleted the 1ec5-label-l10n-upstream branch September 16, 2021 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature request. release blocker Needs to be resolved before the release. topic: localization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants