Skip to content

Commit

Permalink
i18n: fix merge translations if structure differs
Browse files Browse the repository at this point in the history
If the structure is different between lang and fallbackLang such that a key is an object in fallbackLang and a string in lang, we experience an error when we attempt to assign fill in the property to the string.
This change will skip filling in if the key is not an object in *both* lang and fallbackLang, thus preventing the error.
  • Loading branch information
JGreenlee committed Oct 17, 2023
1 parent cc0e419 commit 9be110d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions www/js/i18nextInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ const mergeInTranslations = (lang, fallbackLang) => {
if (__DEV__) {
if (typeof value === 'string') {
lang[key] = `🌐${value}`
} else if (typeof value === 'object') {
} else if (typeof value === 'object' && typeof lang[key] === 'object') {
lang[key] = {};
mergeInTranslations(lang[key], value);
}
} else {
lang[key] = value;
}
} else if (typeof value === 'object') {
} else if (typeof value === 'object' && typeof lang[key] === 'object') {
mergeInTranslations(lang[key], fallbackLang[key])
}
});
Expand Down

0 comments on commit 9be110d

Please sign in to comment.