From 46c6d2d6766465de23d8131dbf4a398114c75c08 Mon Sep 17 00:00:00 2001 From: aeizzz Date: Wed, 8 Mar 2023 12:05:31 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20Introducing=20new=20features.=20?= =?UTF-8?q?=E5=AE=8C=E5=96=84i18n=20=E5=BC=82=E6=AD=A5=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/i18n/index.ts | 33 ++++++++++++++++++++++++--------- src/utils/request.ts | 1 - 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/i18n/index.ts b/src/i18n/index.ts index 0bef6117..1d0a4659 100644 --- a/src/i18n/index.ts +++ b/src/i18n/index.ts @@ -46,15 +46,6 @@ function mergeArrObj(list: T, key: string) { return obj; } -// 远程获取i18n -try { - const infoI18n = await info(); - itemize['zh-cn'].push(...infoI18n.data['zh-cn']); - itemize.en.push(...infoI18n.data.en); -} catch (e) { - // 考虑请求不过去没有后台的情况下导致的i18n失效 -} - for (const key in itemize) { messages[key] = { name: key, @@ -79,3 +70,27 @@ export const i18n = createI18n({ fallbackLocale: zhcnLocale.name, messages, }); + +const messageLocal = {}; + +const itemizeLocal = { en: [] as any[], 'zh-cn': [] as any[] }; + +// 远程获取i18n +try { + setTimeout(async () => { + const infoI18n = await info(); + itemizeLocal['zh-cn'].push(...infoI18n.data['zh-cn']); + itemizeLocal.en.push(...infoI18n.data.en); + for (const key in itemizeLocal) { + messageLocal[key] = { + name: key, + ...mergeArrObj(itemizeLocal, key), + }; + } + i18n.global.mergeLocaleMessage('zh-cn', messageLocal['zh-cn']); + i18n.global.mergeLocaleMessage('en', messageLocal['en']); + i18n.global.locale.value = themeConfig.value.globalI18n; + }, 50); +} catch (e) { + // 考虑请求不过去没有后台的情况下导致的i18n失效 +} diff --git a/src/utils/request.ts b/src/utils/request.ts index ebeed8de..ca6a6b71 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -1,5 +1,4 @@ import axios, { AxiosInstance, InternalAxiosRequestConfig } from 'axios'; -import { ElMessageBox } from 'element-plus'; import { Session, Local } from '/@/utils/storage'; import qs from 'qs'; import { useMessageBox } from '../hooks/message';