@tushi11/elpis 1.0.35 → 1.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/pages/plugins/i18n/index.js +97 -97
- package/package.json +3 -2
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
import { createI18n } from 'vue-i18n';
|
|
2
|
-
import cache from '$elpisCommon/cache';
|
|
3
|
-
import { SETTING_KEY } from '$elpisPages/enums/cacheEnums';
|
|
4
|
-
import pageConfigs from '$elpisPages/configs/configs.js';
|
|
5
|
-
import { merge } from 'lodash';
|
|
6
|
-
|
|
7
|
-
// 导入业务语言包
|
|
8
|
-
import enLocale from './locales/en';
|
|
9
|
-
import zhLocale from './locales/zh-CN';
|
|
10
|
-
|
|
11
|
-
// 导入Element Plus语言包
|
|
12
|
-
import zhCn from 'element-plus/es/locale/lang/zh-cn';
|
|
13
|
-
// import en from 'element-plus/dist/locale/en.mjs';
|
|
14
|
-
import en from 'element-plus/es/locale/lang/en';
|
|
15
|
-
|
|
16
|
-
// 业务拓展 i18n-config 配置
|
|
17
|
-
import businessI18nConfig from '$businessI18nConfig';
|
|
18
|
-
|
|
19
|
-
const elpisI18nConfig = {
|
|
20
|
-
'zh-cn': {
|
|
21
|
-
name: '简体中文',
|
|
22
|
-
business: zhLocale, // 业务翻译(页面文本等)
|
|
23
|
-
element: zhCn, // Element Plus组件翻译
|
|
24
|
-
},
|
|
25
|
-
en: {
|
|
26
|
-
name: 'English',
|
|
27
|
-
business: enLocale, // 业务翻译
|
|
28
|
-
element: en, // Element Plus组件翻译
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const languageMap = merge(elpisI18nConfig, businessI18nConfig);
|
|
33
|
-
|
|
34
|
-
// 提取业务语言包(供Vue I18n使用)
|
|
35
|
-
const messages = Object.fromEntries(
|
|
36
|
-
Object.entries(languageMap).map(([lang, { business }]) => [lang, business])
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
// 提取Element Plus语言包映射
|
|
40
|
-
export const elLocaleMap = Object.fromEntries(
|
|
41
|
-
Object.entries(languageMap).map(([lang, { element }]) => [lang, element])
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
// 提取语言选择列表(带lang和name)
|
|
45
|
-
export const localeMap = Object.entries(languageMap).map(([lang, { name }]) => ({
|
|
46
|
-
lang,
|
|
47
|
-
name,
|
|
48
|
-
}));
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* 获取当前语言设置
|
|
52
|
-
* @returns {string} 当前语言标识(如 'zh-cn' 或 'en')
|
|
53
|
-
*/
|
|
54
|
-
export function getLanguage() {
|
|
55
|
-
const storageSetting = cache.get(SETTING_KEY);
|
|
56
|
-
if (storageSetting) return storageSetting.language || 'zh-cn';
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// 创建i18n实例
|
|
60
|
-
const i18n = createI18n({
|
|
61
|
-
silentTranslationWarn: process.env.NODE_ENV === 'production', // 生产环境关闭翻译警告
|
|
62
|
-
missingWarn: process.env.NODE_ENV === 'production', // 关闭缺失翻译警告
|
|
63
|
-
silentFallbackWarn: process.env.NODE_ENV === 'production', // 关闭 fallback 警告
|
|
64
|
-
legacy: false,
|
|
65
|
-
globalInjection: true, // 允许全局使用 $t 函数
|
|
66
|
-
locale: getLanguage(), // 当前语言
|
|
67
|
-
messages, // 语言包
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
const {
|
|
71
|
-
sysSetting: { useI18n },
|
|
72
|
-
} = pageConfigs;
|
|
73
|
-
|
|
74
|
-
// 基础翻译方法
|
|
75
|
-
export const { t: i18nT } = i18n.global;
|
|
76
|
-
/**
|
|
77
|
-
* 条件翻译方法
|
|
78
|
-
* @param {string} content - 翻译键或原始内容
|
|
79
|
-
* @param {object} [interpolations={}] - 插值变量(如 { name: '张三' })
|
|
80
|
-
* @param {object} [options={}] - 翻译配置
|
|
81
|
-
* @returns {string} 处理后的内容
|
|
82
|
-
*/
|
|
83
|
-
export const t = (content = '', interpolations = {}, options = { silent: true }) => {
|
|
84
|
-
let needTranslate = false;
|
|
85
|
-
if (typeof content === 'string' && content.startsWith('t::')) {
|
|
86
|
-
content = content.slice(3);
|
|
87
|
-
needTranslate = true;
|
|
88
|
-
}
|
|
89
|
-
if (useI18n || needTranslate) {
|
|
90
|
-
// 需要翻译时,使用t方法并默认关闭动态内容的警告
|
|
91
|
-
return i18nT(content, interpolations, options);
|
|
92
|
-
}
|
|
93
|
-
// 不需要翻译时,直接返回原始内容
|
|
94
|
-
return content;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
export default i18n;
|
|
1
|
+
import { createI18n } from 'vue-i18n';
|
|
2
|
+
import cache from '$elpisCommon/cache';
|
|
3
|
+
import { SETTING_KEY } from '$elpisPages/enums/cacheEnums';
|
|
4
|
+
import pageConfigs from '$elpisPages/configs/configs.js';
|
|
5
|
+
import { merge } from 'lodash';
|
|
6
|
+
|
|
7
|
+
// 导入业务语言包
|
|
8
|
+
import enLocale from './locales/en';
|
|
9
|
+
import zhLocale from './locales/zh-CN';
|
|
10
|
+
|
|
11
|
+
// 导入Element Plus语言包
|
|
12
|
+
import zhCn from 'element-plus/es/locale/lang/zh-cn';
|
|
13
|
+
// import en from 'element-plus/dist/locale/en.mjs';
|
|
14
|
+
import en from 'element-plus/es/locale/lang/en';
|
|
15
|
+
|
|
16
|
+
// 业务拓展 i18n-config 配置
|
|
17
|
+
import businessI18nConfig from '$businessI18nConfig';
|
|
18
|
+
|
|
19
|
+
const elpisI18nConfig = {
|
|
20
|
+
'zh-cn': {
|
|
21
|
+
name: '简体中文',
|
|
22
|
+
business: zhLocale, // 业务翻译(页面文本等)
|
|
23
|
+
element: zhCn, // Element Plus组件翻译
|
|
24
|
+
},
|
|
25
|
+
en: {
|
|
26
|
+
name: 'English',
|
|
27
|
+
business: enLocale, // 业务翻译
|
|
28
|
+
element: en, // Element Plus组件翻译
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const languageMap = merge(elpisI18nConfig, businessI18nConfig);
|
|
33
|
+
|
|
34
|
+
// 提取业务语言包(供Vue I18n使用)
|
|
35
|
+
const messages = Object.fromEntries(
|
|
36
|
+
Object.entries(languageMap).map(([lang, { business }]) => [lang, business])
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
// 提取Element Plus语言包映射
|
|
40
|
+
export const elLocaleMap = Object.fromEntries(
|
|
41
|
+
Object.entries(languageMap).map(([lang, { element }]) => [lang, element])
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
// 提取语言选择列表(带lang和name)
|
|
45
|
+
export const localeMap = Object.entries(languageMap).map(([lang, { name }]) => ({
|
|
46
|
+
lang,
|
|
47
|
+
name,
|
|
48
|
+
}));
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 获取当前语言设置
|
|
52
|
+
* @returns {string} 当前语言标识(如 'zh-cn' 或 'en')
|
|
53
|
+
*/
|
|
54
|
+
export function getLanguage() {
|
|
55
|
+
const storageSetting = cache.get(SETTING_KEY);
|
|
56
|
+
if (storageSetting) return storageSetting.language || 'zh-cn';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 创建i18n实例
|
|
60
|
+
const i18n = createI18n({
|
|
61
|
+
silentTranslationWarn: process.env.NODE_ENV === 'production', // 生产环境关闭翻译警告
|
|
62
|
+
missingWarn: process.env.NODE_ENV === 'production', // 关闭缺失翻译警告
|
|
63
|
+
silentFallbackWarn: process.env.NODE_ENV === 'production', // 关闭 fallback 警告
|
|
64
|
+
legacy: false,
|
|
65
|
+
globalInjection: true, // 允许全局使用 $t 函数
|
|
66
|
+
locale: getLanguage(), // 当前语言
|
|
67
|
+
messages, // 语言包
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const {
|
|
71
|
+
sysSetting: { useI18n },
|
|
72
|
+
} = pageConfigs;
|
|
73
|
+
|
|
74
|
+
// 基础翻译方法
|
|
75
|
+
export const { t: i18nT } = i18n.global;
|
|
76
|
+
/**
|
|
77
|
+
* 条件翻译方法
|
|
78
|
+
* @param {string} content - 翻译键或原始内容
|
|
79
|
+
* @param {object} [interpolations={}] - 插值变量(如 { name: '张三' })
|
|
80
|
+
* @param {object} [options={}] - 翻译配置
|
|
81
|
+
* @returns {string} 处理后的内容
|
|
82
|
+
*/
|
|
83
|
+
export const t = (content = '', interpolations = {}, options = { silent: true }) => {
|
|
84
|
+
let needTranslate = false;
|
|
85
|
+
if (typeof content === 'string' && content.startsWith('t::')) {
|
|
86
|
+
content = content.slice(3);
|
|
87
|
+
needTranslate = true;
|
|
88
|
+
}
|
|
89
|
+
if (useI18n || needTranslate) {
|
|
90
|
+
// 需要翻译时,使用t方法并默认关闭动态内容的警告
|
|
91
|
+
return i18nT(content, interpolations, options);
|
|
92
|
+
}
|
|
93
|
+
// 不需要翻译时,直接返回原始内容
|
|
94
|
+
return content;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export default i18n;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tushi11/elpis",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.37",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"@babel/core": "^7.24.0",
|
|
18
18
|
"@babel/plugin-transform-runtime": "^7.1.0",
|
|
19
19
|
"@babel/preset-env": "^7.4.5",
|
|
20
|
+
"@babel/runtime": "^7.28.4",
|
|
20
21
|
"@element-plus/icons-vue": "^2.3.1",
|
|
21
22
|
"@iconify-json/ep": "^1.2.3",
|
|
22
23
|
"@iconify-json/mdi": "^1.2.3",
|
|
@@ -65,6 +66,7 @@
|
|
|
65
66
|
"nprogress": "^0.2.0",
|
|
66
67
|
"path": "^0.12.7",
|
|
67
68
|
"pinia": "^2.1.6",
|
|
69
|
+
"postcss-loader": "^8.1.1",
|
|
68
70
|
"postcss-pxtorem": "^6.1.0",
|
|
69
71
|
"sass": "^1.77.8",
|
|
70
72
|
"sass-loader": "^16.0.5",
|
|
@@ -102,7 +104,6 @@
|
|
|
102
104
|
"koa-proxy": "^1.0.0-alpha.3",
|
|
103
105
|
"mocha": "^6.1.4",
|
|
104
106
|
"postcss": "^8.4.41",
|
|
105
|
-
"postcss-loader": "^8.1.1",
|
|
106
107
|
"supertest": "^4.0.2",
|
|
107
108
|
"tailwindcss": "^3.4.10",
|
|
108
109
|
"validate-commit-msg": "~2.14.0"
|