Skip to content

fix(i18n): translate profile selector labels on language change#446

Merged
DennisOSRM merged 2 commits intogh-pagesfrom
fix/i18n-profile-selector-translation
May 3, 2026
Merged

fix(i18n): translate profile selector labels on language change#446
DennisOSRM merged 2 commits intogh-pagesfrom
fix/i18n-profile-selector-translation

Conversation

@DennisOSRM
Copy link
Copy Markdown
Contributor

This PR ensures the profile selector uses translated labels when the language changes.

Files changed:

  • src/leaflet_options.js
  • src/index.js

Tests: Ran locally; all tests passed.

- Add labelKey and default mappings for driving/bike/foot in src/leaflet_options.js
- Build and translate services before creating mode selector and use services globally in src/index.js

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 3, 2026 18:45
@DennisOSRM DennisOSRM merged commit 2d2a50b into gh-pages May 3, 2026
5 checks passed
@DennisOSRM DennisOSRM deleted the fix/i18n-profile-selector-translation branch May 3, 2026 18:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Ensures routing profile selector labels are localized and update correctly when the UI language changes, by providing stable translation keys for services/profiles.

Changes:

  • Add labelKey (with defaults) to the services built from runtime modes, enabling consistent lookup in i18n dictionaries.
  • Translate/prepare services earlier in src/index.js so the mode selector and routing control share the same service objects.
  • Replace direct leafletOptions.services accesses with a single services reference for consistency.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/leaflet_options.js Adds labelKey (with default mappings) to service objects produced from OSRM_MODES/defaults.
src/index.js Prepares/translates services earlier and uses the shared services array throughout router/control/profile switching code.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/index.js
Comment on lines +30 to +37
// Build and translate services early so modeSelector can use translated labels
var services = leafletOptions.services;
for (var i = 0, len = services.length; i < len; i++) {
var profileLabelKey = services[i].labelKey || services[i].label;
services[i].labelKey = profileLabelKey;
services[i].label = localization.t(language, profileLabelKey) || profileLabelKey;
}
var modeSelector = modeSelectorModule.createModeSelector(localization.get(language), services);
Comment thread src/leaflet_options.js
Comment on lines +323 to +327
var label = mode.label || name;
var labelKey = mode.labelKey || defaultLabelMapping[name] || label;
return {
label: mode.name,
label: label,
labelKey: labelKey,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants