Fix #790: editor breaking when missing some translations

This commit is contained in:
jos 2020-01-18 14:19:06 +01:00
parent 259b32d441
commit b3c0eedc08
2 changed files with 13 additions and 8 deletions

View File

@ -3,6 +3,11 @@
https://github.com/josdejong/jsoneditor 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 ## 2020-01-16, version 8.2.0
- Make it easy to create custom styling by overriding default SASS variable - Make it easy to create custom styling by overriding default SASS variable

View File

@ -575,12 +575,12 @@ export function setLanguages (languages) {
if (!languages) { if (!languages) {
return return
} }
for (const key in languages) { for (const language in languages) {
const langFound = _locales.find(l => l === key) const langFound = _locales.find(l => l === language)
if (!langFound) { 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) { if (!lang) {
lang = _lang lang = _lang
} }
let text = _defs[lang][key] let text = _defs[lang][key] || _defs[_defaultLang][key] || key
if (data) { if (data) {
for (key in data) { for (const dataKey in data) {
text = text.replace('${' + key + '}', data[key]) text = text.replace('${' + dataKey + '}', data[dataKey])
} }
} }
return text || key return text
} }