|
@@ -8,16 +8,15 @@ import { storageLocal, isObject } from "@pureadmin/utils";
|
|
|
import enLocale from "element-plus/es/locale/lang/en";
|
|
import enLocale from "element-plus/es/locale/lang/en";
|
|
|
import zhLocale from "element-plus/es/locale/lang/zh-cn";
|
|
import zhLocale from "element-plus/es/locale/lang/zh-cn";
|
|
|
|
|
|
|
|
|
|
+// 项目国际化资源(静态导入,兼容 Vite 8)
|
|
|
|
|
+import zhCN from "../../locales/zh-CN.yaml";
|
|
|
|
|
+import en from "../../locales/en.yaml";
|
|
|
|
|
+
|
|
|
const siphonI18n = (function () {
|
|
const siphonI18n = (function () {
|
|
|
- // 仅初始化一次国际化配置
|
|
|
|
|
- const cache = Object.fromEntries(
|
|
|
|
|
- Object.entries(
|
|
|
|
|
- import.meta.glob("../../locales/*.y(a)?ml", { eager: true })
|
|
|
|
|
- ).map(([key, value]: any) => {
|
|
|
|
|
- const matched = key.match(/([A-Za-z0-9-_]+)\./i)[1];
|
|
|
|
|
- return [matched, value.default];
|
|
|
|
|
- })
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ const cache: Record<string, any> = {
|
|
|
|
|
+ "zh-CN": zhCN,
|
|
|
|
|
+ "en": en
|
|
|
|
|
+ };
|
|
|
return (prefix = "zh-CN") => {
|
|
return (prefix = "zh-CN") => {
|
|
|
return cache[prefix];
|
|
return cache[prefix];
|
|
|
};
|
|
};
|
|
@@ -89,10 +88,10 @@ export function transformI18n(message: any = "") {
|
|
|
const key = message.match(/(\S*)\./)?.input;
|
|
const key = message.match(/(\S*)\./)?.input;
|
|
|
|
|
|
|
|
if (key && flatI18n("zh-CN").has(key)) {
|
|
if (key && flatI18n("zh-CN").has(key)) {
|
|
|
- return i18n.global.t.call(i18n.global.locale, message);
|
|
|
|
|
|
|
+ return i18n.global.t(message);
|
|
|
} else if (!key && Object.hasOwn(siphonI18n("zh-CN"), message)) {
|
|
} else if (!key && Object.hasOwn(siphonI18n("zh-CN"), message)) {
|
|
|
// 兼容非嵌套形式的国际化写法
|
|
// 兼容非嵌套形式的国际化写法
|
|
|
- return i18n.global.t.call(i18n.global.locale, message);
|
|
|
|
|
|
|
+ return i18n.global.t(message);
|
|
|
} else {
|
|
} else {
|
|
|
return message;
|
|
return message;
|
|
|
}
|
|
}
|