From 5d88e0e270916de8599ac17bfd6dbecd4b7370f5 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Thu, 28 Mar 2024 18:50:50 +0100 Subject: [PATCH] fix: fix L.locale no more set --- umap/static/umap/js/modules/i18n.js | 7 +++++++ umap/static/umap/js/umap.features.js | 3 ++- umap/static/umap/js/umap.js | 2 +- umap/static/umap/js/umap.popup.js | 3 ++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/umap/static/umap/js/modules/i18n.js b/umap/static/umap/js/modules/i18n.js index 02c90997..78172132 100644 --- a/umap/static/umap/js/modules/i18n.js +++ b/umap/static/umap/js/modules/i18n.js @@ -17,6 +17,13 @@ export function registerLocale(code, locale) { export function setLocale(code) { locale = code } + +// Until we have a proper way to load `locale` directly from this module, +// without copying to window.L we need to have a getter +export function getLocale() { + return locale +} + // @function translate(string: String, data?: Object): String // Actually try to translate the `string`, with optionnal variable passed in `data`. export function translate(string, data = {}) { diff --git a/umap/static/umap/js/umap.features.js b/umap/static/umap/js/umap.features.js index 4b2ddd76..1d41215c 100644 --- a/umap/static/umap/js/umap.features.js +++ b/umap/static/umap/js/umap.features.js @@ -533,7 +533,8 @@ U.FeatureMixin = { extendedProperties: function () { // Include context properties properties = this.map.getGeoContext() - if (L.locale) properties.locale = L.locale + const locale = L.getLocale() + if (locale) properties.locale = locale if (L.lang) properties.lang = L.lang properties.rank = this.getRank() + 1 if (this.hasGeom()) { diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index a380ded6..64ae48b3 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -1767,7 +1767,7 @@ U.Map = L.Map.extend({ const url = this.urls.get('routing', { lat: e.latlng.lat, lng: e.latlng.lng, - locale: L.locale, + locale: L.getLocale(), zoom: this.getZoom(), }) if (url) window.open(url) diff --git a/umap/static/umap/js/umap.popup.js b/umap/static/umap/js/umap.popup.js index 3b519981..64db0713 100644 --- a/umap/static/umap/js/umap.popup.js +++ b/umap/static/umap/js/umap.popup.js @@ -263,7 +263,8 @@ U.PopupTemplate.OSM = U.PopupTemplate.Default.extend({ getName: function () { const props = this.feature.properties - if (L.locale && props[`name:${L.locale}`]) return props[`name:${L.locale}`] + const locale = L.getLocale() + if (locale && props[`name:${locale}`]) return props[`name:${locale}`] return props.name },