Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localize map labels #1111

Merged
merged 2 commits into from
Feb 14, 2018
Merged

Localize map labels #1111

merged 2 commits into from
Feb 14, 2018

Conversation

1ec5
Copy link
Contributor

@1ec5 1ec5 commented Feb 14, 2018

Added a public localizeLabels() method to NavigationMapView for localizing all the labels: road labels are localized into the local language (the name tag in OpenStreetMap, matching the Mapbox Directions API), while place and POI labels are localized into the system’s preferred language if supported by the Mapbox Streets source, falling back to the local language.

The map view embedded in NavigationViewController calls this method automatically, so no developer intervention is typically required for the turn-by-turn map. However, the developer is encouraged to call localizesLabels() on any standalone NavigationMapView from within MGLMapViewDelegate.mapView(_:didFinishLoading:).

This change required porting about half of the MGLStyle.localizesLabels implementation from Objective-C to Swift. MGLStyle.localizesLabels isn’t quite adequate, because it’s a two-way option between the style’s original language (English in the case of the Mapbox Navigation Guidance styles) and the system’s preferred language, with no option to use the local language that matches signage. This map SDK API will be revamped as part of mapbox/mapbox-gl-native#10713.

preview turn-by-turn

Fixes #755.

/cc @bsudekum @frederoni @nickidlugash

@1ec5 1ec5 self-assigned this Feb 14, 2018
@@ -316,6 +316,8 @@ class ViewController: UIViewController, MGLMapViewDelegate, CLLocationManagerDel
}

func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
self.mapView?.localizeLabels()
Copy link
Contributor

Choose a reason for hiding this comment

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

Is self needed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, because localizesLabels() is defined on NavigationMapView, not MGLMapView. The MGLMapView-typed mapView argument takes precedence, so we have to either use the NavigationMapView-typed property or cast the argument to a NavigationMapView.

@1ec5 1ec5 merged commit cd0e5ae into master Feb 14, 2018
@1ec5 1ec5 deleted the 1ec5-localize-labels-755 branch February 14, 2018 20:10
@maliesa96
Copy link

Is it possible to prevent road labels from being localized? I would like them to appear in english on the banner at the top (and preferably the map) but haven't been able to accomplish this.

@1ec5
Copy link
Contributor Author

1ec5 commented Dec 19, 2018

This PR only localizes point of interest labels, not road names. Road names are never localized in this SDK; that is, they always appear in the local language and are never tailored to the user’s preferred language. In part that’s because it’s important to match what the user sees out the window on signage while driving, whatever the user’s language. But it’s also because OSRM currently only provides the local names in the route data (Project-OSRM/osrm-backend#4561), which is used for the turn banner, so we make sure the map matches the turn banner for consistency.

If you want to localize road labels on the map into English and are OK with these labels potentially differing from what’s in the turn banner and out the window, pass the en locale into MGLStyle.localizeLabels(into:) inside your implementation of MGLMapViewDelegate.mapView(_:didFinishLoading:).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants