@zc-ui/locale 0.0.1

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) 2024 ZC UI
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/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("vue");function t(e,n=``){let r={};for(let[i,a]of Object.entries(e)){let e=n?`${n}.${i}`:i;typeof a==`object`&&a&&!Array.isArray(a)?Object.assign(r,t(a,e)):r[e]=String(a)}return r}function n(e,t){return t?e.replace(/\{(\w+)\}/g,(e,n)=>n in t?String(t[n]):e):e}var r={"common.confirm":`确定`,"common.cancel":`取消`,"common.loading":`加载中...`,"common.empty":`暂无数据`,"common.ok":`确定`,"common.save":`保存`,"common.delete":`删除`,"common.close":`关闭`,"zc.pagination.total":`共 {total} 条`,"zc.pagination.goto":`前往`,"zc.pagination.pageClassifier":`页`,"zc.empty.description":`暂无数据`,"zc.select.placeholder":`请选择`,"zc.select.noData":`暂无数据`,"zc.select.noMatch":`无匹配数据`,"zc.timePicker.placeholder":`请选择时间`,"zc.timePicker.startPlaceholder":`开始时间`,"zc.timePicker.endPlaceholder":`结束时间`,"zc.timePicker.rangeSeparator":`至`,"zc.autoComplete.placeholder":`请输入`,"zc.autoComplete.noData":`暂无数据`,"zc.autoComplete.searching":`搜索中...`,"zc.treeSelect.placeholder":`请选择`,"zc.treeSelect.searchPlaceholder":`搜索`,"zc.treeSelect.noData":`暂无数据`,"zc.cascader.placeholder":`请选择`,"zc.carousel.prev":`上一张`,"zc.carousel.next":`下一张`,"zc.carousel.indicator":`切换到第 {index} 张`,"zc.alert.close":`关闭`,"zc.backtop.backToTop":`返回顶部`,"zc.datePicker.placeholder":`请选择日期`,"zc.datePicker.startPlaceholder":`开始日期`,"zc.datePicker.endPlaceholder":`结束日期`,"zc.datePicker.year":`年`,"zc.datePicker.weekdays.sun":`日`,"zc.datePicker.weekdays.mon":`一`,"zc.datePicker.weekdays.tue":`二`,"zc.datePicker.weekdays.wed":`三`,"zc.datePicker.weekdays.thu":`四`,"zc.datePicker.weekdays.fri":`五`,"zc.datePicker.weekdays.sat":`六`,"zc.datePicker.months.jan":`一月`,"zc.datePicker.months.feb":`二月`,"zc.datePicker.months.mar":`三月`,"zc.datePicker.months.apr":`四月`,"zc.datePicker.months.may":`五月`,"zc.datePicker.months.jun":`六月`,"zc.datePicker.months.jul":`七月`,"zc.datePicker.months.aug":`八月`,"zc.datePicker.months.sep":`九月`,"zc.datePicker.months.oct":`十月`,"zc.datePicker.months.nov":`十一月`,"zc.datePicker.months.dec":`十二月`,"zc.mention.placeholder":`请输入内容`,"zc.upload.dragTip":`将文件拖到此处,或`,"zc.upload.clickToUpload":`点击上传`,"zc.form.required":`该字段为必填项`,"zc.form.min":`长度不能少于 {min}`,"zc.form.max":`长度不能超过 {max}`,"zc.form.pattern":`格式不正确`,"zc.form.validateFailed":`校验失败`,"zc.image.preview":`图片预览`,"zc.image.closePreview":`关闭预览`,"zc.image.zoomIn":`放大`,"zc.image.zoomOut":`缩小`,"zc.image.rotateLeft":`向左旋转`,"zc.image.rotateRight":`向右旋转`,"zc.rate.texts.1":`极差`,"zc.rate.texts.2":`失望`,"zc.rate.texts.3":`一般`,"zc.rate.texts.4":`满意`,"zc.rate.texts.5":`惊喜`,"zc.transfer.titleLeft":`列表 1`,"zc.transfer.titleRight":`列表 2`,"zc.transfer.filterPlaceholder":`请输入搜索内容`,"zc.transfer.noData":`暂无数据`,"zc.table.emptyText":`暂无数据`,"zc.tag.close":`移除标签`},i={"common.confirm":`Confirm`,"common.cancel":`Cancel`,"common.loading":`Loading...`,"common.empty":`No data`,"common.ok":`OK`,"common.save":`Save`,"common.delete":`Delete`,"common.close":`Close`,"zc.pagination.total":`Total {total}`,"zc.pagination.goto":`Go to`,"zc.pagination.pageClassifier":``,"zc.pagination.label":`Pagination`,"zc.empty.description":`No Data`,"zc.select.placeholder":`Please select`,"zc.select.noData":`No data`,"zc.select.noMatch":`No matching data`,"zc.timePicker.placeholder":`Select time`,"zc.timePicker.startPlaceholder":`Start time`,"zc.timePicker.endPlaceholder":`End time`,"zc.timePicker.rangeSeparator":`To`,"zc.autoComplete.placeholder":`Please input`,"zc.autoComplete.noData":`No data`,"zc.autoComplete.searching":`Searching...`,"zc.treeSelect.placeholder":`Please select`,"zc.treeSelect.searchPlaceholder":`Search`,"zc.treeSelect.noData":`No data`,"zc.cascader.placeholder":`Please select`,"zc.carousel.prev":`Previous`,"zc.carousel.next":`Next`,"zc.carousel.indicator":`Go to slide {index}`,"zc.alert.close":`Close`,"zc.backtop.backToTop":`Back to top`,"zc.datePicker.placeholder":`Select date`,"zc.datePicker.startPlaceholder":`Start date`,"zc.datePicker.endPlaceholder":`End date`,"zc.datePicker.year":``,"zc.datePicker.weekdays.sun":`Su`,"zc.datePicker.weekdays.mon":`Mo`,"zc.datePicker.weekdays.tue":`Tu`,"zc.datePicker.weekdays.wed":`We`,"zc.datePicker.weekdays.thu":`Th`,"zc.datePicker.weekdays.fri":`Fr`,"zc.datePicker.weekdays.sat":`Sa`,"zc.datePicker.months.jan":`January`,"zc.datePicker.months.feb":`February`,"zc.datePicker.months.mar":`March`,"zc.datePicker.months.apr":`April`,"zc.datePicker.months.may":`May`,"zc.datePicker.months.jun":`June`,"zc.datePicker.months.jul":`July`,"zc.datePicker.months.aug":`August`,"zc.datePicker.months.sep":`September`,"zc.datePicker.months.oct":`October`,"zc.datePicker.months.nov":`November`,"zc.datePicker.months.dec":`December`,"zc.mention.placeholder":`Please enter content`,"zc.upload.dragTip":`Drop files here, or `,"zc.upload.clickToUpload":`click to upload`,"zc.form.required":`This field is required`,"zc.form.min":`Length cannot be less than {min}`,"zc.form.max":`Length cannot be greater than {max}`,"zc.form.pattern":`Invalid format`,"zc.form.validateFailed":`Validation failed`,"zc.image.preview":`Image Preview`,"zc.image.closePreview":`Close preview`,"zc.image.zoomIn":`Zoom In`,"zc.image.zoomOut":`Zoom Out`,"zc.image.rotateLeft":`Rotate Left`,"zc.image.rotateRight":`Rotate Right`,"zc.rate.texts.1":`Very Bad`,"zc.rate.texts.2":`Disappointed`,"zc.rate.texts.3":`Normal`,"zc.rate.texts.4":`Satisfied`,"zc.rate.texts.5":`Surprised`,"zc.transfer.titleLeft":`List 1`,"zc.transfer.titleRight":`List 2`,"zc.transfer.filterPlaceholder":`Enter search content`,"zc.transfer.noData":`No data`,"zc.table.emptyText":`No Data`,"zc.tag.close":`Remove tag`},a=(0,e.ref)(`zh-CN`),o=(0,e.ref)(`zh-CN`),s=(0,e.reactive)({"zh-CN":{...r},"en-US":{...i}});function c(e){a.value=e}function l(){return a.value}function u(e){o.value=e}function d(){return o.value}function f(e,t){var r,i;let c=s[a.value],l=s[o.value];return n((r=(i=c==null?void 0:c[e])==null?l==null?void 0:l[e]:i)==null?e:r,t)}function p(e,n){let r=t(n);s[e]={...s[e],...r}}var m=Symbol(`zcLocale`);function h(){return(0,e.inject)(m,null)||{locale:(0,e.readonly)(a),t:f,setLocale:c,getLocale:l,setFallbackLocale:u,getFallbackLocale:d,register:p}}function g(t){return{install(n){if(t!=null&&t.locale&&c(t.locale),t!=null&&t.fallbackLocale&&u(t.fallbackLocale),t!=null&&t.messages)for(let[e,n]of Object.entries(t.messages))p(e,n);let r={locale:(0,e.readonly)(a),t:f,setLocale:c,getLocale:l,setFallbackLocale:u,getFallbackLocale:d,register:p};n.provide(m,r)}}}exports.createLocale=g,exports.getFallbackLocale=d,exports.getLocale=l,exports.localeInjectionKey=m,exports.register=p,exports.setFallbackLocale=u,exports.setLocale=c,exports.t=f,exports.useLocale=h;
package/dist/index.mjs ADDED
@@ -0,0 +1,235 @@
1
+ import { inject as e, reactive as t, readonly as n, ref as r } from "vue";
2
+ //#region src/dictionary.ts
3
+ function i(e, t = "") {
4
+ let n = {};
5
+ for (let [r, a] of Object.entries(e)) {
6
+ let e = t ? `${t}.${r}` : r;
7
+ typeof a == "object" && a && !Array.isArray(a) ? Object.assign(n, i(a, e)) : n[e] = String(a);
8
+ }
9
+ return n;
10
+ }
11
+ //#endregion
12
+ //#region src/translate.ts
13
+ function a(e, t) {
14
+ return t ? e.replace(/\{(\w+)\}/g, (e, n) => n in t ? String(t[n]) : e) : e;
15
+ }
16
+ //#endregion
17
+ //#region src/index.ts
18
+ var o = {
19
+ "common.confirm": "确定",
20
+ "common.cancel": "取消",
21
+ "common.loading": "加载中...",
22
+ "common.empty": "暂无数据",
23
+ "common.ok": "确定",
24
+ "common.save": "保存",
25
+ "common.delete": "删除",
26
+ "common.close": "关闭",
27
+ "zc.pagination.total": "共 {total} 条",
28
+ "zc.pagination.goto": "前往",
29
+ "zc.pagination.pageClassifier": "页",
30
+ "zc.empty.description": "暂无数据",
31
+ "zc.select.placeholder": "请选择",
32
+ "zc.select.noData": "暂无数据",
33
+ "zc.select.noMatch": "无匹配数据",
34
+ "zc.timePicker.placeholder": "请选择时间",
35
+ "zc.timePicker.startPlaceholder": "开始时间",
36
+ "zc.timePicker.endPlaceholder": "结束时间",
37
+ "zc.timePicker.rangeSeparator": "至",
38
+ "zc.autoComplete.placeholder": "请输入",
39
+ "zc.autoComplete.noData": "暂无数据",
40
+ "zc.autoComplete.searching": "搜索中...",
41
+ "zc.treeSelect.placeholder": "请选择",
42
+ "zc.treeSelect.searchPlaceholder": "搜索",
43
+ "zc.treeSelect.noData": "暂无数据",
44
+ "zc.cascader.placeholder": "请选择",
45
+ "zc.carousel.prev": "上一张",
46
+ "zc.carousel.next": "下一张",
47
+ "zc.carousel.indicator": "切换到第 {index} 张",
48
+ "zc.alert.close": "关闭",
49
+ "zc.backtop.backToTop": "返回顶部",
50
+ "zc.datePicker.placeholder": "请选择日期",
51
+ "zc.datePicker.startPlaceholder": "开始日期",
52
+ "zc.datePicker.endPlaceholder": "结束日期",
53
+ "zc.datePicker.year": "年",
54
+ "zc.datePicker.weekdays.sun": "日",
55
+ "zc.datePicker.weekdays.mon": "一",
56
+ "zc.datePicker.weekdays.tue": "二",
57
+ "zc.datePicker.weekdays.wed": "三",
58
+ "zc.datePicker.weekdays.thu": "四",
59
+ "zc.datePicker.weekdays.fri": "五",
60
+ "zc.datePicker.weekdays.sat": "六",
61
+ "zc.datePicker.months.jan": "一月",
62
+ "zc.datePicker.months.feb": "二月",
63
+ "zc.datePicker.months.mar": "三月",
64
+ "zc.datePicker.months.apr": "四月",
65
+ "zc.datePicker.months.may": "五月",
66
+ "zc.datePicker.months.jun": "六月",
67
+ "zc.datePicker.months.jul": "七月",
68
+ "zc.datePicker.months.aug": "八月",
69
+ "zc.datePicker.months.sep": "九月",
70
+ "zc.datePicker.months.oct": "十月",
71
+ "zc.datePicker.months.nov": "十一月",
72
+ "zc.datePicker.months.dec": "十二月",
73
+ "zc.mention.placeholder": "请输入内容",
74
+ "zc.upload.dragTip": "将文件拖到此处,或",
75
+ "zc.upload.clickToUpload": "点击上传",
76
+ "zc.form.required": "该字段为必填项",
77
+ "zc.form.min": "长度不能少于 {min}",
78
+ "zc.form.max": "长度不能超过 {max}",
79
+ "zc.form.pattern": "格式不正确",
80
+ "zc.form.validateFailed": "校验失败",
81
+ "zc.image.preview": "图片预览",
82
+ "zc.image.closePreview": "关闭预览",
83
+ "zc.image.zoomIn": "放大",
84
+ "zc.image.zoomOut": "缩小",
85
+ "zc.image.rotateLeft": "向左旋转",
86
+ "zc.image.rotateRight": "向右旋转",
87
+ "zc.rate.texts.1": "极差",
88
+ "zc.rate.texts.2": "失望",
89
+ "zc.rate.texts.3": "一般",
90
+ "zc.rate.texts.4": "满意",
91
+ "zc.rate.texts.5": "惊喜",
92
+ "zc.transfer.titleLeft": "列表 1",
93
+ "zc.transfer.titleRight": "列表 2",
94
+ "zc.transfer.filterPlaceholder": "请输入搜索内容",
95
+ "zc.transfer.noData": "暂无数据",
96
+ "zc.table.emptyText": "暂无数据",
97
+ "zc.tag.close": "移除标签"
98
+ }, s = {
99
+ "common.confirm": "Confirm",
100
+ "common.cancel": "Cancel",
101
+ "common.loading": "Loading...",
102
+ "common.empty": "No data",
103
+ "common.ok": "OK",
104
+ "common.save": "Save",
105
+ "common.delete": "Delete",
106
+ "common.close": "Close",
107
+ "zc.pagination.total": "Total {total}",
108
+ "zc.pagination.goto": "Go to",
109
+ "zc.pagination.pageClassifier": "",
110
+ "zc.pagination.label": "Pagination",
111
+ "zc.empty.description": "No Data",
112
+ "zc.select.placeholder": "Please select",
113
+ "zc.select.noData": "No data",
114
+ "zc.select.noMatch": "No matching data",
115
+ "zc.timePicker.placeholder": "Select time",
116
+ "zc.timePicker.startPlaceholder": "Start time",
117
+ "zc.timePicker.endPlaceholder": "End time",
118
+ "zc.timePicker.rangeSeparator": "To",
119
+ "zc.autoComplete.placeholder": "Please input",
120
+ "zc.autoComplete.noData": "No data",
121
+ "zc.autoComplete.searching": "Searching...",
122
+ "zc.treeSelect.placeholder": "Please select",
123
+ "zc.treeSelect.searchPlaceholder": "Search",
124
+ "zc.treeSelect.noData": "No data",
125
+ "zc.cascader.placeholder": "Please select",
126
+ "zc.carousel.prev": "Previous",
127
+ "zc.carousel.next": "Next",
128
+ "zc.carousel.indicator": "Go to slide {index}",
129
+ "zc.alert.close": "Close",
130
+ "zc.backtop.backToTop": "Back to top",
131
+ "zc.datePicker.placeholder": "Select date",
132
+ "zc.datePicker.startPlaceholder": "Start date",
133
+ "zc.datePicker.endPlaceholder": "End date",
134
+ "zc.datePicker.year": "",
135
+ "zc.datePicker.weekdays.sun": "Su",
136
+ "zc.datePicker.weekdays.mon": "Mo",
137
+ "zc.datePicker.weekdays.tue": "Tu",
138
+ "zc.datePicker.weekdays.wed": "We",
139
+ "zc.datePicker.weekdays.thu": "Th",
140
+ "zc.datePicker.weekdays.fri": "Fr",
141
+ "zc.datePicker.weekdays.sat": "Sa",
142
+ "zc.datePicker.months.jan": "January",
143
+ "zc.datePicker.months.feb": "February",
144
+ "zc.datePicker.months.mar": "March",
145
+ "zc.datePicker.months.apr": "April",
146
+ "zc.datePicker.months.may": "May",
147
+ "zc.datePicker.months.jun": "June",
148
+ "zc.datePicker.months.jul": "July",
149
+ "zc.datePicker.months.aug": "August",
150
+ "zc.datePicker.months.sep": "September",
151
+ "zc.datePicker.months.oct": "October",
152
+ "zc.datePicker.months.nov": "November",
153
+ "zc.datePicker.months.dec": "December",
154
+ "zc.mention.placeholder": "Please enter content",
155
+ "zc.upload.dragTip": "Drop files here, or ",
156
+ "zc.upload.clickToUpload": "click to upload",
157
+ "zc.form.required": "This field is required",
158
+ "zc.form.min": "Length cannot be less than {min}",
159
+ "zc.form.max": "Length cannot be greater than {max}",
160
+ "zc.form.pattern": "Invalid format",
161
+ "zc.form.validateFailed": "Validation failed",
162
+ "zc.image.preview": "Image Preview",
163
+ "zc.image.closePreview": "Close preview",
164
+ "zc.image.zoomIn": "Zoom In",
165
+ "zc.image.zoomOut": "Zoom Out",
166
+ "zc.image.rotateLeft": "Rotate Left",
167
+ "zc.image.rotateRight": "Rotate Right",
168
+ "zc.rate.texts.1": "Very Bad",
169
+ "zc.rate.texts.2": "Disappointed",
170
+ "zc.rate.texts.3": "Normal",
171
+ "zc.rate.texts.4": "Satisfied",
172
+ "zc.rate.texts.5": "Surprised",
173
+ "zc.transfer.titleLeft": "List 1",
174
+ "zc.transfer.titleRight": "List 2",
175
+ "zc.transfer.filterPlaceholder": "Enter search content",
176
+ "zc.transfer.noData": "No data",
177
+ "zc.table.emptyText": "No Data",
178
+ "zc.tag.close": "Remove tag"
179
+ }, c = r("zh-CN"), l = r("zh-CN"), u = t({
180
+ "zh-CN": { ...o },
181
+ "en-US": { ...s }
182
+ });
183
+ function d(e) {
184
+ c.value = e;
185
+ }
186
+ function f() {
187
+ return c.value;
188
+ }
189
+ function p(e) {
190
+ l.value = e;
191
+ }
192
+ function m() {
193
+ return l.value;
194
+ }
195
+ function h(e, t) {
196
+ var n, r;
197
+ let i = u[c.value], o = u[l.value];
198
+ return a((n = (r = i == null ? void 0 : i[e]) == null ? o == null ? void 0 : o[e] : r) == null ? e : n, t);
199
+ }
200
+ function g(e, t) {
201
+ let n = i(t);
202
+ u[e] = {
203
+ ...u[e],
204
+ ...n
205
+ };
206
+ }
207
+ var _ = Symbol("zcLocale");
208
+ function v() {
209
+ return e(_, null) || {
210
+ locale: n(c),
211
+ t: h,
212
+ setLocale: d,
213
+ getLocale: f,
214
+ setFallbackLocale: p,
215
+ getFallbackLocale: m,
216
+ register: g
217
+ };
218
+ }
219
+ function y(e) {
220
+ return { install(t) {
221
+ if (e != null && e.locale && d(e.locale), e != null && e.fallbackLocale && p(e.fallbackLocale), e != null && e.messages) for (let [t, n] of Object.entries(e.messages)) g(t, n);
222
+ let r = {
223
+ locale: n(c),
224
+ t: h,
225
+ setLocale: d,
226
+ getLocale: f,
227
+ setFallbackLocale: p,
228
+ getFallbackLocale: m,
229
+ register: g
230
+ };
231
+ t.provide(_, r);
232
+ } };
233
+ }
234
+ //#endregion
235
+ export { y as createLocale, m as getFallbackLocale, f as getLocale, _ as localeInjectionKey, g as register, p as setFallbackLocale, d as setLocale, h as t, v as useLocale };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=composable.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composable.spec.d.ts","sourceRoot":"","sources":["../../../src/__tests__/composable.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=dictionary.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dictionary.spec.d.ts","sourceRoot":"","sources":["../../../src/__tests__/dictionary.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.spec.d.ts","sourceRoot":"","sources":["../../../src/__tests__/index.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=translate.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translate.spec.d.ts","sourceRoot":"","sources":["../../../src/__tests__/translate.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Recursively flatten a nested dictionary into dot-notation keys.
3
+ *
4
+ * Both nested objects (`{ button: { confirm: '确定' } }`) and already-flat
5
+ * keys (`{ 'button.confirm': '确定' }`) are supported. The result is always
6
+ * a flat `Record<string, string>`.
7
+ *
8
+ * @example
9
+ * flatten({ button: { confirm: '确定' } })
10
+ * // → { 'button.confirm': '确定' }
11
+ */
12
+ export declare function flatten(dict: Record<string, unknown>, prefix?: string): Record<string, string>;
13
+ //# sourceMappingURL=dictionary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dictionary.d.ts","sourceRoot":"","sources":["../../src/dictionary.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,SAAK,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAc1F"}
@@ -0,0 +1,108 @@
1
+ import { Ref, InjectionKey, Plugin } from 'vue';
2
+ /** Language code. Defaults to 'zh-CN' / 'en-US'; any string is valid. */
3
+ export type Language = string;
4
+ /** Dictionary value: a string or a nested dictionary object. */
5
+ export interface LocaleDictionary {
6
+ [key: string]: string | LocaleDictionary;
7
+ }
8
+ /** Named interpolation parameters. */
9
+ export type TranslateOptions = Record<string, string | number>;
10
+ /** Locale context exposed via provide/inject and useLocale(). */
11
+ export interface LocaleContext {
12
+ /** Reactive current language (read-only) */
13
+ locale: Readonly<Ref<Language>>;
14
+ /** Translate a key with optional named parameters */
15
+ t: (key: string, options?: TranslateOptions) => string;
16
+ /** Set the current language */
17
+ setLocale: (lang: Language) => void;
18
+ /** Get the current language */
19
+ getLocale: () => Language;
20
+ /** Set the fallback language (used when a key is missing in current locale) */
21
+ setFallbackLocale: (lang: Language) => void;
22
+ /** Get the fallback language */
23
+ getFallbackLocale: () => Language;
24
+ /** Register/extend a language pack */
25
+ register: (lang: Language, dict: LocaleDictionary) => void;
26
+ }
27
+ /**
28
+ * Set the current language (reactive).
29
+ */
30
+ export declare function setLocale(lang: Language): void;
31
+ /**
32
+ * Get the current language.
33
+ */
34
+ export declare function getLocale(): Language;
35
+ /**
36
+ * Set the fallback language used when a key is missing in the current locale.
37
+ * Defaults to 'zh-CN'.
38
+ */
39
+ export declare function setFallbackLocale(lang: Language): void;
40
+ /**
41
+ * Get the fallback language.
42
+ */
43
+ export declare function getFallbackLocale(): Language;
44
+ /**
45
+ * Translate a key for the current language.
46
+ *
47
+ * Lookup order:
48
+ * 1. Current locale dictionary
49
+ * 2. Fallback locale dictionary (default: 'zh-CN')
50
+ * 3. The key itself (raw)
51
+ *
52
+ * Supports named parameter interpolation via options.
53
+ *
54
+ * @example
55
+ * t('common.confirm') // '确定'
56
+ * t('welcome', { name: '张三' }) // '欢迎, 张三'
57
+ */
58
+ export declare function t(key: string, options?: TranslateOptions): string;
59
+ /**
60
+ * Register or extend a language pack.
61
+ * Nested objects are flattened to dot-notation keys.
62
+ * If the language already exists, new keys are merged in.
63
+ *
64
+ * @example
65
+ * register('ja-JP', { common: { confirm: '確認' } })
66
+ * register('zh-CN', { 'custom.key': '自定义' })
67
+ */
68
+ export declare function register(lang: Language, dict: LocaleDictionary): void;
69
+ /** Injection key for locale context */
70
+ export declare const localeInjectionKey: InjectionKey<LocaleContext>;
71
+ /**
72
+ * Access the locale context within a component.
73
+ *
74
+ * **Must be called inside a component `setup()` function.** When called
75
+ * within a provide tree (i.e. after `app.use(createLocale())`), it returns
76
+ * the injected context. As a fallback for non-component usage (e.g. in
77
+ * utility modules), it returns the module-level singleton context — note
78
+ * that this fallback will trigger a Vue dev-mode warning about `inject()`
79
+ * being called outside setup, which can be safely ignored.
80
+ *
81
+ * @example
82
+ * // In a component setup:
83
+ * const { t, locale, setLocale } = useLocale()
84
+ * t('common.confirm') // '确定'
85
+ * setLocale('en-US') // reactive switch
86
+ */
87
+ export declare function useLocale(): LocaleContext;
88
+ /**
89
+ * Create a locale plugin with optional initial configuration.
90
+ *
91
+ * @example
92
+ * import { createLocale } from '@zc-ui/locale'
93
+ * app.use(createLocale({ locale: 'en-US' }))
94
+ *
95
+ * @example
96
+ * // With custom messages and fallback
97
+ * app.use(createLocale({
98
+ * locale: 'en-US',
99
+ * fallbackLocale: 'zh-CN',
100
+ * messages: { 'ja-JP': { common: { ok: 'OK' } } }
101
+ * }))
102
+ */
103
+ export declare function createLocale(options?: {
104
+ locale?: Language;
105
+ fallbackLocale?: Language;
106
+ messages?: Record<Language, LocaleDictionary>;
107
+ }): Plugin;
108
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAmC,KAAK,GAAG,EAAE,KAAK,YAAY,EAAE,MAAM,KAAK,CAAA;AAClF,OAAO,KAAK,EAAO,MAAM,EAAE,MAAM,KAAK,CAAA;AAQtC,yEAAyE;AACzE,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAA;AAE7B,gEAAgE;AAChE,MAAM,WAAW,gBAAgB;IAC/B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,gBAAgB,CAAA;CACzC;AAED,sCAAsC;AACtC,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;AAE9D,iEAAiE;AACjE,MAAM,WAAW,aAAa;IAC5B,4CAA4C;IAC5C,MAAM,EAAE,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;IAC/B,qDAAqD;IACrD,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,KAAK,MAAM,CAAA;IACtD,+BAA+B;IAC/B,SAAS,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAA;IACnC,+BAA+B;IAC/B,SAAS,EAAE,MAAM,QAAQ,CAAA;IACzB,+EAA+E;IAC/E,iBAAiB,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAA;IAC3C,gCAAgC;IAChC,iBAAiB,EAAE,MAAM,QAAQ,CAAA;IACjC,sCAAsC;IACtC,QAAQ,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,gBAAgB,KAAK,IAAI,CAAA;CAC3D;AAqMD;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,CAE9C;AAED;;GAEG;AACH,wBAAgB,SAAS,IAAI,QAAQ,CAEpC;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,CAEtD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,QAAQ,CAE5C;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAKjE;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,gBAAgB,GAAG,IAAI,CAGrE;AAMD,uCAAuC;AACvC,eAAO,MAAM,kBAAkB,EAAE,YAAY,CAAC,aAAa,CAAsB,CAAA;AAMjF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,SAAS,IAAI,aAAa,CAazC;AAMD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE;IACrC,MAAM,CAAC,EAAE,QAAQ,CAAA;IACjB,cAAc,CAAC,EAAE,QAAQ,CAAA;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAA;CAC9C,GAAG,MAAM,CA4BT"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Replace `{name}` placeholders in a template string with provided values.
3
+ *
4
+ * Placeholders not present in `options` are left as-is.
5
+ *
6
+ * @example
7
+ * interpolate('Hello, {name}!', { name: 'World' }) // 'Hello, World!'
8
+ */
9
+ export declare function interpolate(template: string, options?: Record<string, string | number>): string;
10
+ //# sourceMappingURL=translate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translate.d.ts","sourceRoot":"","sources":["../../src/translate.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG,MAAM,CAM/F"}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@zc-ui/locale",
3
+ "version": "0.0.1",
4
+ "description": "ZC UI internationalization (i18n)",
5
+ "license": "MIT",
6
+ "author": "ZC UI Team",
7
+ "homepage": "https://zc-ui.github.io/zc-ui",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/zc-ui/zc-ui.git",
11
+ "directory": "packages/locale"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/zc-ui/zc-ui/issues"
15
+ },
16
+ "keywords": [
17
+ "vue",
18
+ "ui",
19
+ "i18n",
20
+ "locale",
21
+ "internationalization",
22
+ "zc-ui"
23
+ ],
24
+ "type": "module",
25
+ "main": "./dist/index.cjs",
26
+ "module": "./dist/index.mjs",
27
+ "types": "./dist/types/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/types/index.d.ts",
31
+ "import": "./dist/index.mjs",
32
+ "require": "./dist/index.cjs"
33
+ }
34
+ },
35
+ "files": [
36
+ "dist"
37
+ ],
38
+ "sideEffects": false,
39
+ "publishConfig": {
40
+ "access": "public",
41
+ "registry": "https://registry.npmjs.org"
42
+ },
43
+ "peerDependencies": {
44
+ "vue": "^3.4.0"
45
+ },
46
+ "scripts": {
47
+ "build": "vite build",
48
+ "typecheck": "vue-tsc --noEmit -p tsconfig.json"
49
+ }
50
+ }