Skip to content

Commit 99d268d

Browse files
committed
fix: don't backtrack on translation key if nested value was not found
1 parent dfa265e commit 99d268d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/translation.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,13 @@ function translate<TTrKey extends string = string>(language: string, key: TTrKey
127127
const keyParts = key.split(".");
128128
let value: string | TrObject | undefined = trObj;
129129
for(const part of keyParts) {
130-
if(typeof value !== "object" || value === null)
130+
if(typeof value !== "object" || value === null) {
131+
value = undefined;
131132
break;
133+
}
132134
value = value?.[part];
133135
}
136+
134137
if(typeof value === "string")
135138
return transformTrVal(key, value);
136139

@@ -140,7 +143,9 @@ function translate<TTrKey extends string = string>(language: string, key: TTrKey
140143
return transformTrVal(key, value);
141144

142145
// default to fallbackLang or translation key
143-
return fallbackLang ? translate(fallbackLang, key, ...trArgs) : key;
146+
return fallbackLang
147+
? translate(fallbackLang, key, ...trArgs)
148+
: key;
144149
}
145150

146151
//#region tr funcs

0 commit comments

Comments
 (0)