feat:add map language control#385
Conversation
|
Preview is ready! 🚀 You can view it here: https://valhalla-app-tests.gis-ops.com/385 |
|
the video doesn't work on my machine/browser (maybe re-encode to smth else?). and just looking at the app I have no idea how I show shortbread tiles with english/german names. |
|
ah now it worked and my eyes didn't see the new map control. I think that's because that's a really strange place to put smth like that. we don't want 2 places with the same intention, language control. we want to rename the "directions language" dropdown and just always show it. then match to german/english for the map, everything else becomes "local". |
|
lastly, are you sure the stadiamaps "alidade smooth" doesn't offer language support? I'd be surprised if not. probably via a header. |
|
hey @nilsnolde |
|
Hi @nilsnolde |
nilsnolde
left a comment
There was a problem hiding this comment.
thanks, LGTM. and there's no AI note necessary in the PR description? I should've written the guidelines in a way to always put a AI note, no matter if used or not. now it's too ambiguous..
| const base = directionsLanguage.split('-')[0]; | ||
| if (base === 'en' || base === 'de') { |
|
there's actually one small thing that's already a problem now in master: on first page load the language doesn't get set in localstorage, so even though we fall back to system language, the map or instructions serve the "default" feel free to fix that in this PR. if not, we'll do it in a separate PR. it's more important now with (default) basemap language control than it was before with maneuver language, which the vast majority of people probably won't look at anyways when playing around. |
|
Hi @nilsnolde |
I think it's only consistent to change the behavior, i.e. only local if language doesn't have a match.
how about this? |
|
Agreed — current behavior already does that. If the system locale matches a supported language (e.g. en-*, de-DE), it uses that for both map labels and instructions. Otherwise it falls back to local names. AI Disclosure: Code was written by me. Used AI to help reframe PR descriptions and comments for grammar corrections :D |
| // Shortbread: simple string like "{name}", "{name_en}", "{name_de}" | ||
| if (typeof textField === 'string') { | ||
| if (!textField.match(/\{name(_[a-z]{2})?\}/)) continue; | ||
|
|
||
| const newTextField = langKey ? `{name_${langKey}}` : '{name}'; | ||
| map.setLayoutProperty(layer.id, 'text-field', newTextField); | ||
| continue; | ||
| } | ||
|
|
||
| // Alidade Smooth: expression-based, e.g. ["get", "name:latin"] | ||
| // or ["coalesce", ["get", "name:en"], ["get", "name:latin"]] | ||
| if (Array.isArray(textField)) { | ||
| const json = JSON.stringify(textField); | ||
| if (!json.includes('"name:') && !json.includes('"name"')) continue; |
There was a problem hiding this comment.
these ifs look a bit "smelly". I'm not sure if somehow making this more dependent on the MVT endpoint instead of field types (which is still a provider dependency, any MVT source can do anything to support languages) or name or whatever would make it more or less "smelly". wdyt @mustaphaturhan ?
Starting Step to close #384
🛠️ Fixes Issue
The issue was the map would show the names of the countries in the format of their own local language (eg- middle eastern countries name would be shown in arabic).
👨💻 Changes proposed
-src/components/map/index.tsx
-src/components/map/map-language-control.tsx
📄 Note to reviewers
Approach:
The Shortbread OSM vector tiles use text-field: "{name}" on all symbol layers for label rendering. The tiles also provide name_en and name_de as alternative name properties.
I added a MapLanguageControl component that:
Currently limited to 3 languages since that's all Shortbread tiles support. This can be extended once we move to Maptiler tiles which offer broader language coverage.
📷 Screenshots
Screen.Recording.2026-03-18.at.6.55.27.PM.mov