-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Automatic label localization should transform non-constant expressions #10713
Comments
The intermediate level of dictionaries appears to be used in order to store different values for different stops. This approach isn’t going to work with expressions (#8074), which can be much more complex. Instead, one possible approach would be to:
For example, if the system language is French and the
would become:
(Note that Then, if the
None of the variable references would have to change, and the original evaluated values of the expressions – whatever attributes they referred to – would be restored. Unfortunately, I think we should wait to implement this robust localization approach until we have a robust foundation to build it on. For one thing, it relies on being able to round-trip completely and reliably from an In the meantime, we can at least keep localizing constant values, relying on the fact that the /cc @anandthakker @tobrun |
#10944 would have mbgl provide an expression transformation method. Since it would take an |
I think we should consider approaches to label localization that don't rely on mutating style property values. That approach sounds complex to implement, requires coordination between the SDK implementers and the style authors, and turns out to be one of the causes of unexpectedly disabling style revalidation/refreshing (mapbox/mapbox-gl-js#4225 (comment)). (Furthermore, it's difficult to see how a "componentized" style would solve the refresh issue, because the nature of this strategy is to reach into whatever "component" has labels and mutate their internals.) A better model would be to extend the expression language such that the style property expression could make reference to a bit of external state, controlled by the SDK, which indicates the desired localization. This external state would be decoupled from the style itself, which could remain independently refreshed. (I believe there have been several proposals to add this kind of parameterization mechanism.) |
I agree that localization would ideally be a built-in feature of the style language, rather than something grafted on at the platform-specific level. mapbox/mapbox-gl-js#6197 proposes a couple expression operators that would supplant the manual runtime styling operations that The proposal isn’t quite as decoupled as you’re suggesting, because TileJSON doesn’t provide GL with enough context to decide which feature property to use for a given language. This isn’t a new problem, of course, but I feel better about hard-coding the Mapbox Streets source’s supported languages in an SDK feature than about doing the same as part of the style file format.
There are many ways in which a developer would end up using the runtime styling API implicitly. Label localization via runtime styling isn’t specific to iOS/macOS; there’s a plugin for GL JS and soon there will be one for Android as well (mapbox/mapbox-plugins-android#74). All three localization tools are opt-in. The alternative is for application code to manually modify layers using runtime styling anyways. Besides label localization, the iOS traffic plugin and the navigation SDK both use runtime styling to add overlays to the map. The documentation for these packages doesn’t explicitly mention runtime styling, either, but style revalidation is nonetheless disabled when using them. While we wait for mapbox/mapbox-gl-js#6197, a short-term solution to the revalidation problem would be to document this behavior in the documentation for For now, I think we should find a way to preserve the current level of support for label localization, kludgy as it may be, because the only alternative is currently to burden the developer with implementing their own |
Currently, This implementation also relies on the legacy token syntax that has been removed from GL JS and will be removed from the native SDKs in #10399. Once that happens, It would be straightforward to implement logic to modify a top-level key path expression. That would mostly get us back to the current state, but it not address the regression from v3.7.x, and concatenated values such as The Cartography team is planning to introduce additional non-name fields that might be used as fallbacks for when no name is available in the user’s language, but these fields may not match one-for-one with name fields, which is the same problem we have with the English-only
|
Correction on this point: support for the token syntax has not and is not being removed; existing styles that use tokens will continue to work. #10399 is about avoiding a Hyrum's Law situation by not shipping a release in which it's possible to mix the expressions and token syntaxes. |
Thanks for the clarification. Regardless, core styles already use style functions and will be transitioning to interpolation expressions, so we’ll need to incorporate a small degree of non-constant expression support in |
The iOS navigation SDK has its own implementation of automatic label localization, since that library needs to use the local language to match the Direction API’s unlocalized response. mapbox/mapbox-navigation-ios#1076 updates that implementation for expressions. Tokens continue to be replaced, but now it digs into interpolation and step functions instead of style functions. The only new kind of expression that it localizes is key path expressions. I’m planning to upstream the navigation SDK implementation into this SDK, porting it to Objective-C. |
Fixed in #11651 on the release-boba branch for iOS map SDK v4.0.0 and macOS map SDK v0.7.0. |
With respect to the “delocalization” issues in #10713 (comment), note that #11651 essentially removes the ability to automatically delocalize a style: #11651 (comment). |
MGLStyle.localizedLayersByIdentifier
is a dictionary of dictionaries of MGLTextLanguage objects. The structure looks something like this:The intermediate level of dictionaries is unnecessary, because we could represent exactly the same information like this:
The way we apply
localizedLayersByIdentifier
is still problematic. If the developer:MGLStyle.localizesLabels
toYES
text
from{name_fr}
to{name_fr} ({ele})
MGLStyle.localizesLabels
back toNO
then the style layer’s
text
gets overridden back to{name_en}
. To avoid this problem, MGLTextLanguage should only keep track of whichname_*
property a given layer started out with, eliminating MGLTextLanguage:/cc @fabian-guerra
The text was updated successfully, but these errors were encountered: