@campus-admin/locale 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 UnionSchool
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # @campus-admin/locale
2
+
3
+ 面向智慧校园后台的国际化运行时:词条管理、取词与切换、日期与数字格式化。
4
+
5
+ 组件库(`@campus-admin/ui`)与业务共用同一个语言实例:组件词条挂 `ca.*` 命名空间,
6
+ 业务词条放自己的根键(示例里是 `app.*` / `menu.*` / `page.*`)。
7
+
8
+ ## 安装
9
+
10
+ ```bash
11
+ pnpm add @campus-admin/locale
12
+ ```
13
+
14
+ ## 用法
15
+
16
+ ```ts
17
+ import { createLocale, installLocale, useLocale, setLocale } from '@campus-admin/locale'
18
+ import { createApp } from 'vue'
19
+
20
+ const app = createApp(App)
21
+
22
+ const locale = createLocale({
23
+ locale: 'zh-CN',
24
+ fallbackLocale: 'zh-CN',
25
+ messages: { 'zh-CN': zhCN, 'en-US': enUS }, // 业务词条,与内置 ca.* 深合并
26
+ })
27
+
28
+ installLocale(app, locale) // 之后 setLocale / useLocale 都指向这个实例
29
+ setLocale('en-US') // 切换:组件文案与业务文案一起变
30
+ ```
31
+
32
+ 组件内取词:
33
+
34
+ ```ts
35
+ const { t, te } = useLocale()
36
+
37
+ t('ca.pagination.total', { total: 12 }) // 组件词条
38
+ t('page.home.count', { total: 12 }) // 业务词条
39
+ te('menu.school-student') // 判断词条是否存在(后端文案兜底用)
40
+ ```
41
+
42
+ 日期与数字统一走 `Intl` 封装,不要在业务里拼「年 / 月 / 日」:
43
+
44
+ ```ts
45
+ import { formatDay, formatMonth, formatNumber, weekdayLabels } from '@campus-admin/locale'
46
+
47
+ formatMonth(new Date(2026, 8, 11), 'en-US') // September 2026
48
+ weekdayLabels('zh-CN') // ['周一', ...]
49
+ formatNumber(3286, 'en-US') // 3,286
50
+ ```
51
+
52
+ ## 约定
53
+
54
+ - `ca.*` 由组件库保留;业务要改写组件文案时只覆盖 `ca` 下的**叶子键**,不要覆盖父级路径(会整段静默失效)。
55
+ - 词条结构就是 vue-i18n 的 messages,已经用 vue-i18n 的项目不要再装第二个实例,把 `caMessages` 合并进自己的实例即可。
56
+ - 找不到词条时原样返回 key,开发环境会打一次 `[@campus-admin/locale] 缺少词条:xxx`。
57
+
58
+ 完整说明见仓库文档《Campus Admin 国际化使用指南》。
59
+
60
+ ## 版权
61
+
62
+ 使用本项目时请保留版权信息(MIT 许可要求随副本保留版权声明):
63
+
64
+ - 保留包内的 `LICENSE` 文件与版权声明;
65
+ - 保留页面页脚中的「Powered By 众校通 ®」与联系方式(示例用 `Copyright` 组件统一渲染);
66
+ - 二次分发或修改后的版本,请在显著位置保留同样的版权声明。
67
+
68
+ ---
69
+
70
+ Powered By 众校通 ®
@@ -0,0 +1,22 @@
1
+ /**
2
+ * 与语言相关的格式化。
3
+ *
4
+ * 统一走浏览器内置的 Intl,不再自己拼“年 / 月 / 日”,也不引第三方日期库:
5
+ * 同一份代码在 zh-CN 下输出「2026年9月」,在 en-US 下输出「September 2026」。
6
+ *
7
+ * 传入无法识别的语言标记时回退到运行环境默认语言,不抛异常。
8
+ */
9
+ /** 2026-09-07 是周一,用它推出七个星期标签 */
10
+ declare const BASE_MONDAY: Date;
11
+ /**
12
+ * 星期标签,按周一到周日返回七个值。
13
+ * style 为 short 时是「周一 / Mon」,narrow 时是「一 / M」。
14
+ */
15
+ export declare function weekdayLabels(locale: string, style?: 'short' | 'narrow'): string[];
16
+ /** 年月:2026年9月 / September 2026 */
17
+ export declare function formatMonth(date: Date, locale: string): string;
18
+ /** 月日:9月11日 / September 11 */
19
+ export declare function formatDay(date: Date, locale: string): string;
20
+ /** 数字与货币:统一走 Intl.NumberFormat,保证千分位与货币符号跟随语言 */
21
+ export declare function formatNumber(value: number, locale: string, options?: Intl.NumberFormatOptions): string;
22
+ export { BASE_MONDAY };
@@ -0,0 +1,50 @@
1
+ import type { App, InjectionKey, Ref } from 'vue';
2
+ import type { CaLocale, CaLocaleOptions, LocaleMessages, LocaleMessageMap } from './types';
3
+ export * from './format';
4
+ export type { CaLocale, CaLocaleConfig, CaLocaleOptions, LocaleMessages, LocaleMessageMap, TranslateFn } from './types';
5
+ /** 默认语言 */
6
+ export declare const DEFAULT_LOCALE = "zh-CN";
7
+ /** 内置支持的语言,业务可以在此基础上追加 */
8
+ export declare const AVAILABLE_LOCALES: readonly ["zh-CN", "en-US"];
9
+ /**
10
+ * 组件库内置词条,按语言分组。
11
+ * 结构与 vue-i18n 的 messages 一致,业务可以直接 mergeLocaleMessage 合并。
12
+ */
13
+ export declare const caMessages: LocaleMessageMap;
14
+ /** 语言实例的注入键,业务替换实现时使用 */
15
+ export declare const CA_LOCALE_KEY: InjectionKey<CaLocale>;
16
+ /**
17
+ * 按 'a.b.c' 取词条,取到非字符串节点时视为未命中。
18
+ * 包内需要“取默认语言文案”的地方(例如考勤状态词典的兜底 label)也用它。
19
+ */
20
+ export declare function lookupMessage(messages: LocaleMessages, key: string): string | undefined;
21
+ /**
22
+ * 取内置默认语言(zh-CN)的某条文案。
23
+ * 给不接入国际化的场景兜底用,例如考勤状态词典里的 label。
24
+ */
25
+ export declare function defaultMessage(key: string): string | undefined;
26
+ /**
27
+ * 创建语言实例。
28
+ * 内置 zh-CN / en-US 词条,options.messages 里的业务词条深合并在其上。
29
+ */
30
+ export declare function createLocale(options?: CaLocaleOptions): CaLocale;
31
+ /**
32
+ * 把语言实例注入到应用,并设为当前实例。
33
+ * campus-admin 与 CampusUI 插件在 install 时调用。
34
+ */
35
+ export declare function installLocale(app: App, locale: CaLocale): void;
36
+ /** 当前语言实例,非 setup 场景(路由、请求拦截器)使用 */
37
+ export declare function getCurrentLocale(): CaLocale;
38
+ /** 切换当前实例的语言 */
39
+ export declare function setLocale(locale: string): void;
40
+ /** 当前语言 */
41
+ export declare function getLocale(): string;
42
+ /** 当前语言的响应式引用,需要跟随语言变化时使用 */
43
+ export declare function useLocaleRef(): Ref<string>;
44
+ /**
45
+ * 组件内取词。返回当前应用的语言实例,注入不到时回退到内置实例。
46
+ * 必须在 setup 中调用(内部使用 inject)。
47
+ */
48
+ export declare function useLocale(): CaLocale;
49
+ /** 仅 setup 中可用:向子组件提供语言实例(一般由应用安装时统一处理) */
50
+ export declare function provideLocale(locale: CaLocale): void;
package/dist/index.js ADDED
@@ -0,0 +1,331 @@
1
+ import { inject as e, provide as t, ref as n } from "vue";
2
+ //#region src/lang/zh-CN.ts
3
+ var r = { ca: {
4
+ common: {
5
+ loading: "加载中…",
6
+ close: "关闭",
7
+ clear: "清空",
8
+ remove: "移除",
9
+ confirm: "确定",
10
+ cancel: "取消",
11
+ processing: "处理中…",
12
+ back: "返回",
13
+ expand: "展开",
14
+ collapse: "收起"
15
+ },
16
+ table: { empty: "暂无数据" },
17
+ pagination: {
18
+ label: "分页导航",
19
+ total: "共 {total} 条",
20
+ prev: "上一页",
21
+ next: "下一页"
22
+ },
23
+ toast: { close: "关闭消息" },
24
+ empty: { title: "暂无数据" },
25
+ copyright: {
26
+ line: "© {year} {name}",
27
+ poweredBy: "Powered By 众校通 ®",
28
+ poweredByPartner: "Powered By {partner} | 众校通 ®"
29
+ },
30
+ slogan: { default: "为教育多做一点" },
31
+ select: {
32
+ placeholder: "请选择",
33
+ empty: "暂无选项"
34
+ },
35
+ breadcrumb: { label: "面包屑导航" },
36
+ searchForm: {
37
+ search: "查询",
38
+ reset: "重置",
39
+ searching: "查询中…"
40
+ },
41
+ classTree: {
42
+ searchPlaceholder: "搜索年级或班级",
43
+ searchLabel: "搜索班级",
44
+ empty: "没有匹配的年级或班级"
45
+ },
46
+ sideMenu: { label: "导航菜单" },
47
+ studentPicker: {
48
+ placeholder: "搜索姓名、学号或班级",
49
+ searchLabel: "搜索学生",
50
+ selected: "已选 {count}",
51
+ studentNo: "学号 {no}",
52
+ emptyTitle: "没有匹配的学生",
53
+ emptyDescription: "换个关键词试试"
54
+ },
55
+ attendance: {
56
+ normal: "正常",
57
+ late: "迟到",
58
+ leave: "请假",
59
+ absent: "缺勤",
60
+ early: "早退",
61
+ unknown: "未打卡"
62
+ },
63
+ timetable: {
64
+ tabsLabel: "课表类型",
65
+ personal: "个人课表",
66
+ class: "班级课表",
67
+ prevWeek: "上一周",
68
+ nextWeek: "下一周",
69
+ thisWeek: "本周",
70
+ week: "第 {week} 周",
71
+ personalSubtitle: "林老师 · 语文",
72
+ classSubtitle: "班级教学安排",
73
+ term: "2026–2027 学年 · 第一学期",
74
+ classLabel: "选择班级",
75
+ weekCount: "本周 {count} 节课",
76
+ caption: "{range} 教学课表",
77
+ periodHeader: "时段 / 节次",
78
+ hint: "点击课程查看详情",
79
+ detail: "{date} {time},授课教师:林老师。请提前准备教学资料。"
80
+ },
81
+ agenda: {
82
+ title: "日程安排",
83
+ backToToday: "回到今天",
84
+ count: "{count} 项日程",
85
+ prevWeek: "日程上一周",
86
+ nextWeek: "日程下一周",
87
+ dayLabel: "{date}日程",
88
+ detail: "详情",
89
+ emptyTitle: "当天暂无日程",
90
+ emptyDescription: "可以查看其他日期的安排",
91
+ emptySearchTitle: "未找到相关日程",
92
+ emptySearchDescription: "试试其他关键词",
93
+ footer: "所有日程均为本地演示数据",
94
+ doneState: "此日程已完成。",
95
+ todoState: "请按时参加并准备相关材料。",
96
+ describe: "{date} {time},地点:{location}。{state}"
97
+ }
98
+ } }, i = { ca: {
99
+ common: {
100
+ loading: "Loading…",
101
+ close: "Close",
102
+ clear: "Clear",
103
+ remove: "Remove",
104
+ confirm: "OK",
105
+ cancel: "Cancel",
106
+ processing: "Processing…",
107
+ back: "Back",
108
+ expand: "Expand",
109
+ collapse: "Collapse"
110
+ },
111
+ table: { empty: "No data" },
112
+ pagination: {
113
+ label: "Pagination",
114
+ total: "{total} items",
115
+ prev: "Previous page",
116
+ next: "Next page"
117
+ },
118
+ toast: { close: "Close message" },
119
+ empty: { title: "No data" },
120
+ copyright: {
121
+ line: "© {year} {name}",
122
+ poweredBy: "Powered By 众校通 ®",
123
+ poweredByPartner: "Powered By {partner} | 众校通 ®"
124
+ },
125
+ slogan: { default: "Do a little more for education" },
126
+ select: {
127
+ placeholder: "Please select",
128
+ empty: "No options"
129
+ },
130
+ breadcrumb: { label: "Breadcrumb" },
131
+ searchForm: {
132
+ search: "Search",
133
+ reset: "Reset",
134
+ searching: "Searching…"
135
+ },
136
+ classTree: {
137
+ searchPlaceholder: "Search grade or class",
138
+ searchLabel: "Search class",
139
+ empty: "No matching grade or class"
140
+ },
141
+ sideMenu: { label: "Navigation" },
142
+ studentPicker: {
143
+ placeholder: "Search name, student no. or class",
144
+ searchLabel: "Search students",
145
+ selected: "{count} selected",
146
+ studentNo: "No. {no}",
147
+ emptyTitle: "No matching students",
148
+ emptyDescription: "Try another keyword"
149
+ },
150
+ attendance: {
151
+ normal: "Present",
152
+ late: "Late",
153
+ leave: "On leave",
154
+ absent: "Absent",
155
+ early: "Left early",
156
+ unknown: "Not checked in"
157
+ },
158
+ timetable: {
159
+ tabsLabel: "Timetable type",
160
+ personal: "My timetable",
161
+ class: "Class timetable",
162
+ prevWeek: "Previous week",
163
+ nextWeek: "Next week",
164
+ thisWeek: "This week",
165
+ week: "Week {week}",
166
+ personalSubtitle: "Ms. Lin · Chinese",
167
+ classSubtitle: "Class teaching plan",
168
+ term: "2026–2027 · First semester",
169
+ classLabel: "Select class",
170
+ weekCount: "{count} lessons this week",
171
+ caption: "{range} timetable",
172
+ periodHeader: "Period",
173
+ hint: "Click a lesson for details",
174
+ detail: "{date} {time}. Teacher: Ms. Lin. Please prepare your materials in advance."
175
+ },
176
+ agenda: {
177
+ title: "Schedule",
178
+ backToToday: "Back to today",
179
+ count: "{count} items",
180
+ prevWeek: "Previous week",
181
+ nextWeek: "Next week",
182
+ dayLabel: "Schedule for {date}",
183
+ detail: "Details",
184
+ emptyTitle: "No schedule for this day",
185
+ emptyDescription: "Pick another date to see its schedule",
186
+ emptySearchTitle: "No matching schedule",
187
+ emptySearchDescription: "Try another keyword",
188
+ footer: "All schedules are local demo data",
189
+ doneState: "This item is done.",
190
+ todoState: "Please attend on time and prepare the relevant materials.",
191
+ describe: "{date} {time}, location: {location}. {state}"
192
+ }
193
+ } }, a = new Date(2026, 8, 7), o = /* @__PURE__ */ new Map();
194
+ function s(e, t) {
195
+ let n = `${e}|${JSON.stringify(t)}`, r = o.get(n);
196
+ if (r) return r;
197
+ let i;
198
+ try {
199
+ i = new Intl.DateTimeFormat(e, t);
200
+ } catch {
201
+ i = new Intl.DateTimeFormat(void 0, t);
202
+ }
203
+ return o.set(n, i), i;
204
+ }
205
+ function c(e, t = "short") {
206
+ let n = s(e, { weekday: t });
207
+ return Array.from({ length: 7 }, (e, t) => n.format(new Date(2026, 8, 7 + t)));
208
+ }
209
+ function l(e, t) {
210
+ return s(t, {
211
+ year: "numeric",
212
+ month: "long"
213
+ }).format(e);
214
+ }
215
+ function u(e, t) {
216
+ return s(t, {
217
+ month: "long",
218
+ day: "numeric"
219
+ }).format(e);
220
+ }
221
+ function d(e, t, n) {
222
+ try {
223
+ return new Intl.NumberFormat(t, n).format(e);
224
+ } catch {
225
+ return new Intl.NumberFormat(void 0, n).format(e);
226
+ }
227
+ }
228
+ //#endregion
229
+ //#region src/index.ts
230
+ var f = "zh-CN", p = ["zh-CN", "en-US"], m = {
231
+ "zh-CN": r,
232
+ "en-US": i
233
+ }, h = Symbol("ca-locale");
234
+ function g(e) {
235
+ let t = {};
236
+ return Object.entries(e).forEach(([e, n]) => {
237
+ t[e] = typeof n == "string" ? n : g(n);
238
+ }), t;
239
+ }
240
+ function _(e, t) {
241
+ let n = g(e);
242
+ return Object.entries(t).forEach(([e, t]) => {
243
+ let r = n[e];
244
+ n[e] = typeof t == "string" || typeof r != "object" ? t : _(r, t);
245
+ }), n;
246
+ }
247
+ function v(e, t) {
248
+ let n = e;
249
+ for (let e of t.split(".")) {
250
+ if (typeof n != "object") return;
251
+ n = n[e];
252
+ }
253
+ return typeof n == "string" ? n : void 0;
254
+ }
255
+ function y(e) {
256
+ return v(m["zh-CN"] ?? {}, e);
257
+ }
258
+ function b(e, t) {
259
+ return t ? e.replace(/\{(\w+)\}/g, (e, n) => n in t ? String(t[n]) : e) : e;
260
+ }
261
+ function x(e, t, n, r) {
262
+ let i = [
263
+ t,
264
+ t.split("-")[0],
265
+ n,
266
+ n.split("-")[0]
267
+ ];
268
+ for (let t of i) {
269
+ if (!t) continue;
270
+ let n = v(e[t] ?? {}, r);
271
+ if (n !== void 0) return n;
272
+ }
273
+ }
274
+ function S(e = {}) {
275
+ let t = n(e.locale ?? "zh-CN"), r = n(e.fallbackLocale ?? "zh-CN"), i = n(C(m, e.messages));
276
+ return {
277
+ locale: t,
278
+ fallbackLocale: r,
279
+ t: (e, n) => {
280
+ let a = x(i.value, t.value, r.value, e);
281
+ return a === void 0 ? e : b(a, n);
282
+ },
283
+ te(e) {
284
+ return x(i.value, t.value, r.value, e) !== void 0;
285
+ },
286
+ setLocale(e) {
287
+ t.value = e;
288
+ },
289
+ mergeMessages(e, t) {
290
+ i.value = {
291
+ ...i.value,
292
+ [e]: _(i.value[e] ?? {}, t)
293
+ };
294
+ },
295
+ getMessages(e) {
296
+ return g(i.value[e] ?? {});
297
+ }
298
+ };
299
+ }
300
+ function C(e, t) {
301
+ let n = {};
302
+ return Object.keys(e).forEach((t) => {
303
+ n[t] = g(e[t]);
304
+ }), Object.entries(t ?? {}).forEach(([e, t]) => {
305
+ n[e] = _(n[e] ?? {}, t);
306
+ }), n;
307
+ }
308
+ var w = S();
309
+ function T(e, t) {
310
+ e.provide(h, t), w = t;
311
+ }
312
+ function E() {
313
+ return w;
314
+ }
315
+ function D(e) {
316
+ w.setLocale(e);
317
+ }
318
+ function O() {
319
+ return w.locale.value;
320
+ }
321
+ function k() {
322
+ return w.locale;
323
+ }
324
+ function A() {
325
+ return e(h, w);
326
+ }
327
+ function j(e) {
328
+ t(h, e);
329
+ }
330
+ //#endregion
331
+ export { p as AVAILABLE_LOCALES, a as BASE_MONDAY, h as CA_LOCALE_KEY, f as DEFAULT_LOCALE, m as caMessages, S as createLocale, y as defaultMessage, u as formatDay, l as formatMonth, d as formatNumber, E as getCurrentLocale, O as getLocale, T as installLocale, v as lookupMessage, j as provideLocale, D as setLocale, A as useLocale, k as useLocaleRef, c as weekdayLabels };
@@ -0,0 +1 @@
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("vue")):typeof define==`function`&&define.amd?define([`exports`,`vue`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.CampusLocale={},e.Vue))})(this,function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var n={ca:{common:{loading:`加载中…`,close:`关闭`,clear:`清空`,remove:`移除`,confirm:`确定`,cancel:`取消`,processing:`处理中…`,back:`返回`,expand:`展开`,collapse:`收起`},table:{empty:`暂无数据`},pagination:{label:`分页导航`,total:`共 {total} 条`,prev:`上一页`,next:`下一页`},toast:{close:`关闭消息`},empty:{title:`暂无数据`},copyright:{line:`© {year} {name}`,poweredBy:`Powered By 众校通 ®`,poweredByPartner:`Powered By {partner} | 众校通 ®`},slogan:{default:`为教育多做一点`},select:{placeholder:`请选择`,empty:`暂无选项`},breadcrumb:{label:`面包屑导航`},searchForm:{search:`查询`,reset:`重置`,searching:`查询中…`},classTree:{searchPlaceholder:`搜索年级或班级`,searchLabel:`搜索班级`,empty:`没有匹配的年级或班级`},sideMenu:{label:`导航菜单`},studentPicker:{placeholder:`搜索姓名、学号或班级`,searchLabel:`搜索学生`,selected:`已选 {count}`,studentNo:`学号 {no}`,emptyTitle:`没有匹配的学生`,emptyDescription:`换个关键词试试`},attendance:{normal:`正常`,late:`迟到`,leave:`请假`,absent:`缺勤`,early:`早退`,unknown:`未打卡`},timetable:{tabsLabel:`课表类型`,personal:`个人课表`,class:`班级课表`,prevWeek:`上一周`,nextWeek:`下一周`,thisWeek:`本周`,week:`第 {week} 周`,personalSubtitle:`林老师 · 语文`,classSubtitle:`班级教学安排`,term:`2026–2027 学年 · 第一学期`,classLabel:`选择班级`,weekCount:`本周 {count} 节课`,caption:`{range} 教学课表`,periodHeader:`时段 / 节次`,hint:`点击课程查看详情`,detail:`{date} {time},授课教师:林老师。请提前准备教学资料。`},agenda:{title:`日程安排`,backToToday:`回到今天`,count:`{count} 项日程`,prevWeek:`日程上一周`,nextWeek:`日程下一周`,dayLabel:`{date}日程`,detail:`详情`,emptyTitle:`当天暂无日程`,emptyDescription:`可以查看其他日期的安排`,emptySearchTitle:`未找到相关日程`,emptySearchDescription:`试试其他关键词`,footer:`所有日程均为本地演示数据`,doneState:`此日程已完成。`,todoState:`请按时参加并准备相关材料。`,describe:`{date} {time},地点:{location}。{state}`}}},r={ca:{common:{loading:`Loading…`,close:`Close`,clear:`Clear`,remove:`Remove`,confirm:`OK`,cancel:`Cancel`,processing:`Processing…`,back:`Back`,expand:`Expand`,collapse:`Collapse`},table:{empty:`No data`},pagination:{label:`Pagination`,total:`{total} items`,prev:`Previous page`,next:`Next page`},toast:{close:`Close message`},empty:{title:`No data`},copyright:{line:`© {year} {name}`,poweredBy:`Powered By 众校通 ®`,poweredByPartner:`Powered By {partner} | 众校通 ®`},slogan:{default:`Do a little more for education`},select:{placeholder:`Please select`,empty:`No options`},breadcrumb:{label:`Breadcrumb`},searchForm:{search:`Search`,reset:`Reset`,searching:`Searching…`},classTree:{searchPlaceholder:`Search grade or class`,searchLabel:`Search class`,empty:`No matching grade or class`},sideMenu:{label:`Navigation`},studentPicker:{placeholder:`Search name, student no. or class`,searchLabel:`Search students`,selected:`{count} selected`,studentNo:`No. {no}`,emptyTitle:`No matching students`,emptyDescription:`Try another keyword`},attendance:{normal:`Present`,late:`Late`,leave:`On leave`,absent:`Absent`,early:`Left early`,unknown:`Not checked in`},timetable:{tabsLabel:`Timetable type`,personal:`My timetable`,class:`Class timetable`,prevWeek:`Previous week`,nextWeek:`Next week`,thisWeek:`This week`,week:`Week {week}`,personalSubtitle:`Ms. Lin · Chinese`,classSubtitle:`Class teaching plan`,term:`2026–2027 · First semester`,classLabel:`Select class`,weekCount:`{count} lessons this week`,caption:`{range} timetable`,periodHeader:`Period`,hint:`Click a lesson for details`,detail:`{date} {time}. Teacher: Ms. Lin. Please prepare your materials in advance.`},agenda:{title:`Schedule`,backToToday:`Back to today`,count:`{count} items`,prevWeek:`Previous week`,nextWeek:`Next week`,dayLabel:`Schedule for {date}`,detail:`Details`,emptyTitle:`No schedule for this day`,emptyDescription:`Pick another date to see its schedule`,emptySearchTitle:`No matching schedule`,emptySearchDescription:`Try another keyword`,footer:`All schedules are local demo data`,doneState:`This item is done.`,todoState:`Please attend on time and prepare the relevant materials.`,describe:`{date} {time}, location: {location}. {state}`}}},i=new Date(2026,8,7),a=new Map;function o(e,t){let n=`${e}|${JSON.stringify(t)}`,r=a.get(n);if(r)return r;let i;try{i=new Intl.DateTimeFormat(e,t)}catch{i=new Intl.DateTimeFormat(void 0,t)}return a.set(n,i),i}function s(e,t=`short`){let n=o(e,{weekday:t});return Array.from({length:7},(e,t)=>n.format(new Date(2026,8,7+t)))}function c(e,t){return o(t,{year:`numeric`,month:`long`}).format(e)}function l(e,t){return o(t,{month:`long`,day:`numeric`}).format(e)}function u(e,t,n){try{return new Intl.NumberFormat(t,n).format(e)}catch{return new Intl.NumberFormat(void 0,n).format(e)}}var d=`zh-CN`,f=[`zh-CN`,`en-US`],p={"zh-CN":n,"en-US":r},m=Symbol(`ca-locale`);function h(e){let t={};return Object.entries(e).forEach(([e,n])=>{t[e]=typeof n==`string`?n:h(n)}),t}function g(e,t){let n=h(e);return Object.entries(t).forEach(([e,t])=>{let r=n[e];n[e]=typeof t==`string`||typeof r!=`object`?t:g(r,t)}),n}function _(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`)return;n=n[e]}return typeof n==`string`?n:void 0}function v(e){return _(p[`zh-CN`]??{},e)}function y(e,t){return t?e.replace(/\{(\w+)\}/g,(e,n)=>n in t?String(t[n]):e):e}function b(e,t,n,r){let i=[t,t.split(`-`)[0],n,n.split(`-`)[0]];for(let t of i){if(!t)continue;let n=_(e[t]??{},r);if(n!==void 0)return n}}function x(e={}){let n=(0,t.ref)(e.locale??`zh-CN`),r=(0,t.ref)(e.fallbackLocale??`zh-CN`),i=(0,t.ref)(S(p,e.messages));return{locale:n,fallbackLocale:r,t:(e,t)=>{let a=b(i.value,n.value,r.value,e);return a===void 0?e:y(a,t)},te(e){return b(i.value,n.value,r.value,e)!==void 0},setLocale(e){n.value=e},mergeMessages(e,t){i.value={...i.value,[e]:g(i.value[e]??{},t)}},getMessages(e){return h(i.value[e]??{})}}}function S(e,t){let n={};return Object.keys(e).forEach(t=>{n[t]=h(e[t])}),Object.entries(t??{}).forEach(([e,t])=>{n[e]=g(n[e]??{},t)}),n}var C=x();function w(e,t){e.provide(m,t),C=t}function T(){return C}function E(e){C.setLocale(e)}function D(){return C.locale.value}function O(){return C.locale}function k(){return(0,t.inject)(m,C)}function A(e){(0,t.provide)(m,e)}e.AVAILABLE_LOCALES=f,e.BASE_MONDAY=i,e.CA_LOCALE_KEY=m,e.DEFAULT_LOCALE=d,e.caMessages=p,e.createLocale=x,e.defaultMessage=v,e.formatDay=l,e.formatMonth=c,e.formatNumber=u,e.getCurrentLocale=T,e.getLocale=D,e.installLocale=w,e.lookupMessage=_,e.provideLocale=A,e.setLocale=E,e.useLocale=k,e.useLocaleRef=O,e.weekdayLabels=s});
@@ -0,0 +1,9 @@
1
+ /**
2
+ * 组件库内置词条(英文)。
3
+ *
4
+ * 与 zh-CN 的键一一对应,缺任何一条都会在英文界面下回退成中文或显示 key 本身。
5
+ * 新增组件文案时两份语言包必须同时补,缺失由 packages/ui 的类型检查兜底。
6
+ */
7
+ import type { LocaleMessages } from '../types';
8
+ declare const enUS: LocaleMessages;
9
+ export default enUS;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 组件库内置词条(简体中文,默认语言)。
3
+ *
4
+ * 约定:
5
+ * 1. 所有键都挂在 ca 命名空间下,ca 由组件库保留;业务要改写组件文案时
6
+ * 只覆盖 ca 下的叶子键,不要覆盖父级路径(父级覆盖会让整棵子树静默失效);
7
+ * 2. 结构就是 vue-i18n 的 messages,业务可以直接 mergeLocaleMessage('zh-CN', caMessagesZhCN);
8
+ * 3. 只放“组件自身的界面文案”。班级名、科目、节次、日程条目这类业务数据
9
+ * 不在这里,真实项目由接口下发(见各组件 data.ts 的说明)。
10
+ */
11
+ import type { LocaleMessages } from '../types';
12
+ declare const zhCN: LocaleMessages;
13
+ export default zhCN;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * 国际化类型契约。
3
+ *
4
+ * 结构与 vue-i18n 的 messages 保持一致(嵌套对象、{name} 插值),
5
+ * 因此内置词条可以直接交给业务侧 mergeLocaleMessage,不需要转换格式。
6
+ */
7
+ import type { Ref } from 'vue';
8
+ /** 词条树:键为语义名,值为字符串或下一层节点 */
9
+ export interface LocaleMessages {
10
+ [key: string]: string | LocaleMessages;
11
+ }
12
+ /** 词条集合:按语言标记分组,例如 { 'zh-CN': {...}, 'en-US': {...} } */
13
+ export type LocaleMessageMap = Record<string, LocaleMessages>;
14
+ /**
15
+ * 取词函数。
16
+ * 签名与 vue-i18n 的 t() 对齐:第二个参数是插值变量;
17
+ * 找不到词条时原样返回 key,便于在页面上直接看出漏翻。
18
+ */
19
+ export type TranslateFn = (key: string, params?: Record<string, string | number>) => string;
20
+ export interface CaLocaleOptions {
21
+ /** 当前语言,默认 zh-CN */
22
+ locale?: string;
23
+ /** 兜底语言,当前语言缺词条时使用,默认 zh-CN */
24
+ fallbackLocale?: string;
25
+ /** 业务词条,按语言分组追加到内置词条之上(深合并) */
26
+ messages?: LocaleMessageMap;
27
+ }
28
+ /** 语言实例:组件与业务都通过它取词 */
29
+ export interface CaLocale {
30
+ /** 当前语言,可写,写入即切换 */
31
+ locale: Ref<string>;
32
+ /** 兜底语言 */
33
+ fallbackLocale: Ref<string>;
34
+ /** 取词 */
35
+ t: TranslateFn;
36
+ /**
37
+ * 词条是否存在,签名与 vue-i18n 的 te() 一致。
38
+ * 用于「有词条就用词条,没有就用后端下发的默认文案」这类场景。
39
+ */
40
+ te: (key: string) => boolean;
41
+ /** 切换语言 */
42
+ setLocale: (locale: string) => void;
43
+ /** 追加词条(深合并,同路径覆盖),用于登录后下发业务词条 */
44
+ mergeMessages: (locale: string, messages: LocaleMessages) => void;
45
+ /** 读取某语言的原始词条,便于业务侧合并进 vue-i18n */
46
+ getMessages: (locale: string) => LocaleMessages;
47
+ }
48
+ /**
49
+ * 组件库在应用配置里的国际化字段。
50
+ * 业务这样交给框架(见 examples/admin):
51
+ * createCampusAdmin({ config: { locale: { locale: 'zh-CN', messages: {...} } } })
52
+ */
53
+ export interface CaLocaleConfig extends CaLocaleOptions {
54
+ }
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@campus-admin/locale",
3
+ "version": "1.0.0",
4
+ "description": "面向智慧校园后台的国际化运行时:词条、取词切换与日期数字格式化",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "UnionSchool",
8
+ "homepage": "https://campus.zhongxiaotong.com",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/UnionSchool/campus-admin.git",
12
+ "directory": "packages/locale"
13
+ },
14
+ "keywords": [
15
+ "vue",
16
+ "vue3",
17
+ "i18n",
18
+ "locale",
19
+ "campus",
20
+ "admin"
21
+ ],
22
+ "sideEffects": false,
23
+ "files": [
24
+ "LICENSE",
25
+ "dist",
26
+ "README.md"
27
+ ],
28
+ "main": "./dist/index.umd.cjs",
29
+ "module": "./dist/index.js",
30
+ "types": "./dist/index.d.ts",
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/index.d.ts",
34
+ "import": "./dist/index.js",
35
+ "require": "./dist/index.umd.cjs",
36
+ "source": "./src/index.ts"
37
+ }
38
+ },
39
+ "publishConfig": {
40
+ "access": "public",
41
+ "provenance": true
42
+ },
43
+ "engines": {
44
+ "node": ">=20.19.0"
45
+ },
46
+ "peerDependencies": {
47
+ "vue": "^3.5.42"
48
+ },
49
+ "devDependencies": {
50
+ "typescript": "^5.9.3",
51
+ "vite": "^8.3.0",
52
+ "vue": "^3.5.42"
53
+ },
54
+ "scripts": {
55
+ "typecheck": "tsc --noEmit -p tsconfig.json",
56
+ "build": "node ../../scripts/clean.mjs dist:packages/locale && tsc --declaration --emitDeclarationOnly -p tsconfig.build.json && vite build"
57
+ }
58
+ }