From ec862cae30a8fe9d7019d246d454155086d5199c Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Fri, 11 Apr 2025 13:25:28 +0300 Subject: [PATCH] Move distance in units translations into their own scope --- .../index/directions-route-output.js | 22 ++++++++++++------- config/locales/en.yml | 5 +++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/index/directions-route-output.js b/app/assets/javascripts/index/directions-route-output.js index 706eb4dd8..cf00c90dc 100644 --- a/app/assets/javascripts/index/directions-route-output.js +++ b/app/assets/javascripts/index/directions-route-output.js @@ -16,31 +16,37 @@ OSM.DirectionsRouteOutput = function (map) { let downloadURL = null; function formatTotalDistance(m) { + const scope = "javascripts.directions.distance_in_units"; + if (m < 1000) { - return OSM.i18n.t("javascripts.directions.distance_m", { distance: Math.round(m) }); + return OSM.i18n.t("m", { scope, distance: Math.round(m) }); } else if (m < 10000) { - return OSM.i18n.t("javascripts.directions.distance_km", { distance: (m / 1000.0).toFixed(1) }); + return OSM.i18n.t("km", { scope, distance: (m / 1000.0).toFixed(1) }); } else { - return OSM.i18n.t("javascripts.directions.distance_km", { distance: Math.round(m / 1000) }); + return OSM.i18n.t("km", { scope, distance: Math.round(m / 1000) }); } } function formatStepDistance(m) { + const scope = "javascripts.directions.distance_in_units"; + if (m < 5) { return ""; } else if (m < 200) { - return OSM.i18n.t("javascripts.directions.distance_m", { distance: String(Math.round(m / 10) * 10) }); + return OSM.i18n.t("m", { scope, distance: String(Math.round(m / 10) * 10) }); } else if (m < 1500) { - return OSM.i18n.t("javascripts.directions.distance_m", { distance: String(Math.round(m / 100) * 100) }); + return OSM.i18n.t("m", { scope, distance: String(Math.round(m / 100) * 100) }); } else if (m < 5000) { - return OSM.i18n.t("javascripts.directions.distance_km", { distance: String(Math.round(m / 100) / 10) }); + return OSM.i18n.t("km", { scope, distance: String(Math.round(m / 100) / 10) }); } else { - return OSM.i18n.t("javascripts.directions.distance_km", { distance: String(Math.round(m / 1000)) }); + return OSM.i18n.t("km", { scope, distance: String(Math.round(m / 1000)) }); } } function formatHeight(m) { - return OSM.i18n.t("javascripts.directions.distance_m", { distance: Math.round(m) }); + const scope = "javascripts.directions.distance_in_units"; + + return OSM.i18n.t("m", { scope, distance: Math.round(m) }); } function formatTime(s) { diff --git a/config/locales/en.yml b/config/locales/en.yml index 02f72dd41..19556fd4c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3296,8 +3296,9 @@ en: embed_html_disabled: HTML embedding is not available for this map layer edit_help: Move the map and zoom in on a location you want to edit, then click here. directions: - distance_m: "%{distance}m" - distance_km: "%{distance}km" + distance_in_units: + m: "%{distance}m" + km: "%{distance}km" errors: no_route: "Couldn't find a route between those two places." no_place: "Sorry - couldn't locate '%{place}'." -- 2.39.5