@origen-ui/admin-cli 1.0.3 → 1.1.0
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/package.json +3 -3
- package/templates/current/clean/CHANGELOG.md +34 -0
- package/templates/current/clean/component-catalog.json +9 -9
- package/templates/current/clean/package.json +41 -41
- package/templates/current/clean/scaffold.lock.json +2 -2
- package/templates/current/clean/scripts/vite-build-policy.spec.ts +71 -0
- package/templates/current/clean/src/App.vue +10 -3
- package/templates/current/clean/src/api/client.ts +90 -10
- package/templates/current/clean/src/api/generated/data-contracts.ts +3 -3
- package/templates/current/clean/src/api/generated/http-client.ts +1 -1
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/206/205/345/256/271/346/226/207/347/253/240.ts +1 -1
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/256/241/350/256/241.ts +1 -1
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/346/226/207/344/273/266/344/270/212/344/274/240.ts +1 -1
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/347/224/250/346/210/267.ts +2 -3
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/217/234/345/215/225.ts +3 -5
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/247/222/350/211/262.ts +2 -3
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/256/242/345/215/225/350/215/211/347/250/277.ts +2 -3
- package/templates/current/clean/src/api/generated//350/256/244/350/257/201.ts +1 -1
- package/templates/current/clean/src/app/adminLocale.ts +90 -0
- package/templates/current/clean/src/app/createAdminUi.spec.ts +65 -9
- package/templates/current/clean/src/app/createAdminUi.ts +14 -29
- package/templates/current/clean/src/app/embedded-token.spec.ts +40 -0
- package/templates/current/clean/src/app/embedded.spec.ts +135 -0
- package/templates/current/clean/src/app/embedded.ts +255 -0
- package/templates/current/clean/src/app/localeFormat.ts +52 -0
- package/templates/current/clean/src/app/menu.spec.ts +26 -0
- package/templates/current/clean/src/app/menu.ts +4 -0
- package/templates/current/clean/src/app/menuTypes.ts +1 -0
- package/templates/current/clean/src/app/origenUiLocale.spec.ts +6 -5
- package/templates/current/clean/src/app/origenUiLocale.ts +3 -58
- package/templates/current/clean/src/app/permission.spec.ts +26 -0
- package/templates/current/clean/src/app/runtimeConfig.ts +8 -7
- package/templates/current/clean/src/env.d.ts +18 -0
- package/templates/current/clean/src/features/appearance/components/ThemePanel.vue +21 -17
- package/templates/current/clean/src/features/appearance/store/theme.ts +2 -1
- package/templates/current/clean/src/features/auth/pages/Login.vue +15 -11
- package/templates/current/clean/src/features/auth/store/auth.ts +13 -3
- package/templates/current/clean/src/features/security/components/DevtoolsProtectionOverlay.vue +5 -2
- package/templates/current/clean/src/features/security/devtoolsProtection.spec.ts +7 -10
- package/templates/current/clean/src/features/security/devtoolsProtection.ts +2 -1
- package/templates/current/clean/src/features/system/access/api/admin-repository.spec.ts +14 -0
- package/templates/current/clean/src/features/system/access/api/admin-repository.ts +38 -15
- package/templates/current/clean/src/features/system/access/api/rbac.ts +37 -27
- package/templates/current/clean/src/features/workspace/pages/Empty.vue +4 -1
- package/templates/current/clean/src/features/workspace/pages/Profile.vue +13 -11
- package/templates/current/clean/src/layouts/AdminLayout.vue +3 -1
- package/templates/current/clean/src/layouts/TopBar.vue +26 -8
- package/templates/current/clean/src/locales/en-US.json +490 -0
- package/templates/current/clean/src/locales/en-US.runtime.ts +20 -0
- package/templates/current/clean/src/locales/index.ts +129 -45
- package/templates/current/clean/src/locales/messages-types.ts +62 -0
- package/templates/current/clean/src/locales/messages.spec.ts +113 -6
- package/templates/current/clean/src/locales/vue-i18n.d.ts +5 -0
- package/templates/current/clean/src/locales/zh-CN.json +490 -0
- package/templates/current/clean/src/locales/zh-CN.runtime.ts +20 -0
- package/templates/current/clean/src/locales/zh-TW.json +490 -0
- package/templates/current/clean/src/locales/zh-TW.runtime.ts +20 -0
- package/templates/current/clean/src/router/bootstrap.ts +22 -7
- package/templates/current/clean/src/router/dynamicRoutes.ts +5 -1
- package/templates/current/clean/src/router/queryEncryption.spec.ts +30 -4
- package/templates/current/clean/src/router/queryEncryption.ts +48 -44
- package/templates/current/clean/src/router/useRouteQueryDefaults.spec.ts +2 -1
- package/templates/current/clean/src/router/useRouteQueryDefaults.types.ts +2 -1
- package/templates/current/clean/src/templates/og-table.ts +81 -37
- package/templates/current/clean/src/templates/templates.spec.ts +19 -0
- package/templates/current/clean/vite.build-policy.ts +114 -289
- package/templates/current/clean/vite.config.ts +4 -5
- package/templates/current/examples/CHANGELOG.md +34 -0
- package/templates/current/examples/component-catalog.json +9 -9
- package/templates/current/examples/package.json +41 -41
- package/templates/current/examples/scaffold.lock.json +2 -2
- package/templates/current/examples/scripts/vite-build-policy.spec.ts +71 -0
- package/templates/current/examples/src/App.vue +10 -3
- package/templates/current/examples/src/api/client.ts +90 -10
- package/templates/current/examples/src/api/generated/data-contracts.ts +3 -3
- package/templates/current/examples/src/api/generated/http-client.ts +1 -1
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/206/205/345/256/271/346/226/207/347/253/240.ts +1 -1
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/256/241/350/256/241.ts +1 -1
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/346/226/207/344/273/266/344/270/212/344/274/240.ts +1 -1
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/347/224/250/346/210/267.ts +2 -3
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/217/234/345/215/225.ts +3 -5
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/247/222/350/211/262.ts +2 -3
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/256/242/345/215/225/350/215/211/347/250/277.ts +2 -3
- package/templates/current/examples/src/api/generated//350/256/244/350/257/201.ts +1 -1
- package/templates/current/examples/src/app/adminLocale.ts +90 -0
- package/templates/current/examples/src/app/createAdminUi.spec.ts +65 -9
- package/templates/current/examples/src/app/createAdminUi.ts +14 -29
- package/templates/current/examples/src/app/embedded-token.spec.ts +40 -0
- package/templates/current/examples/src/app/embedded.spec.ts +135 -0
- package/templates/current/examples/src/app/embedded.ts +255 -0
- package/templates/current/examples/src/app/localeFormat.ts +52 -0
- package/templates/current/examples/src/app/menu.spec.ts +26 -0
- package/templates/current/examples/src/app/menu.ts +4 -0
- package/templates/current/examples/src/app/menuTypes.ts +1 -0
- package/templates/current/examples/src/app/origenUiLocale.spec.ts +6 -5
- package/templates/current/examples/src/app/origenUiLocale.ts +3 -58
- package/templates/current/examples/src/app/permission.spec.ts +26 -0
- package/templates/current/examples/src/app/runtimeConfig.ts +8 -7
- package/templates/current/examples/src/env.d.ts +18 -0
- package/templates/current/examples/src/features/appearance/components/ThemePanel.vue +21 -17
- package/templates/current/examples/src/features/appearance/store/theme.ts +2 -1
- package/templates/current/examples/src/features/auth/pages/Login.vue +15 -11
- package/templates/current/examples/src/features/auth/store/auth.ts +13 -3
- package/templates/current/examples/src/features/errors/pages/Forbidden.vue +6 -2
- package/templates/current/examples/src/features/errors/pages/NotFound.vue +6 -2
- package/templates/current/examples/src/features/errors/pages/ServerError.vue +6 -2
- package/templates/current/examples/src/features/errors/pages/error-pages.spec.ts +9 -1
- package/templates/current/examples/src/features/feature-composables.spec.ts +36 -9
- package/templates/current/examples/src/features/security/components/DevtoolsProtectionOverlay.vue +5 -2
- package/templates/current/examples/src/features/security/devtoolsProtection.spec.ts +7 -10
- package/templates/current/examples/src/features/security/devtoolsProtection.ts +2 -1
- package/templates/current/examples/src/features/system/access/api/admin-repository.spec.ts +14 -0
- package/templates/current/examples/src/features/system/access/api/admin-repository.ts +38 -15
- package/templates/current/examples/src/features/system/access/api/rbac.ts +37 -27
- package/templates/current/examples/src/features/system/audit/composables/useAuditManagement.ts +43 -38
- package/templates/current/examples/src/features/system/menus/components/MenuEditorForm.vue +33 -30
- package/templates/current/examples/src/features/system/menus/composables/useMenuManagement.ts +81 -69
- package/templates/current/examples/src/features/system/menus/pages/MenuList.vue +3 -1
- package/templates/current/examples/src/features/system/roles/components/RoleEditorForm.vue +18 -15
- package/templates/current/examples/src/features/system/roles/composables/useRoleManagement.ts +49 -53
- package/templates/current/examples/src/features/system/roles/pages/RoleList.vue +3 -1
- package/templates/current/examples/src/features/system/users/components/UserEditorForm.vue +22 -19
- package/templates/current/examples/src/features/system/users/composables/useUserManagement.ts +59 -64
- package/templates/current/examples/src/features/system/users/pages/UserList.vue +3 -1
- package/templates/current/examples/src/features/workspace/pages/Dashboard.spec.ts +9 -0
- package/templates/current/examples/src/features/workspace/pages/Dashboard.vue +54 -26
- package/templates/current/examples/src/features/workspace/pages/Empty.vue +4 -1
- package/templates/current/examples/src/features/workspace/pages/Profile.vue +13 -11
- package/templates/current/examples/src/layouts/AdminLayout.vue +3 -1
- package/templates/current/examples/src/layouts/TopBar.vue +26 -8
- package/templates/current/examples/src/locales/en-US.json +490 -0
- package/templates/current/examples/src/locales/en-US.runtime.ts +20 -0
- package/templates/current/examples/src/locales/index.ts +129 -45
- package/templates/current/examples/src/locales/messages-types.ts +62 -0
- package/templates/current/examples/src/locales/messages.spec.ts +113 -6
- package/templates/current/examples/src/locales/vue-i18n.d.ts +5 -0
- package/templates/current/examples/src/locales/zh-CN.json +490 -0
- package/templates/current/examples/src/locales/zh-CN.runtime.ts +20 -0
- package/templates/current/examples/src/locales/zh-TW.json +490 -0
- package/templates/current/examples/src/locales/zh-TW.runtime.ts +20 -0
- package/templates/current/examples/src/main.ts +31 -5
- package/templates/current/examples/src/router/bootstrap.ts +22 -7
- package/templates/current/examples/src/router/dynamicRoutes.spec.ts +17 -0
- package/templates/current/examples/src/router/dynamicRoutes.ts +5 -1
- package/templates/current/examples/src/router/queryEncryption.spec.ts +30 -4
- package/templates/current/examples/src/router/queryEncryption.ts +48 -44
- package/templates/current/examples/src/router/staticRoutes.ts +1 -1
- package/templates/current/examples/src/router/useRouteQueryDefaults.spec.ts +2 -1
- package/templates/current/examples/src/router/useRouteQueryDefaults.types.ts +2 -1
- package/templates/current/examples/src/templates/og-table.ts +81 -37
- package/templates/current/examples/src/templates/templates.spec.ts +19 -0
- package/templates/current/examples/vite.build-policy.ts +114 -289
- package/templates/current/examples/vite.config.ts +4 -5
- package/templates/current/clean/scripts/check-admin-bundle.mjs +0 -214
- package/templates/current/clean/scripts/performance/baselines/bundle-gzip-v2-pre-entry-unification.json +0 -38
- package/templates/current/clean/src/locales/en-US.ts +0 -55
- package/templates/current/clean/src/locales/zh-CN.ts +0 -55
- package/templates/current/clean/src/locales/zh-TW.ts +0 -44
- package/templates/current/examples/scripts/check-admin-bundle.mjs +0 -214
- package/templates/current/examples/scripts/performance/baselines/bundle-gzip-v2-pre-entry-unification.json +0 -38
- package/templates/current/examples/src/locales/en-US.ts +0 -55
- package/templates/current/examples/src/locales/zh-CN.ts +0 -55
- package/templates/current/examples/src/locales/zh-TW.ts +0 -44
|
@@ -4,90 +4,173 @@ import type { OrigenUiLanguageModule, OrigenUiLanguageRuntime } from 'origen-ui/
|
|
|
4
4
|
import type { App } from 'vue'
|
|
5
5
|
import type { I18n } from 'vue-i18n'
|
|
6
6
|
import type { RouteLocationNormalizedLoaded } from 'vue-router'
|
|
7
|
-
import {
|
|
7
|
+
import type { AdminLocale } from '../app/adminLocale'
|
|
8
|
+
import type { AdminMessages } from './messages-types'
|
|
9
|
+
import { createOrigenUiLanguageRuntime, defineOrigenUiLanguage, mergeLocale } from 'origen-ui/language'
|
|
8
10
|
import { watch } from 'vue'
|
|
9
11
|
import { createI18n } from 'vue-i18n'
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
+
import {
|
|
13
|
+
LOCALE_STORAGE_KEY,
|
|
14
|
+
normalizeAdminLocale,
|
|
15
|
+
resolveInitialLocale,
|
|
16
|
+
setAdminLocale,
|
|
17
|
+
} from '../app/adminLocale'
|
|
18
|
+
import {
|
|
19
|
+
enUSLocale,
|
|
20
|
+
validateAdminLocaleMessages,
|
|
21
|
+
zhCNLocale,
|
|
22
|
+
zhTWLocale,
|
|
23
|
+
} from './messages-types'
|
|
24
|
+
import zhCN from './zh-CN.json'
|
|
25
|
+
import {
|
|
26
|
+
elementPlus as zhCNElementPlus,
|
|
27
|
+
origenUi as zhCNOrigenUi,
|
|
28
|
+
} from './zh-CN.runtime'
|
|
29
|
+
|
|
30
|
+
export type { AdminLocale } from '../app/adminLocale'
|
|
31
|
+
export { currentAdminLocale, normalizeAdminLocale, SUPPORTED_LOCALES } from '../app/adminLocale'
|
|
12
32
|
|
|
13
|
-
export type AdminLocale = 'zh-CN' | 'en-US' | 'zh-TW'
|
|
14
33
|
export type AdminLanguageModule = OrigenUiLanguageModule<
|
|
15
|
-
|
|
34
|
+
AdminMessages,
|
|
16
35
|
unknown,
|
|
17
36
|
OrigenUiMessages
|
|
18
37
|
>
|
|
19
38
|
|
|
20
|
-
|
|
21
|
-
export
|
|
22
|
-
|
|
23
|
-
export function normalizeAdminLocale(value: unknown): AdminLocale | undefined {
|
|
24
|
-
if (typeof value !== 'string') return undefined
|
|
25
|
-
const normalized = value.trim().toLowerCase()
|
|
26
|
-
if (normalized === 'zh' || normalized === 'zh-hans' || normalized === 'zh-cn') return 'zh-CN'
|
|
27
|
-
if (normalized === 'zh-hant' || normalized === 'zh-tw' || normalized === 'zh-hk') return 'zh-TW'
|
|
28
|
-
if (normalized === 'en' || normalized === 'en-us') return 'en-US'
|
|
29
|
-
return undefined
|
|
30
|
-
}
|
|
39
|
+
/** Admin 消息树叶子 key 的联合类型(如 'auth.login'),用于动态 key 的编译期标注。 */
|
|
40
|
+
export type AdminMessageKey = PathKeys<AdminMessages>
|
|
31
41
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
42
|
+
type PathKeys<T, P extends string = ''> = T extends string
|
|
43
|
+
? P
|
|
44
|
+
: T extends readonly unknown[]
|
|
45
|
+
? never
|
|
46
|
+
: T extends object
|
|
47
|
+
? {
|
|
48
|
+
[K in keyof T & string]: PathKeys<T[K], P extends '' ? K : `${P}.${K}`>
|
|
49
|
+
}[keyof T & string]
|
|
50
|
+
: never
|
|
40
51
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
const zhCNModule: AdminLanguageModule = defineOrigenUiLanguage<
|
|
53
|
+
AdminMessages,
|
|
54
|
+
unknown,
|
|
55
|
+
OrigenUiMessages
|
|
56
|
+
>({
|
|
57
|
+
locale: zhCNLocale,
|
|
58
|
+
messages: zhCN,
|
|
59
|
+
elementPlus: zhCNElementPlus,
|
|
60
|
+
origenUi: zhCNOrigenUi,
|
|
61
|
+
})
|
|
50
62
|
|
|
51
|
-
const loaders = {
|
|
52
|
-
'en-US': () =>
|
|
53
|
-
|
|
63
|
+
const loaders: Record<'en-US' | 'zh-TW', () => Promise<AdminLanguageModule>> = {
|
|
64
|
+
'en-US': async () => {
|
|
65
|
+
const [{ default: messages }, { elementPlus, origenUi }] = await Promise.all([
|
|
66
|
+
import('./en-US.json'),
|
|
67
|
+
import('./en-US.runtime'),
|
|
68
|
+
])
|
|
69
|
+
return defineOrigenUiLanguage<AdminMessages, unknown, OrigenUiMessages>({
|
|
70
|
+
locale: enUSLocale,
|
|
71
|
+
messages,
|
|
72
|
+
elementPlus,
|
|
73
|
+
origenUi,
|
|
74
|
+
})
|
|
75
|
+
},
|
|
76
|
+
'zh-TW': async () => {
|
|
77
|
+
const [{ default: messages }, { elementPlus, origenUi }] = await Promise.all([
|
|
78
|
+
import('./zh-TW.json'),
|
|
79
|
+
import('./zh-TW.runtime'),
|
|
80
|
+
])
|
|
81
|
+
return defineOrigenUiLanguage<AdminMessages, unknown, OrigenUiMessages>({
|
|
82
|
+
locale: zhTWLocale,
|
|
83
|
+
messages,
|
|
84
|
+
elementPlus,
|
|
85
|
+
origenUi,
|
|
86
|
+
})
|
|
87
|
+
},
|
|
54
88
|
}
|
|
55
89
|
|
|
56
90
|
export interface AdminI18nRuntime {
|
|
57
91
|
i18n: I18n
|
|
58
|
-
language: OrigenUiLanguageRuntime<
|
|
92
|
+
language: OrigenUiLanguageRuntime<AdminMessages, unknown, OrigenUiMessages>
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let runtimeI18n: I18n | null = null
|
|
96
|
+
|
|
97
|
+
/** Returns the active admin i18n instance, or null before bootstrap completes. */
|
|
98
|
+
export function getAdminI18n(): I18n | null {
|
|
99
|
+
return runtimeI18n
|
|
59
100
|
}
|
|
60
101
|
|
|
61
102
|
export function createAdminTitleResolver(
|
|
62
103
|
i18n: I18n,
|
|
63
104
|
): (route: RouteLocationNormalizedLoaded, meta: AdapterRouteMeta) => string | undefined {
|
|
64
105
|
return (_route, meta) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
106
|
+
const key = meta.breadcrumb?.labelKey ?? meta.titleKey
|
|
107
|
+
if (!key) return meta.title
|
|
108
|
+
const global = i18n.global as unknown as {
|
|
109
|
+
te?: (key: string) => boolean
|
|
110
|
+
t: (key: string) => string
|
|
111
|
+
}
|
|
112
|
+
if (global.te?.(key)) return global.t(key as AdminMessageKey)
|
|
113
|
+
return meta.breadcrumb?.labelKey ? meta.breadcrumb?.label ?? meta.title : meta.title
|
|
68
114
|
}
|
|
69
115
|
}
|
|
70
116
|
|
|
71
117
|
export function createAdminI18n(existing?: I18n): AdminI18nRuntime {
|
|
72
|
-
const
|
|
118
|
+
const hostLocale = existing?.global.locale
|
|
119
|
+
const initial = normalizeAdminLocale(
|
|
120
|
+
typeof hostLocale === 'string' ? hostLocale : hostLocale?.value,
|
|
121
|
+
) ?? resolveInitialLocale()
|
|
73
122
|
const i18n =
|
|
74
123
|
existing ??
|
|
75
124
|
createI18n({
|
|
76
125
|
legacy: false,
|
|
77
126
|
locale: initial,
|
|
78
127
|
fallbackLocale: 'zh-CN',
|
|
79
|
-
messages: { 'zh-CN': zhCN
|
|
128
|
+
messages: { 'zh-CN': zhCN },
|
|
80
129
|
})
|
|
81
130
|
|
|
82
|
-
|
|
131
|
+
// Reject legacy instances early — useI18n() fails at runtime in legacy mode
|
|
132
|
+
// and deep-merge of host messages relies on the Composition API.
|
|
133
|
+
if (i18n.mode !== 'composition') {
|
|
134
|
+
throw new Error(
|
|
135
|
+
'[origen-ui/admin] createAdminI18n expects a Composition-mode vue-i18n instance; found legacy mode.',
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
runtimeI18n = i18n
|
|
139
|
+
|
|
140
|
+
const language = createOrigenUiLanguageRuntime<AdminMessages, unknown, OrigenUiMessages>({
|
|
83
141
|
initial,
|
|
84
142
|
loaders: {
|
|
85
|
-
'zh-CN': () =>
|
|
143
|
+
'zh-CN': () => zhCNModule,
|
|
86
144
|
...loaders,
|
|
87
145
|
},
|
|
88
146
|
bridge: {
|
|
89
147
|
prepare: (module) => {
|
|
90
|
-
if (module.messages)
|
|
148
|
+
if (module.messages) {
|
|
149
|
+
const validation = validateAdminLocaleMessages(zhCN, module.messages)
|
|
150
|
+
if (
|
|
151
|
+
validation.missing.length ||
|
|
152
|
+
validation.extra.length ||
|
|
153
|
+
validation.invalid.length ||
|
|
154
|
+
validation.empty.length ||
|
|
155
|
+
validation.interpolation.length
|
|
156
|
+
) {
|
|
157
|
+
throw new Error(
|
|
158
|
+
`[origen-ui/admin] Invalid ${module.locale} messages: ${JSON.stringify(validation)}`,
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
// vue-i18n returns an empty object for unknown locales in normal
|
|
162
|
+
// operation, but callers may provide a custom Composer that returns
|
|
163
|
+
// undefined/null. Normalize that boundary so mergeLocale always
|
|
164
|
+
// clones the Admin payload instead of retaining the module object.
|
|
165
|
+
const hostMessages = i18n.global.getLocaleMessage(module.locale) as unknown
|
|
166
|
+
i18n.global.setLocaleMessage(
|
|
167
|
+
module.locale,
|
|
168
|
+
mergeLocale(
|
|
169
|
+
(hostMessages && typeof hostMessages === 'object' ? hostMessages : {}) as AdminMessages,
|
|
170
|
+
module.messages,
|
|
171
|
+
),
|
|
172
|
+
)
|
|
173
|
+
}
|
|
91
174
|
},
|
|
92
175
|
install: (app: App, runtime) => {
|
|
93
176
|
const sync = () => {
|
|
@@ -104,6 +187,7 @@ export function createAdminI18n(existing?: I18n): AdminI18nRuntime {
|
|
|
104
187
|
// Storage is optional; language switching remains usable when unavailable.
|
|
105
188
|
}
|
|
106
189
|
}
|
|
190
|
+
setAdminLocale(runtime.current.value as AdminLocale)
|
|
107
191
|
}
|
|
108
192
|
const stop = watch([runtime.current, runtime.active, runtime.status], sync, {
|
|
109
193
|
immediate: true,
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type zhCN from './zh-CN.json'
|
|
2
|
+
import { validateLocaleShape } from '@origen-ui/shared'
|
|
3
|
+
|
|
4
|
+
/** 简体中文 locale 标签 */
|
|
5
|
+
export const zhCNLocale = 'zh-CN' as const
|
|
6
|
+
/** 英文 locale 标签 */
|
|
7
|
+
export const enUSLocale = 'en-US' as const
|
|
8
|
+
/** 繁体中文 locale 标签 */
|
|
9
|
+
export const zhTWLocale = 'zh-TW' as const
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Admin 消息树类型基准,由 zh-CN.json 推导。
|
|
13
|
+
* 供 vue-i18n 类型化 keys(DefineLocaleMessage)与 PathKeys 联合类型使用。
|
|
14
|
+
*/
|
|
15
|
+
export type AdminMessages = typeof zhCN
|
|
16
|
+
|
|
17
|
+
export interface AdminLocaleValidation {
|
|
18
|
+
missing: string[]
|
|
19
|
+
extra: string[]
|
|
20
|
+
invalid: string[]
|
|
21
|
+
empty: string[]
|
|
22
|
+
interpolation: string[]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const interpolationPattern = /\{[^{}]+\}/g
|
|
26
|
+
|
|
27
|
+
function placeholders(value: string): string[] {
|
|
28
|
+
return value.match(interpolationPattern) ?? []
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Validates official Admin locale shape, leaf values, empties, and placeholders. */
|
|
32
|
+
export function validateAdminLocaleMessages(
|
|
33
|
+
reference: unknown,
|
|
34
|
+
candidate: unknown,
|
|
35
|
+
): AdminLocaleValidation {
|
|
36
|
+
const shape = validateLocaleShape(reference, candidate)
|
|
37
|
+
const empty: string[] = []
|
|
38
|
+
const interpolation: string[] = []
|
|
39
|
+
|
|
40
|
+
const visit = (referenceValue: unknown, candidateValue: unknown, path: string): void => {
|
|
41
|
+
if (typeof referenceValue === 'string') {
|
|
42
|
+
if (typeof candidateValue !== 'string') return
|
|
43
|
+
if (!candidateValue.trim()) empty.push(path)
|
|
44
|
+
const expected = placeholders(referenceValue).sort().join('|')
|
|
45
|
+
const actual = placeholders(candidateValue).sort().join('|')
|
|
46
|
+
if (expected !== actual) interpolation.push(path)
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
if (!referenceValue || typeof referenceValue !== 'object') return
|
|
50
|
+
if (!candidateValue || typeof candidateValue !== 'object') return
|
|
51
|
+
for (const key of Object.keys(referenceValue as Record<string, unknown>)) {
|
|
52
|
+
if (!(key in (candidateValue as Record<string, unknown>))) continue
|
|
53
|
+
visit(
|
|
54
|
+
(referenceValue as Record<string, unknown>)[key],
|
|
55
|
+
(candidateValue as Record<string, unknown>)[key],
|
|
56
|
+
path ? `${path}.${key}` : key,
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
visit(reference, candidate, '')
|
|
61
|
+
return { ...shape, empty, interpolation }
|
|
62
|
+
}
|
|
@@ -1,23 +1,130 @@
|
|
|
1
1
|
import type { I18nOptions } from 'vue-i18n'
|
|
2
|
+
import { validateLocaleShape } from '@origen-ui/shared'
|
|
2
3
|
import { describe, expect, it } from 'vitest'
|
|
3
4
|
import { createI18n } from 'vue-i18n'
|
|
4
|
-
import enUS from './en-US'
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import enUS from './en-US.json'
|
|
6
|
+
import { enUSLocale, validateAdminLocaleMessages, zhCNLocale, zhTWLocale } from './messages-types'
|
|
7
|
+
import zhCN from './zh-CN.json'
|
|
8
|
+
import zhTW from './zh-TW.json'
|
|
7
9
|
|
|
8
|
-
const modules = [
|
|
10
|
+
const modules = [
|
|
11
|
+
{ locale: zhCNLocale, messages: zhCN },
|
|
12
|
+
{ locale: enUSLocale, messages: enUS },
|
|
13
|
+
{ locale: zhTWLocale, messages: zhTW },
|
|
14
|
+
]
|
|
9
15
|
|
|
10
16
|
describe('admin locale messages', () => {
|
|
11
17
|
it.each(modules)('compiles the app title for $locale', (module) => {
|
|
12
18
|
const i18n = createI18n({
|
|
13
19
|
legacy: false,
|
|
14
20
|
locale: module.locale,
|
|
15
|
-
messages: { [module.locale]: module.messages
|
|
16
|
-
} as I18nOptions)
|
|
21
|
+
messages: { [module.locale]: module.messages },
|
|
22
|
+
} as unknown as I18nOptions)
|
|
17
23
|
|
|
18
24
|
const title = i18n.global.t('app.title')
|
|
19
25
|
|
|
20
26
|
expect(title).not.toContain('@')
|
|
21
27
|
expect(title).not.toBe('app.title')
|
|
22
28
|
})
|
|
29
|
+
|
|
30
|
+
it.each(modules)('translates shared table actions for $locale', (module) => {
|
|
31
|
+
const i18n = createI18n({
|
|
32
|
+
legacy: false,
|
|
33
|
+
locale: module.locale,
|
|
34
|
+
messages: { [module.locale]: module.messages },
|
|
35
|
+
} as unknown as I18nOptions)
|
|
36
|
+
expect(i18n.global.t('common.actions.approve')).not.toBe('common.actions.approve')
|
|
37
|
+
expect(i18n.global.t('common.actions.batchProcess')).not.toBe('common.actions.batchProcess')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('keeps every official language structurally complete and non-empty against zh-CN', () => {
|
|
41
|
+
for (const module of [zhCN, enUS, zhTW]) {
|
|
42
|
+
expect(validateLocaleShape(zhCN, module)).toEqual({
|
|
43
|
+
missing: [],
|
|
44
|
+
extra: [],
|
|
45
|
+
invalid: [],
|
|
46
|
+
})
|
|
47
|
+
expect(validateAdminLocaleMessages(zhCN, module)).toEqual({
|
|
48
|
+
missing: [],
|
|
49
|
+
extra: [],
|
|
50
|
+
invalid: [],
|
|
51
|
+
empty: [],
|
|
52
|
+
interpolation: [],
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('reports empty leaves and interpolation mismatches', () => {
|
|
58
|
+
expect(
|
|
59
|
+
validateAdminLocaleMessages(
|
|
60
|
+
{ nested: { description: 'Welcome, {name}' } },
|
|
61
|
+
{ nested: { description: ' ' } },
|
|
62
|
+
),
|
|
63
|
+
).toEqual({
|
|
64
|
+
missing: [],
|
|
65
|
+
extra: [],
|
|
66
|
+
invalid: [],
|
|
67
|
+
empty: ['nested.description'],
|
|
68
|
+
interpolation: ['nested.description'],
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('reports structural and leaf-type violations before interpolation checks', () => {
|
|
73
|
+
expect(
|
|
74
|
+
validateAdminLocaleMessages(
|
|
75
|
+
{ nested: { title: 'Title', count: '{count}' } },
|
|
76
|
+
{ nested: { title: 42, count: '{count} {extra}', extra: 'unexpected' } },
|
|
77
|
+
),
|
|
78
|
+
).toEqual({
|
|
79
|
+
missing: [],
|
|
80
|
+
extra: ['nested.extra'],
|
|
81
|
+
invalid: ['nested.title'],
|
|
82
|
+
empty: [],
|
|
83
|
+
interpolation: ['nested.count'],
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('preserves host namespaces while Admin messages take precedence', async () => {
|
|
88
|
+
const host = createI18n({
|
|
89
|
+
legacy: false,
|
|
90
|
+
locale: 'zh-CN',
|
|
91
|
+
messages: {
|
|
92
|
+
'zh-CN': {
|
|
93
|
+
host: { keep: 'host value', nested: { keep: 'nested host value' } },
|
|
94
|
+
app: { title: 'host title', hostOnly: 'retained', nested: { hostOnly: 'nested retained' } },
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
} as unknown as I18nOptions)
|
|
98
|
+
const { createAdminI18n } = await import('./index')
|
|
99
|
+
const runtime = createAdminI18n(host)
|
|
100
|
+
await runtime.language.ready
|
|
101
|
+
expect(host.global.t('host.keep')).toBe('host value')
|
|
102
|
+
expect(host.global.t('host.nested.keep')).toBe('nested host value')
|
|
103
|
+
expect(host.global.t('app.title')).toBe(zhCN.app.title)
|
|
104
|
+
expect(host.global.t('app.hostOnly')).toBe('retained')
|
|
105
|
+
expect(host.global.t('app.nested.hostOnly')).toBe('nested retained')
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it('uses an existing composition locale as the initial Admin locale', async () => {
|
|
109
|
+
const host = createI18n({
|
|
110
|
+
legacy: false,
|
|
111
|
+
locale: 'en-US',
|
|
112
|
+
messages: { 'en-US': { host: { keep: 'host value' } } },
|
|
113
|
+
} as unknown as I18nOptions)
|
|
114
|
+
const { createAdminI18n } = await import('./index')
|
|
115
|
+
const runtime = createAdminI18n(host)
|
|
116
|
+
await runtime.language.ready
|
|
117
|
+
|
|
118
|
+
expect(runtime.language.current.value).toBe('en-US')
|
|
119
|
+
expect(host.global.t('app.title')).toBe(enUS.app.title)
|
|
120
|
+
expect(host.global.t('host.keep')).toBe('host value')
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('rejects legacy-mode vue-i18n instances', async () => {
|
|
124
|
+
const { createAdminI18n } = await import('./index')
|
|
125
|
+
const legacy = createI18n(
|
|
126
|
+
{ legacy: true, locale: 'zh-CN', messages: { 'zh-CN': {} } } as unknown as I18nOptions,
|
|
127
|
+
)
|
|
128
|
+
expect(() => createAdminI18n(legacy)).toThrow(/Composition-mode/)
|
|
129
|
+
})
|
|
23
130
|
})
|