From b3c0eedc086a3dbde63ce7019a29928aa657d3fe Mon Sep 17 00:00:00 2001 From: jos Date: Sat, 18 Jan 2020 14:19:06 +0100 Subject: [PATCH] Fix #790: editor breaking when missing some translations --- HISTORY.md | 5 +++++ src/js/i18n.js | 16 ++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 2a6fac8..7dc6afc 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -3,6 +3,11 @@ https://github.com/josdejong/jsoneditor +## not yet published, version 8.2.1 + +- Fix #790: editor breaking when missing some translations. + + ## 2020-01-16, version 8.2.0 - Make it easy to create custom styling by overriding default SASS variable diff --git a/src/js/i18n.js b/src/js/i18n.js index 12303db..0a65ea0 100644 --- a/src/js/i18n.js +++ b/src/js/i18n.js @@ -575,12 +575,12 @@ export function setLanguages (languages) { if (!languages) { return } - for (const key in languages) { - const langFound = _locales.find(l => l === key) + for (const language in languages) { + const langFound = _locales.find(l => l === language) if (!langFound) { - _locales.push(key) + _locales.push(language) } - _defs[key] = Object.assign({}, _defs[_defaultLang], _defs[key], languages[key]) + _defs[language] = Object.assign({}, _defs[_defaultLang], _defs[language], languages[language]) } } @@ -588,11 +588,11 @@ export function translate (key, data, lang) { if (!lang) { lang = _lang } - let text = _defs[lang][key] + let text = _defs[lang][key] || _defs[_defaultLang][key] || key if (data) { - for (key in data) { - text = text.replace('${' + key + '}', data[key]) + for (const dataKey in data) { + text = text.replace('${' + dataKey + '}', data[dataKey]) } } - return text || key + return text }