From db886f5dd775093aa31718c1aa0fa40b69086f74 Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Fri, 7 Jul 2023 13:29:09 +0200 Subject: [PATCH] fix crash when using "exotic" locales which undefined `languageNames` see also #9737 --- CHANGELOG.md | 2 ++ modules/core/localizer.js | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16227c583..abed0a5ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,7 @@ _Breaking developer changes, which may affect downstream projects or sites that * Fix dysfunctional autocomplete of wikidata fields for some languages with country-codes ([#9638]) * Prevent certain tag values from corrupting css classes when they contain whitespaces ([#9637], thanks [@k-yle]) * Don't move the cursor to the end of (some) input fields while editing in the middle ([#9233]) +* Fix crash when using certain locales (e.g. `fr-FR`) ([#9737], thanks [@k-yle]) #### :earth_asia: Localization * Send `Accept-Language` header on Nominatim API calls ([#9501], thanks [@k-yle]) * Add Address and Phone format for India ([#9482], thanks [@biswajit-k]) @@ -89,6 +90,7 @@ _Breaking developer changes, which may affect downstream projects or sites that [#9638]: https://github.com/openstreetmap/iD/pull/9638 [#9640]: https://github.com/openstreetmap/iD/issues/9640 [#9650]: https://github.com/openstreetmap/iD/pull/9650 +[#9737]: https://github.com/openstreetmap/iD/pull/9737 [@biswajit-k]: https://github.com/biswajit-k [@bryceco]: https://github.com/bryceco diff --git a/modules/core/localizer.js b/modules/core/localizer.js index 09bcc2028..f275eefd3 100644 --- a/modules/core/localizer.js +++ b/modules/core/localizer.js @@ -401,7 +401,7 @@ export function coreLocalizer() { localizer.languageName = (code, options) => { - if (_languageNames[code]) { // name in locale language + if (_languageNames && _languageNames[code]) { // name in locale language // e.g. "German" return _languageNames[code]; } @@ -418,9 +418,9 @@ export function coreLocalizer() { } else if (langInfo.base && langInfo.script) { const base = langInfo.base; // the code of the language this is based on - if (_languageNames[base]) { // base language name in locale language + if (_languageNames && _languageNames[base]) { // base language name in locale language const scriptCode = langInfo.script; - const script = _scriptNames[scriptCode] || scriptCode; + const script = (_scriptNames && _scriptNames[scriptCode]) || scriptCode; // e.g. "Serbian (Cyrillic)" return localizer.t('translate.language_and_code', { language: _languageNames[base], code: script });