yh-i18n 2.2.11 → 2.2.12
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/index.js +17 -10
- package/package.json +19 -19
package/index.js
CHANGED
|
@@ -25,7 +25,14 @@ import el_vi from "element-plus/dist/locale/vi.mjs";
|
|
|
25
25
|
import el_tr from "element-plus/dist/locale/tr.mjs";
|
|
26
26
|
|
|
27
27
|
// 自动根据浏览器系统语言设置语言
|
|
28
|
-
|
|
28
|
+
let navLang = navigator.language.replace("-", "_");
|
|
29
|
+
if (navLang.indexOf("en") > -1 && navLang !== "en_US") {
|
|
30
|
+
navLang = "en_US";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (navLang.indexOf("zh") > -1 && navLang !== "zh_CN") {
|
|
34
|
+
navLang = "zh_CN";
|
|
35
|
+
}
|
|
29
36
|
const initlang = localStorage.translateLanguage || navLang || "zh_CN";
|
|
30
37
|
|
|
31
38
|
export let i18n = null;
|
|
@@ -40,7 +47,7 @@ Object.keys(zhCNBase).forEach((key) => {
|
|
|
40
47
|
|
|
41
48
|
const unHandle = [];
|
|
42
49
|
|
|
43
|
-
function addTranslate(key) {
|
|
50
|
+
function addTranslate (key) {
|
|
44
51
|
if (key.indexOf("vxe") === -1) {
|
|
45
52
|
try {
|
|
46
53
|
axios.request({
|
|
@@ -58,7 +65,7 @@ function addTranslate(key) {
|
|
|
58
65
|
}
|
|
59
66
|
|
|
60
67
|
let recursionAddTimer = null;
|
|
61
|
-
function recursionAddTranslate() {
|
|
68
|
+
function recursionAddTranslate () {
|
|
62
69
|
if (recursionAddTimer !== null) {
|
|
63
70
|
return false;
|
|
64
71
|
}
|
|
@@ -99,7 +106,7 @@ export const useI18nStore = defineStore("i18nStore", () => {
|
|
|
99
106
|
/**
|
|
100
107
|
* @param {I18nList} l 要设置的新语言
|
|
101
108
|
*/
|
|
102
|
-
function setLang(l) {
|
|
109
|
+
function setLang (l) {
|
|
103
110
|
lang.value = l;
|
|
104
111
|
localStorage.translateLanguage = l;
|
|
105
112
|
if (i18n) {
|
|
@@ -116,7 +123,7 @@ export const useI18nStore = defineStore("i18nStore", () => {
|
|
|
116
123
|
});
|
|
117
124
|
|
|
118
125
|
const localList = reactive([]);
|
|
119
|
-
function setLocalList(list) {
|
|
126
|
+
function setLocalList (list) {
|
|
120
127
|
list.forEach((item) => {
|
|
121
128
|
switch (item) {
|
|
122
129
|
case "zh_CN":
|
|
@@ -184,7 +191,7 @@ export const useI18nStore = defineStore("i18nStore", () => {
|
|
|
184
191
|
};
|
|
185
192
|
});
|
|
186
193
|
|
|
187
|
-
async function getRemoteMessage(list) {
|
|
194
|
+
async function getRemoteMessage (list) {
|
|
188
195
|
try {
|
|
189
196
|
let messages = {
|
|
190
197
|
zh_CN: {},
|
|
@@ -231,7 +238,7 @@ async function getRemoteMessage(list) {
|
|
|
231
238
|
} catch (error) {}
|
|
232
239
|
}
|
|
233
240
|
|
|
234
|
-
function createLocalMessage(list) {
|
|
241
|
+
function createLocalMessage (list) {
|
|
235
242
|
let messages = {};
|
|
236
243
|
list.forEach((item) => {
|
|
237
244
|
switch (item) {
|
|
@@ -260,7 +267,7 @@ function createLocalMessage(list) {
|
|
|
260
267
|
return messages;
|
|
261
268
|
}
|
|
262
269
|
|
|
263
|
-
export function addI18nPage(router) {
|
|
270
|
+
export function addI18nPage (router) {
|
|
264
271
|
if (isDev) {
|
|
265
272
|
router.addRoute("Index", {
|
|
266
273
|
path: "translate",
|
|
@@ -274,7 +281,7 @@ export function addI18nPage(router) {
|
|
|
274
281
|
}
|
|
275
282
|
}
|
|
276
283
|
|
|
277
|
-
export function cLog(string, isError = false) {
|
|
284
|
+
export function cLog (string, isError = false) {
|
|
278
285
|
if (isError) {
|
|
279
286
|
console.error("%cyhI18n:%c", "font-size: 16px;font-weight: bold;color: #00ffff", "font-size: 16px;font-weight: bold;color: #ccccc", string);
|
|
280
287
|
} else {
|
|
@@ -283,7 +290,7 @@ export function cLog(string, isError = false) {
|
|
|
283
290
|
}
|
|
284
291
|
|
|
285
292
|
export const yhI18n = {
|
|
286
|
-
install(app, config) {
|
|
293
|
+
install (app, config) {
|
|
287
294
|
let { list, router, pinia, VXETable } = config;
|
|
288
295
|
if (!list) {
|
|
289
296
|
cLog("请设置 Config.i18nList ,并将其设置到 yhI18n 的 congfig.list 上,否则 国际化插件将失效");
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "yh-i18n",
|
|
3
|
-
"version": "2.2.
|
|
4
|
-
"description": "对于国际化的封装",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"pub:npm": "npm publish --registry https://registry.npmjs.org/ --no-git-checks",
|
|
8
|
-
"pub:aliyun": "npm publish --registry https://packages.aliyun.com/60765e0161a945067837bb5f/npm/npm-registry/ --no-git-checks"
|
|
9
|
-
},
|
|
10
|
-
"dependencies": {
|
|
11
|
-
"exceljs": "4.4.0"
|
|
12
|
-
},
|
|
13
|
-
"peerDependencies": {
|
|
14
|
-
"vue-i18n": "9.8.0",
|
|
15
|
-
"vue": "3.2.47",
|
|
16
|
-
"vxe-table": "4.3.10",
|
|
17
|
-
"element-plus": "2.3.8"
|
|
18
|
-
},
|
|
19
|
-
"author": "Liubin"
|
|
1
|
+
{
|
|
2
|
+
"name": "yh-i18n",
|
|
3
|
+
"version": "2.2.12",
|
|
4
|
+
"description": "对于国际化的封装",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"pub:npm": "npm publish --registry https://registry.npmjs.org/ --no-git-checks",
|
|
8
|
+
"pub:aliyun": "npm publish --registry https://packages.aliyun.com/60765e0161a945067837bb5f/npm/npm-registry/ --no-git-checks"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"exceljs": "4.4.0"
|
|
12
|
+
},
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"vue-i18n": "9.8.0",
|
|
15
|
+
"vue": "3.2.47",
|
|
16
|
+
"vxe-table": "4.3.10",
|
|
17
|
+
"element-plus": "2.3.8"
|
|
18
|
+
},
|
|
19
|
+
"author": "Liubin"
|
|
20
20
|
}
|