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`).
This commit is contained in:
Yohan Boniface 2024-02-28 18:21:49 +01:00
parent fcf22195cb
commit da945cf733
4 changed files with 3 additions and 4 deletions

View file

@ -1,7 +1,7 @@
// Comes from https://github.com/Leaflet/Leaflet/pull/9281 // Comes from https://github.com/Leaflet/Leaflet/pull/9281
import { Util } from '../../vendors/leaflet/leaflet-src.esm.js' import { Util } from '../../vendors/leaflet/leaflet-src.esm.js'
const locales = {} export const locales = {}
// @property locale: String // @property locale: String
// The current locale code, that will be used when translating strings. // 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 // @function translate(string: String, data?: Object): String
// Actually try to translate the `string`, with optionnal variable passed in `data`. // 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) { if (locale && locales[locale] && locales[locale][string] !== undefined) {
string = locales[locale][string] string = locales[locale][string]
} }

View file

@ -4,3 +4,4 @@ import * as L from '../../vendors/leaflet/leaflet-src.esm.js'
import * as i18n from './i18n.js' import * as i18n from './i18n.js'
window.L = { ...L, ...i18n } window.L = { ...L, ...i18n }
window.L._ = i18n.translate

View file

@ -8,7 +8,6 @@
<script src="../vendors/editable/Path.Drag.js" defer></script> <script src="../vendors/editable/Path.Drag.js" defer></script>
<script src="../vendors/editable/Leaflet.Editable.js" defer></script> <script src="../vendors/editable/Leaflet.Editable.js" defer></script>
<script src="../vendors/hash/leaflet-hash.js" defer></script> <script src="../vendors/hash/leaflet-hash.js" defer></script>
<script src="../vendors/i18n/Leaflet.i18n.js" defer></script>
<script src="../vendors/editinosm/Leaflet.EditInOSM.js" defer></script> <script src="../vendors/editinosm/Leaflet.EditInOSM.js" defer></script>
<script src="../vendors/minimap/Control.MiniMap.min.js" defer></script> <script src="../vendors/minimap/Control.MiniMap.min.js" defer></script>
<script src="../vendors/csv2geojson/csv2geojson.js" defer></script> <script src="../vendors/csv2geojson/csv2geojson.js" defer></script>

View file

@ -12,7 +12,6 @@
<script src="{% static 'umap/vendors/editable/Path.Drag.js' %}" defer></script> <script src="{% static 'umap/vendors/editable/Path.Drag.js' %}" defer></script>
<script src="{% static 'umap/vendors/editable/Leaflet.Editable.js' %}" defer></script> <script src="{% static 'umap/vendors/editable/Leaflet.Editable.js' %}" defer></script>
<script src="{% static 'umap/vendors/hash/leaflet-hash.js' %}" defer></script> <script src="{% static 'umap/vendors/hash/leaflet-hash.js' %}" defer></script>
<script src="{% static 'umap/vendors/i18n/Leaflet.i18n.js' %}" defer></script>
<script src="{% static 'umap/vendors/editinosm/Leaflet.EditInOSM.js' %}" <script src="{% static 'umap/vendors/editinosm/Leaflet.EditInOSM.js' %}"
defer></script> defer></script>
<script src="{% static 'umap/vendors/minimap/Control.MiniMap.min.js' %}" <script src="{% static 'umap/vendors/minimap/Control.MiniMap.min.js' %}"