gc_i18n 1.5.5 → 1.5.6
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/example/vue3-test/lang/index.js +27 -27
- package/example/vue3-test/lang/index.json +32 -0
- package/example/vue3-test/src/App.vue +19 -0
- package/example/vue3-test/src/auth.js +43 -0
- package/example/vue3-test/src/main.js +3 -18
- package/example/vue3-test/vite.config.js +1 -1
- package/lib/gc_i18n.es.js +1275 -1151
- package/lib/gc_i18n.umd.js +49 -49
- package/package.json +1 -1
- package/packages/components/earth.js +29 -0
- package/packages/index.js +234 -60
- package/packages/libs/service.js +68 -29
- package/packages/libs/textEditMode.js +21 -36
- package/vite.config.js +9 -7
|
@@ -1,29 +1,29 @@
|
|
|
1
|
+
import pro_zh_CN from "pro_iview_v3/lib/locales/zh-CN";
|
|
2
|
+
import iview_zh_CN from "view-ui-plus/dist/locale/zh-CN";
|
|
3
|
+
import pro_zh_TW from "pro_iview_v3/lib/locales/zh-TW";
|
|
4
|
+
import iview_zh_TW from "view-ui-plus/dist/locale/zh-TW";
|
|
1
5
|
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
name: "繁体中文"
|
|
14
|
-
}]
|
|
6
|
+
import gc_i18n from "../../../packages/index";
|
|
7
|
+
export const languages = [
|
|
8
|
+
{
|
|
9
|
+
code: "zh-CN",
|
|
10
|
+
name: "简体中文"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
code: "zh-TW",
|
|
14
|
+
name: "繁体中文"
|
|
15
|
+
}
|
|
16
|
+
];
|
|
15
17
|
export default {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
18
|
+
install(app, router) {
|
|
19
|
+
const { i18n } = new gc_i18n({
|
|
20
|
+
appCode: "TEST_VUE3",
|
|
21
|
+
router,
|
|
22
|
+
messages: {
|
|
23
|
+
"zh-CN": { ...pro_zh_CN, ...iview_zh_CN },
|
|
24
|
+
"zh-TW": { ...pro_zh_TW, ...iview_zh_TW }
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
app.use(i18n);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
@@ -14,5 +14,37 @@
|
|
|
14
14
|
"lws22": {
|
|
15
15
|
"zh-cn": "繁体",
|
|
16
16
|
"zh-tw": "繁體"
|
|
17
|
+
},
|
|
18
|
+
"lggagb5": {
|
|
19
|
+
"zh-cn": "登录状态:",
|
|
20
|
+
"zh-tw": "登錄狀態:"
|
|
21
|
+
},
|
|
22
|
+
"ec1po3": {
|
|
23
|
+
"zh-cn": "已登录",
|
|
24
|
+
"zh-tw": "已登錄"
|
|
25
|
+
},
|
|
26
|
+
"fonok3": {
|
|
27
|
+
"zh-cn": "未登录",
|
|
28
|
+
"zh-tw": "未登錄"
|
|
29
|
+
},
|
|
30
|
+
"koca2": {
|
|
31
|
+
"zh-cn": "登录",
|
|
32
|
+
"zh-tw": "登錄"
|
|
33
|
+
},
|
|
34
|
+
"klpb2": {
|
|
35
|
+
"zh-cn": "登出",
|
|
36
|
+
"zh-tw": "登出"
|
|
37
|
+
},
|
|
38
|
+
"gkc0dp4": {
|
|
39
|
+
"zh-cn": "繁體中文",
|
|
40
|
+
"zh-tw": "繁體中文"
|
|
41
|
+
},
|
|
42
|
+
"kgsv2": {
|
|
43
|
+
"zh-cn": "用户",
|
|
44
|
+
"zh-tw": "用戶"
|
|
45
|
+
},
|
|
46
|
+
"f6tq2o4": {
|
|
47
|
+
"zh-cn": "用户房子",
|
|
48
|
+
"zh-tw": "用戶房子"
|
|
17
49
|
}
|
|
18
50
|
}
|
|
@@ -2,9 +2,14 @@
|
|
|
2
2
|
<div id="app">
|
|
3
3
|
<h1>{{ $t("welcome") }}</h1>
|
|
4
4
|
<p>{{ $t("description") }}</p>
|
|
5
|
+
<p class="status">登录状态: {{ authState.token ? "已登录" : "未登录" }}</p>
|
|
6
|
+
<p class="status">Scope: {{ authState.scope || "登录" }}</p>
|
|
5
7
|
<div>
|
|
6
8
|
<button @click="changeLang('zh-CN')">中文</button>
|
|
9
|
+
<button @click="changeLang('zh-TW')">繁體中文</button>
|
|
7
10
|
<button @click="changeLang('en-US')">English</button>
|
|
11
|
+
<button @click="login">登录</button>
|
|
12
|
+
<button @click="logout">登出</button>
|
|
8
13
|
</div>
|
|
9
14
|
<router-view />
|
|
10
15
|
</div>
|
|
@@ -12,12 +17,21 @@
|
|
|
12
17
|
|
|
13
18
|
<script setup>
|
|
14
19
|
import { getCurrentInstance } from "vue";
|
|
20
|
+
import { authState, auth } from "./auth";
|
|
15
21
|
|
|
16
22
|
const { proxy } = getCurrentInstance();
|
|
17
23
|
|
|
18
24
|
const changeLang = (lang) => {
|
|
19
25
|
proxy.$i18n.changeLocale(lang);
|
|
20
26
|
};
|
|
27
|
+
|
|
28
|
+
const login = () => {
|
|
29
|
+
auth.login("demo-user");
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const logout = () => {
|
|
33
|
+
auth.logout();
|
|
34
|
+
};
|
|
21
35
|
</script>
|
|
22
36
|
|
|
23
37
|
<style>
|
|
@@ -42,4 +56,9 @@ button {
|
|
|
42
56
|
button:hover {
|
|
43
57
|
background: #f0f0f0;
|
|
44
58
|
}
|
|
59
|
+
|
|
60
|
+
.status {
|
|
61
|
+
margin: 8px 0;
|
|
62
|
+
color: #666;
|
|
63
|
+
}
|
|
45
64
|
</style>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { reactive } from "vue";
|
|
2
|
+
|
|
3
|
+
const TOKEN_KEY = "I18N_TOKEN";
|
|
4
|
+
const SCOPE_KEY = "I18N_SCOPE";
|
|
5
|
+
|
|
6
|
+
const listeners = new Set();
|
|
7
|
+
|
|
8
|
+
export const authState = reactive({
|
|
9
|
+
token: localStorage.getItem(TOKEN_KEY) || "",
|
|
10
|
+
scope: localStorage.getItem(SCOPE_KEY) || ""
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const emit = () => {
|
|
14
|
+
const state = {
|
|
15
|
+
token: authState.token,
|
|
16
|
+
scope: authState.scope,
|
|
17
|
+
isAuthenticated: !!authState.token
|
|
18
|
+
};
|
|
19
|
+
listeners.forEach((listener) => listener(state));
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const auth = {
|
|
23
|
+
getToken: () => authState.token,
|
|
24
|
+
getScope: () => authState.scope,
|
|
25
|
+
subscribe(listener) {
|
|
26
|
+
listeners.add(listener);
|
|
27
|
+
return () => listeners.delete(listener);
|
|
28
|
+
},
|
|
29
|
+
login(scope = "demo-user") {
|
|
30
|
+
authState.token = `test-token-${scope}`;
|
|
31
|
+
authState.scope = scope;
|
|
32
|
+
localStorage.setItem(TOKEN_KEY, authState.token);
|
|
33
|
+
localStorage.setItem(SCOPE_KEY, authState.scope);
|
|
34
|
+
emit();
|
|
35
|
+
},
|
|
36
|
+
logout() {
|
|
37
|
+
authState.token = "";
|
|
38
|
+
authState.scope = "";
|
|
39
|
+
localStorage.removeItem(TOKEN_KEY);
|
|
40
|
+
localStorage.removeItem(SCOPE_KEY);
|
|
41
|
+
emit();
|
|
42
|
+
}
|
|
43
|
+
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createApp } from "vue";
|
|
2
2
|
import { createRouter, createWebHistory } from "vue-router";
|
|
3
|
-
import I18n from "
|
|
3
|
+
import I18n from "../../../packages/index";
|
|
4
4
|
import App from "./App.vue";
|
|
5
|
+
import { auth } from "./auth";
|
|
5
6
|
|
|
6
7
|
// 创建路由实例
|
|
7
8
|
const router = createRouter({
|
|
@@ -23,29 +24,13 @@ const i18n = new I18n({
|
|
|
23
24
|
appCode: "TEST_VUE3",
|
|
24
25
|
router,
|
|
25
26
|
env: "dev",
|
|
26
|
-
|
|
27
|
-
"zh-CN": {
|
|
28
|
-
welcome: "你好"
|
|
29
|
-
},
|
|
30
|
-
"en-US": {
|
|
31
|
-
welcome: "Hello"
|
|
32
|
-
}
|
|
33
|
-
}
|
|
27
|
+
auth
|
|
34
28
|
});
|
|
35
29
|
|
|
36
|
-
console.log("i18n instance:", i18n);
|
|
37
|
-
console.log("i18n.install:", i18n.install);
|
|
38
|
-
|
|
39
30
|
// 使用插件
|
|
40
31
|
app.use(router);
|
|
41
32
|
app.use(i18n);
|
|
42
33
|
|
|
43
|
-
// 手动测试
|
|
44
|
-
console.log(
|
|
45
|
-
"After app.use, app.config.globalProperties.$t:",
|
|
46
|
-
app.config.globalProperties.$t
|
|
47
|
-
);
|
|
48
|
-
|
|
49
34
|
// 挂载应用
|
|
50
35
|
app.mount("#app");
|
|
51
36
|
|