fix translation fallback for sparely translated languages when complete categories are missing

This commit is contained in:
schlagmichdoch 2023-08-29 02:32:54 +02:00
parent c2a746d69c
commit abc06fcc21
2 changed files with 28 additions and 16 deletions

View file

@ -76,19 +76,25 @@ class Localization {
? Localization.defaultTranslations ? Localization.defaultTranslations
: Localization.translations; : Localization.translations;
for (let i=0; i<keys.length-1; i++) { let translation;
try {
for (let i = 0; i < keys.length - 1; i++) {
translationCandidates = translationCandidates[keys[i]] translationCandidates = translationCandidates[keys[i]]
} }
let lastKey = keys[keys.length-1]; let lastKey = keys[keys.length - 1];
if (attr) lastKey += "_" + attr; if (attr) lastKey += "_" + attr;
let translation = translationCandidates[lastKey]; translation = translationCandidates[lastKey];
for (let j in data) { for (let j in data) {
translation = translation.replace(`{{${j}}}`, data[j]); translation = translation.replace(`{{${j}}}`, data[j]);
} }
} catch (e) {
translation = "";
}
if (!translation) { if (!translation) {
if (!useDefault) { if (!useDefault) {

View file

@ -76,19 +76,25 @@ class Localization {
? Localization.defaultTranslations ? Localization.defaultTranslations
: Localization.translations; : Localization.translations;
for (let i=0; i<keys.length-1; i++) { let translation;
try {
for (let i = 0; i < keys.length - 1; i++) {
translationCandidates = translationCandidates[keys[i]] translationCandidates = translationCandidates[keys[i]]
} }
let lastKey = keys[keys.length-1]; let lastKey = keys[keys.length - 1];
if (attr) lastKey += "_" + attr; if (attr) lastKey += "_" + attr;
let translation = translationCandidates[lastKey]; translation = translationCandidates[lastKey];
for (let j in data) { for (let j in data) {
translation = translation.replace(`{{${j}}}`, data[j]); translation = translation.replace(`{{${j}}}`, data[j]);
} }
} catch (e) {
translation = "";
}
if (!translation) { if (!translation) {
if (!useDefault) { if (!useDefault) {