gc_i18n 1.5.4 → 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/AGENTS.md ADDED
@@ -0,0 +1,24 @@
1
+ # Repository Guidelines
2
+
3
+ ## Project Structure & Module Organization
4
+ `packages/` contains the published library source: `index.js` is the main entry, `libs/` holds utilities and services, and `components/` contains reusable UI pieces. `src/` is the local Vite playground used to exercise the plugin in a Vue app, with routes in `src/router/` and views in `src/view/`. `lang/` stores bundled language data. `example/vue2-test/` and `example/vue3-test/` are manual integration fixtures. `lib/` contains build artifacts and should only change when releasing a new build.
5
+
6
+ ## Build, Test, and Development Commands
7
+ Prefer `pnpm` because the repo declares `pnpm@10` and includes a workspace file.
8
+
9
+ - `pnpm dev`: start the local Vite playground.
10
+ - `pnpm dev:unit`: run the playground in `unit` mode on port `8080`.
11
+ - `pnpm dev:template`: run the template mode on port `8081`.
12
+ - `pnpm build`: generate library bundles in `lib/`.
13
+ - `pnpm preview`: preview the latest production build.
14
+ - `cd example/vue3-test && pnpm dev`: verify Vue 3 integration.
15
+ - `cd example/vue2-test && pnpm dev`: verify Vue 2 integration.
16
+
17
+ ## Coding Style & Naming Conventions
18
+ Match the style of the file you touch. In current source, prefer double quotes, semicolons, and descriptive camelCase names for variables and functions. Use PascalCase for Vue components such as `Home.vue`, and keep utility modules in lowercase filenames such as `service.js` or `i18nUtils.ts`. Default to 2-space indentation in Vue/JS files unless the target file already uses a different width.
19
+
20
+ ## Testing Guidelines
21
+ There is no automated unit test suite configured in the root package. Validate changes by running `pnpm build` and manually exercising the Vue 2 and Vue 3 examples, especially `$t()`, locale switching, router integration, and keyboard-triggered flows. Keep example-specific notes in `example/TEST_REPORT.md` when behavior or compatibility changes.
22
+
23
+ ## Commit & Pull Request Guidelines
24
+ Recent history uses short conventional prefixes: `feat:`, `fix:`, and `build:`. Follow that format and keep subjects brief, for example `fix: normalize Firefox locale handling`. Pull requests should state the user-facing change, list verification steps, and include screenshots or recordings for UI or modal changes. Call out any regenerated `lib/` files so reviewers can separate source edits from build output.
@@ -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 pro_zh_CN from 'pro_iview_v3/lib/locales/zh-CN';
3
- import iview_zh_CN from 'view-ui-plus/dist/locale/zh-CN';
4
- import pro_zh_TW from 'pro_iview_v3/lib/locales/zh-TW';
5
- import iview_zh_TW from 'view-ui-plus/dist/locale/zh-TW';
6
-
7
- import gc_i18n from 'gc_i18n'
8
- export const languages = [{
9
- code: "zh-CN",
10
- name: "简体中文"
11
- },{
12
- code: "zh-TW",
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
- install(app, router) {
17
- const { i18n } = new gc_i18n({
18
- appCode: "TEST",
19
- router,
20
- local: localStorage.getItem('I18N_LANGUAGE'),
21
- token: localStorage.getItem('I18N_TOKEN'),
22
- messages:{
23
- "zh-CN":{...pro_zh_CN, ...iview_zh_CN},"zh-TW":{...pro_zh_TW, ...iview_zh_TW}
24
- }
25
- })
26
- app.use(i18n)
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 "gc_i18n";
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
- messages: {
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
 
@@ -6,7 +6,7 @@ import { resolve } from "path";
6
6
 
7
7
  // 配置 i18n 插件
8
8
  const i18nPlugin = vitePluginsAutoI18n({
9
- appCode: "TEST",
9
+ appCode: "TEST_VUE3",
10
10
  env: "local",
11
11
  excludedPath: ["node_modules", "src/main.js"]
12
12
  });
package/lang/index.json CHANGED
@@ -134,5 +134,9 @@
134
134
  "mhhc53": {
135
135
  "zh-cn": "阿拉伯",
136
136
  "zh-tw": "阿拉伯"
137
+ },
138
+ "je4zs38": {
139
+ "zh-cn": "保存的翻译数据:",
140
+ "zh-tw": "保存的翻譯數據:"
137
141
  }
138
142
  }