From 24b77acbbfb16209c40b16166bbd04b63d8401bc Mon Sep 17 00:00:00 2001 From: twwu Date: Tue, 22 Jul 2025 11:13:42 +0800 Subject: [PATCH] refactor: restructure language resource loading in i18next configuration --- web/i18n/i18next-config.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/web/i18n/i18next-config.ts b/web/i18n/i18next-config.ts index 8c5583bf9a..7fe7e8173c 100644 --- a/web/i18n/i18next-config.ts +++ b/web/i18n/i18next-config.ts @@ -58,8 +58,19 @@ i18n.use(initReactI18next) .init({ lng: undefined, fallbackLng: 'en-US', - resources, + resources: { + 'en-US': loadLangResources('en-US'), + }, }) -export const changeLanguage = i18n.changeLanguage +export const changeLanguage = async (lng?: string) => { + const resolvedLng = lng ?? 'en-US' + const resources = { + [resolvedLng]: loadLangResources(resolvedLng), + } + if (!i18n.hasResourceBundle(resolvedLng, 'translation')) + i18n.addResourceBundle(resolvedLng, 'translation', resources[resolvedLng].translation, true, true) + await i18n.changeLanguage(resolvedLng) +} + export default i18n