From 9be110d47e85b9d3aeecad5ee68502eabae535f6 Mon Sep 17 00:00:00 2001 From: Jack Greenlee Date: Tue, 17 Oct 2023 15:45:54 -0400 Subject: [PATCH] i18n: fix merge translations if structure differs 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. --- www/js/i18nextInit.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/www/js/i18nextInit.ts b/www/js/i18nextInit.ts index 48177caf5..a2688d66e 100644 --- a/www/js/i18nextInit.ts +++ b/www/js/i18nextInit.ts @@ -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]) } });