-
Notifications
You must be signed in to change notification settings - Fork 313
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
Localize map labels #1111
Conversation
@@ -316,6 +316,8 @@ class ViewController: UIViewController, MGLMapViewDelegate, CLLocationManagerDel | |||
} | |||
|
|||
func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) { | |||
self.mapView?.localizeLabels() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is self needed here?
There was a problem hiding this comment.
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.
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. |
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 |
Added a public
localizeLabels()
method to NavigationMapView for localizing all the labels: road labels are localized into the local language (thename
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 withinMGLMapViewDelegate.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.Fixes #755.
/cc @bsudekum @frederoni @nickidlugash