Merge pull request #1190 from umap-project/locale-vs-lang

Use LANGUAGE_CODE instead of locale name for browser APIs
This commit is contained in:
Yohan Boniface 2023-07-03 20:41:30 +02:00 committed by GitHub
commit 133a74b1f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 6 deletions

View file

@ -219,7 +219,7 @@ L.Util.sortFeatures = (features, sortKey) => {
score = valA score = valA
.toString() .toString()
.toLowerCase() .toLowerCase()
.localeCompare(valB.toString().toLowerCase(), L.locale || 'en', { .localeCompare(valB.toString().toLowerCase(), L.lang || 'en', {
sensitivity: 'base', sensitivity: 'base',
numeric: true, numeric: true,
}) })
@ -536,7 +536,7 @@ L.U.Help = L.Class.extend({
formatURL: `${L._( formatURL: `${L._(
'Supported variables that will be dynamically replaced' 'Supported variables that will be dynamically replaced'
)}: {bbox}, {lat}, {lng}, {zoom}, {east}, {north}..., {left}, {top}..., locale`, )}: {bbox}, {lat}, {lng}, {zoom}, {east}, {north}..., {left}, {top}..., locale, lang`,
formatIconSymbol: L._( formatIconSymbol: L._(
'Symbol can be either a unicode character or an URL. You can use feature properties as variables: ex.: with "http://myserver.org/images/{name}.png", the {name} variable will be replaced by the "name" value of each marker.' 'Symbol can be either a unicode character or an URL. You can use feature properties as variables: ex.: with "http://myserver.org/images/{name}.png", the {name} variable will be replaced by the "name" value of each marker.'
), ),

View file

@ -500,6 +500,7 @@ L.U.FeatureMixin = {
properties.lng = center.lng properties.lng = center.lng
properties.rank = this.getRank() + 1 properties.rank = this.getRank() + 1
if (L.locale) properties.locale = L.locale if (L.locale) properties.locale = L.locale
if (L.lang) properties.lang = L.lang
if (typeof this.getMeasure !== 'undefined') { if (typeof this.getMeasure !== 'undefined') {
properties.measure = this.getMeasure() properties.measure = this.getMeasure()
} }

View file

@ -65,9 +65,16 @@ L.U.Map.include({
], ],
initialize: function (el, geojson) { initialize: function (el, geojson) {
if (geojson.properties && geojson.properties.locale) // Locale name (pt_PT, en_US…)
// To be used for Django localization
if (geojson.properties.locale)
L.setLocale(geojson.properties.locale) L.setLocale(geojson.properties.locale)
// Language code (pt-pt, en-us…)
// To be used in javascript APIs
if (geojson.properties.lang)
L.lang = geojson.properties.lang
// Don't let default autocreation of controls // Don't let default autocreation of controls
const zoomControl = const zoomControl =
typeof geojson.properties.zoomControl !== 'undefined' typeof geojson.properties.zoomControl !== 'undefined'

View file

@ -423,11 +423,12 @@ class MapDetailMixin:
properties["shortUrl"] = self.get_short_url() properties["shortUrl"] = self.get_short_url()
if settings.USE_I18N: if settings.USE_I18N:
locale = settings.LANGUAGE_CODE lang = settings.LANGUAGE_CODE
# Check attr in case the middleware is not active # Check attr in case the middleware is not active
if hasattr(self.request, "LANGUAGE_CODE"): if hasattr(self.request, "LANGUAGE_CODE"):
locale = self.request.LANGUAGE_CODE lang = self.request.LANGUAGE_CODE
locale = to_locale(locale) properties["lang"] = lang
locale = to_locale(lang)
properties["locale"] = locale properties["locale"] = locale
context["locale"] = locale context["locale"] = locale
user = self.request.user user = self.request.user