diff --git a/lib/translation.ts b/lib/translation.ts index 1c300f8..1d9de44 100644 --- a/lib/translation.ts +++ b/lib/translation.ts @@ -127,10 +127,13 @@ function translate(language: string, key: TTrKey const keyParts = key.split("."); let value: string | TrObject | undefined = trObj; for(const part of keyParts) { - if(typeof value !== "object" || value === null) + if(typeof value !== "object" || value === null) { + value = undefined; break; + } value = value?.[part]; } + if(typeof value === "string") return transformTrVal(key, value); @@ -140,7 +143,9 @@ function translate(language: string, key: TTrKey return transformTrVal(key, value); // default to fallbackLang or translation key - return fallbackLang ? translate(fallbackLang, key, ...trArgs) : key; + return fallbackLang + ? translate(fallbackLang, key, ...trArgs) + : key; } //#region tr funcs