From c189786096d4996f89cc9bc2a37a4c01afc14cbc Mon Sep 17 00:00:00 2001 From: Marwin Hochfelsner <50826859+hlfan@users.noreply.github.com> Date: Mon, 19 Jan 2026 17:41:47 +0000 Subject: [PATCH] Change i18n keys to drop maplibre translation patch panel --- app/assets/javascripts/leaflet.locate.js | 4 ++-- app/assets/javascripts/leaflet.zoom.js | 4 ++-- app/assets/javascripts/maplibre.i18n.js | 7 ------- app/assets/javascripts/maplibre/map.js | 7 +++++-- config/locales/en.yml | 12 ++++++------ 5 files changed, 15 insertions(+), 19 deletions(-) delete mode 100644 app/assets/javascripts/maplibre.i18n.js diff --git a/app/assets/javascripts/leaflet.locate.js b/app/assets/javascripts/leaflet.locate.js index a6192e099..c45fc3220 100644 --- a/app/assets/javascripts/leaflet.locate.js +++ b/app/assets/javascripts/leaflet.locate.js @@ -3,9 +3,9 @@ L.OSM.locate = function (options) { const control = L.control.locate({ strings: { - title: OSM.i18n.t("javascripts.map.locate.title"), + title: OSM.i18n.t("javascripts.map.geolocate_control.find_my_location"), popup: function (options) { - return OSM.i18n.t("javascripts.map.locate." + options.unit + "Popup", { count: options.distance }); + return OSM.i18n.t("javascripts.map.geolocate_control." + options.unit + "Popup", { count: options.distance }); } }, ...options diff --git a/app/assets/javascripts/leaflet.zoom.js b/app/assets/javascripts/leaflet.zoom.js index 5aa080d33..e4302fa2e 100644 --- a/app/assets/javascripts/leaflet.zoom.js +++ b/app/assets/javascripts/leaflet.zoom.js @@ -10,9 +10,9 @@ L.OSM.Zoom = L.Control.extend({ this._map = map; this._zoomInButton = this._createButton( - "", OSM.i18n.t("javascripts.map.zoom.in"), "plus-lg", container, this._zoomIn, this); + "", OSM.i18n.t("javascripts.map.navigation_control.zoom_in"), "plus-lg", container, this._zoomIn, this); this._zoomOutButton = this._createButton( - "", OSM.i18n.t("javascripts.map.zoom.out"), "dash-lg", container, this._zoomOut, this); + "", OSM.i18n.t("javascripts.map.navigation_control.zoom_out"), "dash-lg", container, this._zoomOut, this); map.on("zoomend zoomlevelschange", this._updateDisabled, this); diff --git a/app/assets/javascripts/maplibre.i18n.js b/app/assets/javascripts/maplibre.i18n.js deleted file mode 100644 index d5358f9da..000000000 --- a/app/assets/javascripts/maplibre.i18n.js +++ /dev/null @@ -1,7 +0,0 @@ -OSM.MapLibre.Locale = { - "GeolocateControl.FindMyLocation": OSM.i18n.t("javascripts.map.locate.title"), - "GeolocateControl.LocationNotAvailable": OSM.i18n.t("javascripts.map.locate.not_available"), - "NavigationControl.ZoomIn": OSM.i18n.t("javascripts.map.zoom.in"), - "NavigationControl.ZoomOut": OSM.i18n.t("javascripts.map.zoom.out"), - "Popup.Close": OSM.i18n.t("javascripts.map.popup.close") -}; diff --git a/app/assets/javascripts/maplibre/map.js b/app/assets/javascripts/maplibre/map.js index 09b302508..73f780c2c 100644 --- a/app/assets/javascripts/maplibre/map.js +++ b/app/assets/javascripts/maplibre/map.js @@ -1,9 +1,13 @@ //= require maplibre-gl/dist/maplibre-gl -//= require maplibre.i18n //= require maplibre/controls //= require maplibre/dom_util //= require maplibre/styles +maplibregl.Map.prototype._getUIString = function (key) { + const snakeCaseKey = key.replaceAll(/(?<=\w)[A-Z]/g, "_$&").toLowerCase(); + return OSM.i18n.t(`javascripts.map.${snakeCaseKey}`); +}; + OSM.MapLibre.Map = class extends maplibregl.Map { constructor({ allowRotation, ...options } = {}) { const rotationOptions = {}; @@ -34,7 +38,6 @@ OSM.MapLibre.SecondaryMap = class extends OSM.MapLibre.Map { container: "map", style: OSM.MapLibre.Styles.Mapnik, attributionControl: false, - locale: OSM.MapLibre.Locale, allowRotation: false, maxPitch: 0, center: OSM.home ? [OSM.home.lon, OSM.home.lat] : [0, 0], diff --git a/config/locales/en.yml b/config/locales/en.yml index 3443a638c..6e132deb7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3563,12 +3563,12 @@ en: map: popup: close: Close - zoom: - in: Zoom In - out: Zoom Out - locate: - title: Show My Location - not_available: Location not available + navigation_control: + zoom_in: Zoom In + zoom_out: Zoom Out + geolocate_control: + find_my_location: Show My Location + location_not_available: Location not available metersPopup: one: You are within %{count} meter of this point other: You are within %{count} meters of this point -- 2.39.5