Skip to content

Frontend changes to support multilingual labels #878

Closed
OpenHistoricalMap/ohm-website
#291

Description

@danrademacher

Last piece from #481 is to modify the front end to load the name key that matches a user's language.

Here's @1ec5 s year-old notes from 481:

Pick out the relevant changes from openstreetmap/openstreetmap-website#4042, specifically the parts that install Mapbox GL Language and configure it to prefer the logged-in user’s language preference.

More recently, Minh did the work on the embed site to make Mabox GL Language work. This was a little tricky, so reference his code:
OpenHistoricalMap/openhistoricalmap-embed#8

Activity

  1. added
    internationalization
    on Aug 27, 2024
  2. danrademacher commented on Nov 22, 2024

    @danrademacher
    Author

    Some notes from conversation with Eric, which he will add details to:

    • Initial work on this has not been successful so far, so nothing has been committed
    • On theory is that because we're not using a MapLibre Map but instead a Leaflet plugin, some tings are not handled by that plugin and that's causing issues.

    @erictheise will post more details here so we can get more brains on this problem.

  3. 1ec5 commented on Nov 23, 2024

    @1ec5
    Member

    On theory is that because we're not using a MapLibre Map but instead a Leaflet plugin, some tings are not handled by that plugin and that's causing issues.

    openstreetmap/openstreetmap-website#4042 is successfully using the same plugin with Leaflet. I wonder if it’s basically a race condition. We seem to have a lot of our map customizations tied to the time slider loading: #915.

  4. danrademacher commented on Dec 3, 2024

    @danrademacher
    Author

    @erictheise can you please add the notes we talked about your adding here?

  5. erictheise commented on Dec 3, 2024

    @erictheise
    Contributor

    My attention has been on upstream catchup but the last thing I tried was adding

    //= require maplibre-gl
    //= require @maplibre/maplibre-gl-leaflet
    //= require @mapbox/mapbox-gl-language
    //= require i18n
    

    at the beginning of app/assets/javascripts/leaflet.map.js and incorporating

        historical.addControl(new MapboxLanguage({
          defaultLanguage: 'mul'
        }));
    

    into the push of the historical layer at https://github.com/OpenHistoricalMap/ohm-website/blob/43b6c1bf455a92eb1b4969c18ffd83c2d63f95ba/app/assets/javascripts/leaflet.map.js#L86

  6. erictheise commented on Dec 3, 2024

    @erictheise
    Contributor

    I started down the path of incorporating the maptiler code in openstreetmap/openstreetmap-website#4042 but worried we'd regret it later. That pull request is a year and half old and seemed unlikely to be incorporated into upstream but apparently it is still under discussion and may be moving forward. See https://osmfoundation.org/wiki/Operations/Minutes/2024-10-31#OpenMapTiles_application

  7. erictheise commented on Dec 3, 2024

    @erictheise
    Contributor

    My earliest attempt instantiated a MaplibreGL with the mechanisms in https://github.com/maptiler/openstreetmap-website/blob/888767144630f56340097450c362edc639a771d8/app/assets/javascripts/leaflet.map.js#L19-L49, then pushed that into all of our styles which seemed like the right way to go but although I got it to a point where it loaded without error it produced no visible effect on maps.

    My IDE frustratingly seems not to have kept the memory of that work but I should be able to reconstruct it.

  8. erictheise commented on Dec 3, 2024

    @erictheise
    Contributor

    The wording and API at the repo for maplibre-gl-leaflet made me wonder if it supported what we're trying to do here but Minh points out above that it must.

  9. 1ec5 commented on Dec 3, 2024

    @1ec5
    Member

    Conceptually, any runtime styling modifications for localizing labels need to happen at about the same time that we first apply the date filter to the map. As long as that happens early enough, Leaflet should pick up the modifications along with the date filter. However, if it happens too late, it’s possible that Leaflet will take some time to reflect the changes, if at all. I’ve seen that happen sporadically with the date filter too, but it isn’t very deterministic.

  10. 9 remaining items

  11. erictheise commented on May 8, 2025

    @erictheise
    Contributor

    we haven’t overridden the default: OpenHistoricalMap/ohm-website#289 (comment).

    The embed site accepts any string of any length in the language param. I believe the main site should perform a validation on the string before adding it to a user's language.supportedLanguages. I was going to propose a regex based on RFC 5646 and see that we may already have one as a result of the discussion in 948.

    A similar validation should be in place when edits are received.

  12. 1ec5 commented on May 8, 2025

    @1ec5
    Member

    For the embed site, the only impact of specifying an invalid language parameter is that everything falls back to multilingual labels, as if you had specified mul. (Ideally, everything would fall back to the next language in the list, on a feature by feature basis, but mapbox-gl-language doesn’t support that.)

    Anyways, I don’t think that has anything to do with why Hindi isn’t working. The screenshot shows that the preference is correctly set to hi.

  13. 1ec5 commented on May 9, 2025

    @1ec5
    Member

    @jeffreyameyer noticed that the map crashes on an uncaught exception when you set the language to a valid code that isn’t supported by Mapbox Streets, such as zh (Chinese, but without specifying a script).

    Uncaught Error: Language zh is not supported

    OpenHistoricalMap/ohm-website#289 (comment) is the fix for this issue.

  14. added a commit that references this issue on May 13, 2025
  15. erictheise commented on May 13, 2025

    @erictheise
    Contributor

    @jeffreyameyer noticed that the map crashes on an uncaught exception when you set the language to a valid code that isn’t supported by Mapbox Streets, such as zh (Chinese, but without specifying a script).

    I was not able to duplicate this on staging.

  16. erictheise commented on May 13, 2025

    @erictheise
    Contributor

    I added many new labels to the testbed as part of #1050 today. That work has not made it to the staging tiles so all I can offer is screenshots of my dev environment using production tiles. This is the area at /#map=16/70.01184/-42.33122&layers=O&date=1925-05-13&daterange=1825-01-01,2025-12-31 and you will see that the various types of waterways and the one town pick up and properly display the labels.

    en (and zh):

    Image

    de:

    Image

    ru:

    Image

    cs:

    Image

    el:

    Image
  17. erictheise commented on May 13, 2025

    @erictheise
    Contributor

    I left the console.info statements in on purpose to help with debugging if people have questions but they should come out after a few iterations.

    Image
  18. moved this from In Progress to On Staging in OpenHistoricalMap Dev Planningon May 13, 2025
  19. moved this from On Staging to Ready for Staging in OpenHistoricalMap Dev Planningon May 13, 2025
  20. moved this from Ready for Staging to On Staging in OpenHistoricalMap Dev Planningon May 13, 2025
  21. moved this from On Staging to In Production in OpenHistoricalMap Dev Planningon May 14, 2025
  22. erictheise commented on May 14, 2025

    @erictheise
    Contributor

    Verified via the testbed that multilingual labels are working in production.

  23. Elaws commented on May 26, 2025

    @Elaws

    Hi,

    With language settings defined as :

    Image

    Map labels still display in their original language :

    Image

    Is this expected behavior ? Is their a way to display these labels in French or English ?

    Thank you very much.

  24. 1ec5 commented on May 27, 2025

    @1ec5
    Member

    Thanks for noticing – that’s a known issue, now tracked in #1068.

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

Metadata

Metadata

Assignees

Labels

internationalizationwebsite

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions