fix: add error handling for undefined locale (#344)

This commit is contained in:
David 2025-06-13 00:11:56 -05:00 committed by GitHub
parent 0b00e2d19b
commit 3f6c6dc4d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -14,6 +14,7 @@ export const LangRouter = (userLocale: string, defaultLang: string, langs: Parti
function getValue(locale?: string) { function getValue(locale?: string) {
if (typeof locale === 'undefined') throw new Error('Undefined locale'); if (typeof locale === 'undefined') throw new Error('Undefined locale');
let value = langs[locale] as Record<string, any>; let value = langs[locale] as Record<string, any>;
if (typeof value === 'undefined') throw new Error(`Locale "${locale}" not found`);
for (const i of route) value = value[i]; for (const i of route) value = value[i];
return value; return value;
} }
@ -51,4 +52,4 @@ export type __InternalParseLocale<T extends Record<string, any>> = {
}; };
export type ParseLocales<T extends Record<string, any>> = T; export type ParseLocales<T extends Record<string, any>> = T;
/**Idea inspiration from: FreeAoi */ /**Idea inspiration from: FreeAoi | Fixed by: Drylozu */