A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
fix(i18n): Fixes for multilingual file loading and updating issues
haitaoo6eff356eca6b
diff --git a/ui/src/utils/guard.ts b/ui/src/utils/guard.tsindex 3ca73e0e..f2867378 100644--- a/ui/src/utils/guard.ts+++ b/ui/src/utils/guard.ts@@ -283,7 +283,7 @@ export const setupApp = async () => {// TODO: optimize `initAppSettingsStore` by server renderif (shouldInitAppFetchData()) {await Promise.allSettled([pullLoggedUser(), initAppSettingsStore()]);- setupAppLanguage();+ await setupAppLanguage();setupAppTimeZone();}};diff --git a/ui/src/utils/localize.ts b/ui/src/utils/localize.tsindex 5071ee9d..e6b9fc89 100644--- a/ui/src/utils/localize.ts+++ b/ui/src/utils/localize.ts@@ -31,8 +31,17 @@ export const loadLanguageOptions = async (forAdmin = false) => {return languageOptions;};+const pullLanguageConf = (res) => {+ return getLanguageConfig().then((langConf) => {+ if (langConf && langConf.ui) {+ res.resources = langConf.ui;+ Storage.set(LANG_RESOURCE_STORAGE_KEY, res);+ }+ });+};const addI18nResource = async (langName) => {const res = { lng: langName, resources: undefined };+ const storageResource = Storage.get(LANG_RESOURCE_STORAGE_KEY);if (process.env.NODE_ENV === 'development') {try {const { default: resConf } = await import(`@i18n/${langName}.yaml`);@@ -40,17 +49,13 @@ const addI18nResource = async (langName) => {} catch (ex) {console.log('ex: ', ex);}+ } else if (storageResource && storageResource.lng === res.lng) {+ res.resources = storageResource.resources;+ pullLanguageConf(res);} else {- const storageResource = Storage.get(LANG_RESOURCE_STORAGE_KEY);- if (storageResource?.lng === res.lng) {- res.resources = storageResource.resources;- } else {- const langConf = await getLanguageConfig();- if (langConf) {- res.resources = langConf;- }- }+ await pullLanguageConf(res);}+if (res.resources) {i18next.addResourceBundle(res.lng,@@ -59,7 +64,6 @@ const addI18nResource = async (langName) => {true,true,);- Storage.set(LANG_RESOURCE_STORAGE_KEY, res);}};