From da945cf733ebf751eab37e8391d7f64c85e7d4c4 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Wed, 28 Feb 2024 18:21:49 +0100 Subject: [PATCH] wip: remove Leaflet.i18n from frontend and expose L._ But we keep Leaflet.i18n for now, as we use its script to collect strings (this script to be tweaked to support also `translate`). --- umap/static/umap/js/modules/i18n.js | 4 ++-- umap/static/umap/js/modules/leaflet-configure.js | 1 + umap/static/umap/test/index.html | 1 - umap/templates/umap/js.html | 1 - 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/umap/static/umap/js/modules/i18n.js b/umap/static/umap/js/modules/i18n.js index d2b6b429..02c90997 100644 --- a/umap/static/umap/js/modules/i18n.js +++ b/umap/static/umap/js/modules/i18n.js @@ -1,7 +1,7 @@ // Comes from https://github.com/Leaflet/Leaflet/pull/9281 import { Util } from '../../vendors/leaflet/leaflet-src.esm.js' -const locales = {} +export const locales = {} // @property locale: String // The current locale code, that will be used when translating strings. @@ -19,7 +19,7 @@ export function setLocale(code) { } // @function translate(string: String, data?: Object): String // Actually try to translate the `string`, with optionnal variable passed in `data`. -export function translate(string, data) { +export function translate(string, data = {}) { if (locale && locales[locale] && locales[locale][string] !== undefined) { string = locales[locale][string] } diff --git a/umap/static/umap/js/modules/leaflet-configure.js b/umap/static/umap/js/modules/leaflet-configure.js index 9679f3f4..b7b502ff 100644 --- a/umap/static/umap/js/modules/leaflet-configure.js +++ b/umap/static/umap/js/modules/leaflet-configure.js @@ -4,3 +4,4 @@ import * as L from '../../vendors/leaflet/leaflet-src.esm.js' import * as i18n from './i18n.js' window.L = { ...L, ...i18n } +window.L._ = i18n.translate diff --git a/umap/static/umap/test/index.html b/umap/static/umap/test/index.html index 9d6da7d4..e01794a3 100644 --- a/umap/static/umap/test/index.html +++ b/umap/static/umap/test/index.html @@ -8,7 +8,6 @@ - diff --git a/umap/templates/umap/js.html b/umap/templates/umap/js.html index bcc700f0..86ea502e 100644 --- a/umap/templates/umap/js.html +++ b/umap/templates/umap/js.html @@ -12,7 +12,6 @@ -