This commit is contained in:
吴红兵
2026-03-07 01:34:48 +08:00
parent adc511cfdc
commit 94c3473958
1211 changed files with 599405 additions and 322105 deletions

View File

@@ -1,8 +1,8 @@
import {createI18n} from 'vue-i18n';
import { createI18n } from 'vue-i18n';
import pinia from '/@/stores/index';
import {storeToRefs} from 'pinia';
import {useThemeConfig} from '/@/stores/themeConfig';
import {info} from '/@/api/admin/i18n';
import { storeToRefs } from 'pinia';
import { useThemeConfig } from '/@/stores/themeConfig';
import { info } from '/@/api/admin/i18n';
// 定义语言国际化内容
@@ -20,72 +20,72 @@ import zhcnLocale from 'element-plus/es/locale/lang/zh-cn';
// 定义变量内容
const messages = {};
const element = {en: enLocale, 'zh-cn': zhcnLocale};
const itemize = {en: [] as any[], 'zh-cn': [] as any[]};
const modules: Record<string, any> = import.meta.glob('./**/*.ts', {eager: true});
const pages: Record<string, any> = import.meta.glob('./../../**/**/**/i18n/*.ts', {eager: true});
const element = { en: enLocale, 'zh-cn': zhcnLocale };
const itemize = { en: [] as any[], 'zh-cn': [] as any[] };
const modules: Record<string, any> = import.meta.glob('./**/*.ts', { eager: true });
const pages: Record<string, any> = import.meta.glob('./../../**/**/**/i18n/*.ts', { eager: true });
// 对自动引入的 modules 进行分类 en、zh-cn、zh-tw
for (const path in modules) {
const key = path.match(/(\S+)\/(\S+).ts/);
if (itemize[key![2]]) itemize[key![2]].push(modules[path].default);
else itemize[key![2]] = modules[path];
const key = path.match(/(\S+)\/(\S+).ts/);
if (itemize[key![2]]) itemize[key![2]].push(modules[path].default);
else itemize[key![2]] = modules[path];
}
for (const path in pages) {
const key = path.match(/(\S+)\/(\S+).ts/);
if (itemize[key![2]]) itemize[key![2]].push(pages[path].default);
else itemize[key![2]] = pages[path];
const key = path.match(/(\S+)\/(\S+).ts/);
if (itemize[key![2]]) itemize[key![2]].push(pages[path].default);
else itemize[key![2]] = pages[path];
}
// 合并数组对象(非标准数组对象,数组中对象的每项 key、value 都不同)
function mergeArrObj<T>(list: T, key: string) {
let obj = {};
list[key].forEach((i: EmptyObjectType) => {
obj = Object.assign({}, obj, i);
});
return obj;
let obj = {};
list[key].forEach((i: EmptyObjectType) => {
obj = Object.assign({}, obj, i);
});
return obj;
}
for (const key in itemize) {
messages[key] = {
name: key,
el: element[key].el,
...mergeArrObj(itemize, key),
};
messages[key] = {
name: key,
el: element[key].el,
...mergeArrObj(itemize, key),
};
}
// 读取 pinia 默认语言
const stores = useThemeConfig(pinia);
const {themeConfig} = storeToRefs(stores);
const { themeConfig } = storeToRefs(stores);
// 导出语言国际化
export const i18n = createI18n({
legacy: false,
silentTranslationWarn: true,
missingWarn: false,
silentFallbackWarn: true,
fallbackWarn: false,
locale: themeConfig.value.globalI18n,
fallbackLocale: zhcnLocale.name,
messages,
legacy: false,
silentTranslationWarn: true,
missingWarn: false,
silentFallbackWarn: true,
fallbackWarn: false,
locale: themeConfig.value.globalI18n,
fallbackLocale: zhcnLocale.name,
messages,
});
await fetchI18n()
await fetchI18n();
// 远程获取i18n
async function fetchI18n() {
const infoI18n = await info();
const messageLocal = {};
const itemizeLocal = {en: [] as any[], 'zh-cn': [] as any[]};
itemizeLocal['zh-cn'].push(...infoI18n.data.data['zh-cn']);
itemizeLocal.en.push(...infoI18n.data.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;
const infoI18n = await info();
const messageLocal = {};
const itemizeLocal = { en: [] as any[], 'zh-cn': [] as any[] };
itemizeLocal['zh-cn'].push(...infoI18n.data.data['zh-cn']);
itemizeLocal.en.push(...infoI18n.data.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;
}

View File

@@ -125,7 +125,7 @@ export default {
fullscreen: 'Fullscreen',
closeFullscreen: 'Close Fullscreen',
favorite: 'Favorite',
favoriteMax: 'The number of shortcut navigation exceeds the upper limit. Please remove some shortcuts'
favoriteMax: 'The number of shortcut navigation exceeds the upper limit. Please remove some shortcuts',
},
notFound: {
foundTitle: 'Wrong Address Input, Please Re-enter the Address~',

View File

@@ -118,7 +118,7 @@ export default {
fullscreen: '当前页全屏',
closeFullscreen: '关闭全屏',
favorite: '收藏',
favoriteMax: '快捷导航数量超过上限,请移除部分'
favoriteMax: '快捷导航数量超过上限,请移除部分',
},
notFound: {
foundTitle: '地址输入错误,请重新输入地址~',

View File

@@ -14,7 +14,7 @@ export default {
importUserTip: 'Import user',
queryDeptTip: 'Enter department name',
resetBtn: 'Reset',
copyBtn:'Copy',
copyBtn: 'Copy',
action: 'Action',
optSuccessText: 'Operation successful',
optConfirmText: 'Confirm this operation?',