@i18n-micro/vue 1.3.3 → 1.3.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/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -6
- package/dist/index.d.ts +30 -6
- package/dist/index.mjs +320 -279
- package/dist/index.mjs.map +1 -1
- package/package.json +35 -37
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import { BaseI18n as
|
|
3
|
-
import { FormatService as
|
|
4
|
-
import { RouterLink as
|
|
5
|
-
const
|
|
1
|
+
import { defineComponent as z, inject as k, h as g, computed as S, ref as G, onMounted as ee, onUnmounted as te, nextTick as ne, shallowRef as B } from "vue";
|
|
2
|
+
import { BaseI18n as ae } from "@i18n-micro/core";
|
|
3
|
+
import { FormatService as Le, defaultPlural as ke, interpolate as Se } from "@i18n-micro/core";
|
|
4
|
+
import { RouterLink as oe } from "vue-router";
|
|
5
|
+
const N = /* @__PURE__ */ Symbol("i18n"), J = /* @__PURE__ */ Symbol("i18n-locales"), Q = /* @__PURE__ */ Symbol("i18n-default-locale"), E = /* @__PURE__ */ Symbol("i18n-router-strategy"), re = z({
|
|
6
6
|
name: "I18nGroup",
|
|
7
7
|
props: {
|
|
8
8
|
prefix: {
|
|
@@ -15,19 +15,19 @@ const E = /* @__PURE__ */ Symbol("i18n"), G = /* @__PURE__ */ Symbol("i18n-local
|
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
setup(t, { slots: e }) {
|
|
18
|
-
const
|
|
19
|
-
if (!
|
|
18
|
+
const n = k(N);
|
|
19
|
+
if (!n)
|
|
20
20
|
throw new Error("[i18n-micro] I18nGroup: i18n instance not found. Make sure i18n plugin is installed.");
|
|
21
|
-
const
|
|
22
|
-
return () =>
|
|
21
|
+
const a = (s, o) => n.t(`${t.prefix}.${s}`, o, void 0, n.getRoute());
|
|
22
|
+
return () => g(
|
|
23
23
|
"div",
|
|
24
24
|
{
|
|
25
25
|
class: ["i18n-group", t.groupClass]
|
|
26
26
|
},
|
|
27
|
-
e.default?.({ prefix: t.prefix, t:
|
|
27
|
+
e.default?.({ prefix: t.prefix, t: a })
|
|
28
28
|
);
|
|
29
29
|
}
|
|
30
|
-
}),
|
|
30
|
+
}), le = z({
|
|
31
31
|
name: "I18nLink",
|
|
32
32
|
props: {
|
|
33
33
|
to: {
|
|
@@ -44,27 +44,27 @@ const E = /* @__PURE__ */ Symbol("i18n"), G = /* @__PURE__ */ Symbol("i18n-local
|
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
setup(t, { slots: e }) {
|
|
47
|
-
const
|
|
48
|
-
if (!
|
|
47
|
+
const n = k(N), a = k(E, void 0);
|
|
48
|
+
if (!n)
|
|
49
49
|
throw new Error("[i18n-micro] I18nLink: i18n instance not found. Make sure i18n plugin is installed.");
|
|
50
|
-
const
|
|
51
|
-
if (
|
|
50
|
+
const s = S(() => typeof t.to == "string" ? /^(?:https?:\/\/|\/\/|[a-zA-Z0-9-]+\.[a-zA-Z]{2,})|tel:|mailto:/.test(t.to) : !1), o = S(() => {
|
|
51
|
+
if (s.value)
|
|
52
52
|
return t.to;
|
|
53
53
|
if (t.localeRoute) {
|
|
54
|
-
const
|
|
55
|
-
return typeof
|
|
54
|
+
const r = t.localeRoute(t.to);
|
|
55
|
+
return typeof r == "string" ? r : r.path || "/";
|
|
56
56
|
}
|
|
57
|
-
if (!
|
|
57
|
+
if (!a?.resolvePath)
|
|
58
58
|
return typeof t.to == "string" ? t.to : t.to.path || "/";
|
|
59
|
-
const
|
|
60
|
-
return typeof
|
|
61
|
-
}), u =
|
|
62
|
-
if (
|
|
59
|
+
const i = a.resolvePath(t.to, n.locale.value);
|
|
60
|
+
return typeof i == "string" ? i : i.path || "/";
|
|
61
|
+
}), u = S(() => {
|
|
62
|
+
if (s.value || !a)
|
|
63
63
|
return !1;
|
|
64
|
-
const
|
|
65
|
-
return
|
|
66
|
-
}), d =
|
|
67
|
-
return () =>
|
|
64
|
+
const i = a.getCurrentPath().replace(/\/$/, ""), r = o.value.replace(/\/$/, "");
|
|
65
|
+
return i === r;
|
|
66
|
+
}), d = S(() => u.value ? t.activeStyle : {});
|
|
67
|
+
return () => s.value ? g(
|
|
68
68
|
"a",
|
|
69
69
|
{
|
|
70
70
|
href: o.value,
|
|
@@ -73,26 +73,26 @@ const E = /* @__PURE__ */ Symbol("i18n"), G = /* @__PURE__ */ Symbol("i18n-local
|
|
|
73
73
|
style: d.value
|
|
74
74
|
},
|
|
75
75
|
e.default?.()
|
|
76
|
-
) :
|
|
77
|
-
|
|
76
|
+
) : a?.linkComponent ? g(
|
|
77
|
+
a.linkComponent,
|
|
78
78
|
{
|
|
79
79
|
to: o.value,
|
|
80
80
|
style: d.value
|
|
81
81
|
},
|
|
82
82
|
{ default: e.default }
|
|
83
|
-
) :
|
|
83
|
+
) : g(
|
|
84
84
|
"a",
|
|
85
85
|
{
|
|
86
86
|
href: o.value,
|
|
87
87
|
style: d.value,
|
|
88
|
-
onClick: (
|
|
89
|
-
|
|
88
|
+
onClick: (i) => {
|
|
89
|
+
i.preventDefault(), a ? a.push({ path: o.value }) : window.location.href = o.value;
|
|
90
90
|
}
|
|
91
91
|
},
|
|
92
92
|
e.default?.()
|
|
93
93
|
);
|
|
94
94
|
}
|
|
95
|
-
}),
|
|
95
|
+
}), ie = z({
|
|
96
96
|
name: "I18nSwitcher",
|
|
97
97
|
props: {
|
|
98
98
|
customLabels: {
|
|
@@ -123,6 +123,13 @@ const E = /* @__PURE__ */ Symbol("i18n"), G = /* @__PURE__ */ Symbol("i18n-local
|
|
|
123
123
|
type: Object,
|
|
124
124
|
default: () => ({})
|
|
125
125
|
},
|
|
126
|
+
/**
|
|
127
|
+
* Inline style applied to the switcher button when the *current* locale is
|
|
128
|
+
* marked as `disabled: true` in the locale config.
|
|
129
|
+
*
|
|
130
|
+
* Note: disabled locales are omitted from the dropdown list, but the current
|
|
131
|
+
* locale label is still shown on the button.
|
|
132
|
+
*/
|
|
126
133
|
customDisabledLinkStyle: {
|
|
127
134
|
type: Object,
|
|
128
135
|
default: () => ({})
|
|
@@ -153,38 +160,38 @@ const E = /* @__PURE__ */ Symbol("i18n"), G = /* @__PURE__ */ Symbol("i18n-local
|
|
|
153
160
|
}
|
|
154
161
|
},
|
|
155
162
|
setup(t, { slots: e }) {
|
|
156
|
-
const
|
|
157
|
-
if (!
|
|
163
|
+
const n = k(N), a = k(E, void 0), s = k(J, void 0);
|
|
164
|
+
if (!n)
|
|
158
165
|
throw new Error("[i18n-micro] I18nSwitcher: i18n instance not found. Make sure i18n plugin is installed.");
|
|
159
|
-
if (!
|
|
166
|
+
if (!s && !t.locales)
|
|
160
167
|
throw new Error(
|
|
161
168
|
"[i18n-micro] I18nSwitcher: locales not provided. Make sure app.provide(I18nLocalesKey, locales) is called or pass locales prop."
|
|
162
169
|
);
|
|
163
|
-
const o =
|
|
164
|
-
|
|
165
|
-
},
|
|
166
|
-
const
|
|
167
|
-
return
|
|
168
|
-
}),
|
|
169
|
-
if (l.value = !1, await
|
|
170
|
-
t.switchLocale(
|
|
170
|
+
const o = S(() => t.locales || s || []), u = S(() => o.value.filter((c) => !c.disabled)), d = S(() => t.currentLocale !== void 0 ? typeof t.currentLocale == "function" ? t.currentLocale() : t.currentLocale : n.locale.value), i = S(() => o.value.some((c) => c.code === d.value && c.disabled)), r = S(() => t.getLocaleName ? t.getLocaleName() || null : o.value.find((y) => y.code === n.locale.value)?.displayName || null), l = G(!1), m = G(null), v = (c) => {
|
|
171
|
+
c && (c.stopPropagation(), c.preventDefault()), l.value = !l.value;
|
|
172
|
+
}, b = (c) => t.customLabels[c.code] || c.displayName || c.code, w = S(() => {
|
|
173
|
+
const c = o.value.find((y) => y.code === d.value);
|
|
174
|
+
return c ? b(c) : r.value || d.value;
|
|
175
|
+
}), P = async (c) => {
|
|
176
|
+
if (l.value = !1, await ne(), t.switchLocale) {
|
|
177
|
+
t.switchLocale(c);
|
|
171
178
|
return;
|
|
172
179
|
}
|
|
173
|
-
if (
|
|
180
|
+
if (n.locale.value = c, !a)
|
|
174
181
|
return;
|
|
175
|
-
const
|
|
176
|
-
const
|
|
177
|
-
return typeof
|
|
178
|
-
})() :
|
|
179
|
-
const
|
|
180
|
-
return typeof
|
|
181
|
-
})() :
|
|
182
|
-
|
|
183
|
-
},
|
|
182
|
+
const y = a.getCurrentPath(), L = t.localeRoute ? (() => {
|
|
183
|
+
const h = t.localeRoute(y, c);
|
|
184
|
+
return typeof h == "string" ? h : h.path || "/";
|
|
185
|
+
})() : a?.resolvePath ? (() => {
|
|
186
|
+
const h = a.resolvePath(y, c);
|
|
187
|
+
return typeof h == "string" ? h : h.path || "/";
|
|
188
|
+
})() : y;
|
|
189
|
+
a.push({ path: L });
|
|
190
|
+
}, _ = {
|
|
184
191
|
position: "relative",
|
|
185
192
|
display: "inline-block",
|
|
186
193
|
verticalAlign: "middle"
|
|
187
|
-
},
|
|
194
|
+
}, I = {
|
|
188
195
|
padding: "4px 12px",
|
|
189
196
|
fontSize: "16px",
|
|
190
197
|
cursor: "pointer",
|
|
@@ -194,7 +201,7 @@ const E = /* @__PURE__ */ Symbol("i18n"), G = /* @__PURE__ */ Symbol("i18n-local
|
|
|
194
201
|
display: "flex",
|
|
195
202
|
alignItems: "center",
|
|
196
203
|
justifyContent: "space-between"
|
|
197
|
-
},
|
|
204
|
+
}, O = {
|
|
198
205
|
position: "absolute",
|
|
199
206
|
top: "100%",
|
|
200
207
|
left: "0",
|
|
@@ -206,126 +213,135 @@ const E = /* @__PURE__ */ Symbol("i18n"), G = /* @__PURE__ */ Symbol("i18n-local
|
|
|
206
213
|
margin: "4px 0 0 0",
|
|
207
214
|
minWidth: "150px",
|
|
208
215
|
boxShadow: "0 2px 8px rgba(0,0,0,0.15)"
|
|
209
|
-
},
|
|
216
|
+
}, C = {
|
|
210
217
|
margin: "0",
|
|
211
218
|
padding: "0"
|
|
212
|
-
},
|
|
219
|
+
}, q = {
|
|
213
220
|
display: "block",
|
|
214
221
|
padding: "8px 12px",
|
|
215
222
|
color: "#333",
|
|
216
223
|
textDecoration: "none",
|
|
217
224
|
transition: "background-color 0.3s ease",
|
|
218
225
|
cursor: "pointer"
|
|
219
|
-
},
|
|
226
|
+
}, V = {
|
|
220
227
|
fontWeight: "bold",
|
|
221
|
-
color: "#007bff"
|
|
222
|
-
|
|
228
|
+
color: "#007bff",
|
|
229
|
+
// Current locale is not a meaningful switch target
|
|
230
|
+
cursor: "not-allowed"
|
|
231
|
+
}, F = {
|
|
223
232
|
marginLeft: "8px",
|
|
224
233
|
display: "inline-block",
|
|
225
234
|
transition: "transform 0.3s ease"
|
|
226
|
-
},
|
|
235
|
+
}, T = {
|
|
227
236
|
transform: "rotate(180deg)"
|
|
228
|
-
},
|
|
237
|
+
}, p = (c) => c ? Array.isArray(c) ? c : [c] : [], U = (c) => {
|
|
229
238
|
if (!l.value) return;
|
|
230
|
-
const
|
|
231
|
-
if (!
|
|
232
|
-
const
|
|
233
|
-
!
|
|
239
|
+
const y = c.target;
|
|
240
|
+
if (!y || !m.value) return;
|
|
241
|
+
const L = m.value.contains(y), h = y.closest(".i18n-switcher-button") !== null;
|
|
242
|
+
!L && !h && (l.value = !1);
|
|
234
243
|
};
|
|
235
|
-
return
|
|
236
|
-
document.addEventListener("click",
|
|
237
|
-
}),
|
|
238
|
-
document.removeEventListener("click",
|
|
244
|
+
return ee(() => {
|
|
245
|
+
document.addEventListener("click", U);
|
|
246
|
+
}), te(() => {
|
|
247
|
+
document.removeEventListener("click", U);
|
|
239
248
|
}), () => {
|
|
240
|
-
const
|
|
241
|
-
e["before-button"] &&
|
|
242
|
-
const
|
|
243
|
-
if (e["before-selected-locale"] &&
|
|
244
|
-
|
|
249
|
+
const c = [];
|
|
250
|
+
e["before-button"] && c.push(...p(e["before-button"]()));
|
|
251
|
+
const y = [];
|
|
252
|
+
if (e["before-selected-locale"] && y.push(...p(e["before-selected-locale"]())), y.push(g("span", w.value)), e["after-selected-locale"] && y.push(...p(e["after-selected-locale"]())), y.push(
|
|
253
|
+
g(
|
|
245
254
|
"span",
|
|
246
255
|
{
|
|
247
256
|
style: {
|
|
248
|
-
...
|
|
249
|
-
...l.value ?
|
|
257
|
+
...F,
|
|
258
|
+
...l.value ? T : {},
|
|
250
259
|
...t.customIconStyle
|
|
251
260
|
}
|
|
252
261
|
},
|
|
253
262
|
"▼"
|
|
254
263
|
)
|
|
255
|
-
),
|
|
256
|
-
|
|
264
|
+
), c.push(
|
|
265
|
+
g(
|
|
257
266
|
"button",
|
|
258
267
|
{
|
|
259
268
|
class: "i18n-switcher-button",
|
|
260
|
-
style: {
|
|
261
|
-
|
|
262
|
-
|
|
269
|
+
style: {
|
|
270
|
+
...I,
|
|
271
|
+
...t.customButtonStyle,
|
|
272
|
+
...i.value ? t.customDisabledLinkStyle : {}
|
|
273
|
+
},
|
|
274
|
+
onClick: (L) => {
|
|
275
|
+
L.preventDefault(), L.stopPropagation(), v(L);
|
|
263
276
|
},
|
|
264
277
|
type: "button",
|
|
265
278
|
ariaHaspopup: !0,
|
|
266
279
|
ariaExpanded: l.value
|
|
267
280
|
},
|
|
268
|
-
|
|
281
|
+
y
|
|
269
282
|
)
|
|
270
|
-
), e["before-dropdown"] &&
|
|
271
|
-
const
|
|
272
|
-
e["before-dropdown-items"] &&
|
|
283
|
+
), e["before-dropdown"] && c.push(...p(e["before-dropdown"]())), l.value) {
|
|
284
|
+
const L = [];
|
|
285
|
+
e["before-dropdown-items"] && L.push(...p(e["before-dropdown-items"]())), u.value.forEach((h) => {
|
|
286
|
+
const j = [];
|
|
287
|
+
e["before-item"] && j.push(...p(e["before-item"]({ locale: h })));
|
|
273
288
|
const M = [];
|
|
274
|
-
e["before-
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
M.push(
|
|
279
|
-
y(
|
|
289
|
+
e["before-link-content"] && M.push(...p(e["before-link-content"]({ locale: h }))), M.push(b(h)), e["after-link-content"] && M.push(...p(e["after-link-content"]({ locale: h })));
|
|
290
|
+
const W = typeof window < "u" ? window.location.pathname : "/", D = t.localeRoute ? t.localeRoute(W, h.code) : a?.resolvePath ? a.resolvePath(W, h.code) : W, A = typeof D == "string" ? D : D.path || "#", K = h.code === d.value;
|
|
291
|
+
j.push(
|
|
292
|
+
g(
|
|
280
293
|
"a",
|
|
281
294
|
{
|
|
282
|
-
class: `switcher-locale-${
|
|
283
|
-
href: typeof
|
|
295
|
+
class: `switcher-locale-${h.code}`,
|
|
296
|
+
href: typeof A == "string" ? A : "#",
|
|
284
297
|
style: {
|
|
285
|
-
...
|
|
286
|
-
...
|
|
287
|
-
...t.customLinkStyle
|
|
298
|
+
...q,
|
|
299
|
+
...K ? V : {},
|
|
300
|
+
...t.customLinkStyle,
|
|
301
|
+
// active-specific customization wins over the generic link style
|
|
302
|
+
// (matches the React/Preact/Solid switchers)
|
|
303
|
+
...K ? t.customActiveLinkStyle : {}
|
|
288
304
|
},
|
|
289
305
|
// Prevent default navigation, use only handleSwitchLocale
|
|
290
|
-
onClick: (
|
|
291
|
-
|
|
306
|
+
onClick: (f) => {
|
|
307
|
+
f.preventDefault(), f.stopPropagation(), P(h.code);
|
|
292
308
|
}
|
|
293
309
|
},
|
|
294
|
-
|
|
310
|
+
M
|
|
295
311
|
)
|
|
296
|
-
), e["after-item"] &&
|
|
297
|
-
|
|
312
|
+
), e["after-item"] && j.push(...p(e["after-item"]({ locale: h }))), L.push(
|
|
313
|
+
g(
|
|
298
314
|
"li",
|
|
299
315
|
{
|
|
300
|
-
key:
|
|
301
|
-
style: { ...
|
|
316
|
+
key: h.code,
|
|
317
|
+
style: { ...C, ...t.customItemStyle }
|
|
302
318
|
},
|
|
303
|
-
|
|
319
|
+
j
|
|
304
320
|
)
|
|
305
321
|
);
|
|
306
|
-
}), e["after-dropdown-items"] &&
|
|
307
|
-
|
|
322
|
+
}), e["after-dropdown-items"] && L.push(...p(e["after-dropdown-items"]())), c.push(
|
|
323
|
+
g(
|
|
308
324
|
"ul",
|
|
309
325
|
{
|
|
310
326
|
class: "i18n-switcher-dropdown",
|
|
311
|
-
style: { ...
|
|
327
|
+
style: { ...O, ...t.customDropdownStyle }
|
|
312
328
|
},
|
|
313
|
-
|
|
329
|
+
L
|
|
314
330
|
)
|
|
315
331
|
);
|
|
316
332
|
}
|
|
317
|
-
return e["after-dropdown"] &&
|
|
333
|
+
return e["after-dropdown"] && c.push(...p(e["after-dropdown"]())), g(
|
|
318
334
|
"div",
|
|
319
335
|
{
|
|
320
|
-
ref:
|
|
336
|
+
ref: m,
|
|
321
337
|
class: "i18n-switcher-wrapper",
|
|
322
|
-
style: { ...
|
|
338
|
+
style: { ..._, ...t.customWrapperStyle }
|
|
323
339
|
},
|
|
324
|
-
|
|
340
|
+
c
|
|
325
341
|
);
|
|
326
342
|
};
|
|
327
343
|
}
|
|
328
|
-
}),
|
|
344
|
+
}), ce = z({
|
|
329
345
|
name: "I18nT",
|
|
330
346
|
props: {
|
|
331
347
|
keypath: {
|
|
@@ -369,91 +385,117 @@ const E = /* @__PURE__ */ Symbol("i18n"), G = /* @__PURE__ */ Symbol("i18n-local
|
|
|
369
385
|
type: [Date, String, Number]
|
|
370
386
|
}
|
|
371
387
|
},
|
|
372
|
-
setup(t, { slots: e, attrs:
|
|
373
|
-
const
|
|
374
|
-
if (!
|
|
388
|
+
setup(t, { slots: e, attrs: n }) {
|
|
389
|
+
const a = k(N);
|
|
390
|
+
if (!a)
|
|
375
391
|
throw new Error("[i18n-micro] I18nT: i18n instance not found. Make sure i18n plugin is installed.");
|
|
376
392
|
return () => {
|
|
377
|
-
const
|
|
393
|
+
const s = {}, o = a.getRoute();
|
|
378
394
|
if (t.number !== void 0) {
|
|
379
|
-
const
|
|
380
|
-
return
|
|
395
|
+
const r = Number(t.number), l = a.tn(r), m = a.t(t.keypath, { number: l, ...t.params }, void 0, o);
|
|
396
|
+
return g(t.tag, { ...n, innerHTML: m });
|
|
381
397
|
}
|
|
382
398
|
if (t.date !== void 0) {
|
|
383
|
-
const
|
|
384
|
-
return
|
|
399
|
+
const r = a.td(t.date), l = a.t(t.keypath, { date: r, ...t.params }, void 0, o);
|
|
400
|
+
return g(t.tag, { ...n, innerHTML: l });
|
|
385
401
|
}
|
|
386
402
|
if (t.relativeDate !== void 0) {
|
|
387
|
-
const
|
|
388
|
-
return
|
|
403
|
+
const r = a.tdr(t.relativeDate), l = a.t(t.keypath, { relativeDate: r, ...t.params }, void 0, o);
|
|
404
|
+
return g(t.tag, { ...n, innerHTML: l });
|
|
389
405
|
}
|
|
390
406
|
if (t.plural !== void 0) {
|
|
391
|
-
const
|
|
407
|
+
const r = Number.parseInt(t.plural.toString(), 10);
|
|
392
408
|
if (t.customPluralRule) {
|
|
393
|
-
const
|
|
409
|
+
const l = t.customPluralRule(
|
|
394
410
|
t.keypath,
|
|
395
|
-
|
|
411
|
+
r,
|
|
396
412
|
t.params,
|
|
397
|
-
|
|
398
|
-
(
|
|
413
|
+
a.locale.value,
|
|
414
|
+
(m, v, b) => a.t(m, v, b, o)
|
|
399
415
|
);
|
|
400
|
-
return
|
|
416
|
+
return g(t.tag, { ...n, innerHTML: l || "" });
|
|
401
417
|
} else {
|
|
402
|
-
const
|
|
403
|
-
return
|
|
418
|
+
const l = a.tc(t.keypath, { count: r, ...t.params });
|
|
419
|
+
return g(t.tag, { ...n, innerHTML: l });
|
|
404
420
|
}
|
|
405
421
|
}
|
|
406
|
-
const u = (
|
|
422
|
+
const u = (a.t(t.keypath, { ...t.params, ...s }, void 0, o) ?? "").toString();
|
|
407
423
|
if (t.hideIfEmpty && !u.trim())
|
|
408
424
|
return t.defaultValue ?? null;
|
|
409
425
|
if (t.html)
|
|
410
|
-
return
|
|
426
|
+
return g(t.tag, { ...n, innerHTML: u });
|
|
411
427
|
if (e.default)
|
|
412
|
-
return
|
|
428
|
+
return g(t.tag, n, e.default({ translation: u }));
|
|
413
429
|
const d = [];
|
|
414
|
-
let
|
|
415
|
-
for (const [
|
|
416
|
-
if (
|
|
417
|
-
const
|
|
418
|
-
|
|
430
|
+
let i = 0;
|
|
431
|
+
for (const [r, l] of Object.entries(e)) {
|
|
432
|
+
if (r === "default") continue;
|
|
433
|
+
const m = `{${r}}`, v = u.indexOf(m, i);
|
|
434
|
+
v !== -1 && (v > i && d.push(u.slice(i, v)), l && d.push(g(l)), i = v + m.length);
|
|
419
435
|
}
|
|
420
|
-
return
|
|
436
|
+
return i < u.length && d.push(u.slice(i)), e.default ? g(t.tag, n, e.default({ children: d })) : d.length > 0 ? g(t.tag, n, d) : g(t.tag, n, u);
|
|
421
437
|
};
|
|
422
438
|
}
|
|
423
439
|
});
|
|
424
|
-
function
|
|
425
|
-
const e =
|
|
440
|
+
function Z(t) {
|
|
441
|
+
const e = t.og?.trim();
|
|
442
|
+
if (e) return e;
|
|
443
|
+
const n = t.iso?.trim();
|
|
444
|
+
if (!n) return null;
|
|
445
|
+
const a = n.indexOf("_");
|
|
446
|
+
if (a > 0) {
|
|
447
|
+
const o = n.slice(0, a), u = n.slice(a + 1);
|
|
448
|
+
if (o.length >= 2 && u.length === 2)
|
|
449
|
+
return `${o.toLowerCase()}_${u.toUpperCase()}`;
|
|
450
|
+
}
|
|
451
|
+
const s = n.indexOf("-");
|
|
452
|
+
if (s > 0) {
|
|
453
|
+
const o = n.slice(0, s), u = n.slice(s + 1);
|
|
454
|
+
if (o.length >= 2 && u.length === 2 && /^[A-Za-z]{2}$/.test(u))
|
|
455
|
+
return `${o.toLowerCase()}_${u.toUpperCase()}`;
|
|
456
|
+
}
|
|
457
|
+
return null;
|
|
458
|
+
}
|
|
459
|
+
function Y(t, e = {}) {
|
|
460
|
+
if (Z(t) !== null || e.missingWarn === !1 || process.env.NODE_ENV === "production") return;
|
|
461
|
+
const n = e.tag ?? "og:locale", a = String(t.code ?? "unknown"), s = t.iso ? `, iso: '${t.iso}'` : "";
|
|
462
|
+
console.warn(
|
|
463
|
+
`[i18n] Cannot derive ${n} for locale '${a}'${s}. Set locale.og (e.g. 'en_US') or use iso with a 2-letter region (e.g. 'en-US').`
|
|
464
|
+
);
|
|
465
|
+
}
|
|
466
|
+
function se(t) {
|
|
467
|
+
const e = k(N), n = k(E, void 0), a = k(J, void 0), s = k(Q, void 0);
|
|
426
468
|
if (!e)
|
|
427
469
|
throw new Error("[i18n-micro] useI18n() must be called after app.use(i18n). Make sure i18n plugin is installed.");
|
|
428
|
-
if (!
|
|
470
|
+
if (!a)
|
|
429
471
|
throw new Error("[i18n-micro] I18nLocalesKey not provided. Make sure app.provide(I18nLocalesKey, locales) is called.");
|
|
430
|
-
if (!
|
|
472
|
+
if (!s)
|
|
431
473
|
throw new Error("[i18n-micro] I18nDefaultLocaleKey not provided. Make sure app.provide(I18nDefaultLocaleKey, defaultLocale) is called.");
|
|
432
|
-
const o = t?.locales ||
|
|
474
|
+
const o = t?.locales || a, u = t?.defaultLocale || s, d = (i, r) => n?.resolvePath ? n.resolvePath(i, r || e.locale.value) : i;
|
|
433
475
|
return {
|
|
434
476
|
// Direct access to instance
|
|
435
477
|
instance: e,
|
|
436
478
|
// Locale (reactive)
|
|
437
|
-
locale:
|
|
479
|
+
locale: S({
|
|
438
480
|
get: () => e.locale.value,
|
|
439
|
-
set: (
|
|
440
|
-
e.locale.value =
|
|
481
|
+
set: (i) => {
|
|
482
|
+
e.locale.value = i;
|
|
441
483
|
}
|
|
442
484
|
}),
|
|
443
485
|
// Locale helpers
|
|
444
486
|
getLocales: () => o,
|
|
445
487
|
defaultLocale: () => u,
|
|
446
|
-
getLocaleName: () => o.find((
|
|
488
|
+
getLocaleName: () => o.find((r) => r.code === e.locale.value)?.displayName || null,
|
|
447
489
|
// Routing helpers
|
|
448
490
|
localeRoute: d,
|
|
449
|
-
localePath: (
|
|
450
|
-
const
|
|
451
|
-
return typeof
|
|
491
|
+
localePath: (i, r) => {
|
|
492
|
+
const l = d(i, r);
|
|
493
|
+
return typeof l == "string" ? l : l.path || "/";
|
|
452
494
|
},
|
|
453
|
-
switchLocale: (
|
|
454
|
-
if (e.locale.value =
|
|
455
|
-
const
|
|
456
|
-
|
|
495
|
+
switchLocale: (i) => {
|
|
496
|
+
if (e.locale.value = i, n) {
|
|
497
|
+
const r = n.getCurrentPath(), l = d(r, i);
|
|
498
|
+
n.push(typeof l == "string" ? { path: l } : { path: l.path || "/" });
|
|
457
499
|
}
|
|
458
500
|
},
|
|
459
501
|
// Translation methods (delegate to instance)
|
|
@@ -464,6 +506,8 @@ function le(t) {
|
|
|
464
506
|
td: e.td.bind(e),
|
|
465
507
|
tdr: e.tdr.bind(e),
|
|
466
508
|
has: e.has.bind(e),
|
|
509
|
+
resolveTranslations: e.resolveTranslations.bind(e),
|
|
510
|
+
setTranslation: e.setTranslation.bind(e),
|
|
467
511
|
// Route management
|
|
468
512
|
setRoute: e.setRoute.bind(e),
|
|
469
513
|
getRoute: e.getRoute.bind(e),
|
|
@@ -475,124 +519,129 @@ function le(t) {
|
|
|
475
519
|
clearCache: e.clearCache.bind(e)
|
|
476
520
|
};
|
|
477
521
|
}
|
|
478
|
-
function
|
|
479
|
-
const { addDirAttribute: e = !0, identifierAttribute:
|
|
522
|
+
function ye(t = {}) {
|
|
523
|
+
const { addDirAttribute: e = !0, identifierAttribute: n = "id", addSeoAttributes: a = !0, baseUrl: s = "/" } = t, { getLocale: o, getLocales: u, localeRoute: d } = se(), i = k(E, void 0), r = G({
|
|
480
524
|
htmlAttrs: {},
|
|
481
525
|
link: [],
|
|
482
526
|
meta: []
|
|
483
527
|
});
|
|
484
|
-
function
|
|
485
|
-
const
|
|
486
|
-
for (const
|
|
487
|
-
|
|
488
|
-
const
|
|
489
|
-
return
|
|
528
|
+
function l(v, b) {
|
|
529
|
+
const w = new URL(v, "http://localhost"), P = new URLSearchParams(w.search), _ = {};
|
|
530
|
+
for (const O of b)
|
|
531
|
+
P.has(O) && (_[O] = P.get(O));
|
|
532
|
+
const I = new URLSearchParams(_);
|
|
533
|
+
return I.toString() ? `${w.pathname}?${I.toString()}` : w.pathname;
|
|
490
534
|
}
|
|
491
|
-
function
|
|
492
|
-
if (!
|
|
493
|
-
|
|
535
|
+
function m(v = []) {
|
|
536
|
+
if (!i) {
|
|
537
|
+
r.value = { htmlAttrs: {}, link: [], meta: [] };
|
|
494
538
|
return;
|
|
495
539
|
}
|
|
496
|
-
const b = o(),
|
|
497
|
-
if (!
|
|
540
|
+
const b = o(), w = u(), P = w.find((f) => f.code === b);
|
|
541
|
+
if (!P)
|
|
498
542
|
return;
|
|
499
|
-
const
|
|
500
|
-
let
|
|
501
|
-
|
|
502
|
-
const
|
|
503
|
-
let
|
|
504
|
-
const
|
|
543
|
+
const _ = P.iso || b, I = Z(P), O = P.dir || "auto";
|
|
544
|
+
let C = i.getCurrentPath();
|
|
545
|
+
C.startsWith("/") || (C = `/${C}`);
|
|
546
|
+
const q = C.split("/").filter(Boolean), V = w.find((f) => q[0] === f.code);
|
|
547
|
+
let F = C, T, p;
|
|
548
|
+
const U = typeof s == "function" ? s() : s;
|
|
505
549
|
if (V) {
|
|
506
|
-
|
|
550
|
+
F = C.slice(V.code.length + 1) || "/", T = l(F, v);
|
|
507
551
|
const f = `/${b}`;
|
|
508
|
-
|
|
552
|
+
p = `${U}${f}${T.startsWith("/") ? "" : "/"}${T}`;
|
|
509
553
|
} else
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
link: [],
|
|
517
|
-
meta: []
|
|
518
|
-
}, !r)
|
|
554
|
+
T = l(C, v), p = `${U}${T.startsWith("/") ? "" : "/"}${T}`;
|
|
555
|
+
const c = {
|
|
556
|
+
lang: _,
|
|
557
|
+
...e ? { dir: O } : {}
|
|
558
|
+
};
|
|
559
|
+
if (!a) {
|
|
560
|
+
r.value = { htmlAttrs: c, link: [], meta: [] };
|
|
519
561
|
return;
|
|
520
|
-
|
|
521
|
-
|
|
562
|
+
}
|
|
563
|
+
const y = w.filter((f) => !f.disabled && f.seo !== !1);
|
|
564
|
+
I || Y(P, { tag: "og:locale" });
|
|
565
|
+
const L = I ? {
|
|
566
|
+
[n]: "i18n-og",
|
|
522
567
|
property: "og:locale",
|
|
523
|
-
content:
|
|
524
|
-
},
|
|
525
|
-
[
|
|
568
|
+
content: I
|
|
569
|
+
} : null, h = {
|
|
570
|
+
[n]: "i18n-og-url",
|
|
526
571
|
property: "og:url",
|
|
527
|
-
content:
|
|
528
|
-
},
|
|
529
|
-
const
|
|
530
|
-
return {
|
|
531
|
-
[
|
|
572
|
+
content: p
|
|
573
|
+
}, j = y.filter((f) => f.code !== b).map((f) => {
|
|
574
|
+
const x = Z(f);
|
|
575
|
+
return x ? {
|
|
576
|
+
[n]: `i18n-og-alt-${x}`,
|
|
532
577
|
property: "og:locale:alternate",
|
|
533
|
-
content:
|
|
534
|
-
};
|
|
535
|
-
}),
|
|
536
|
-
[
|
|
578
|
+
content: x
|
|
579
|
+
} : (Y(f, { tag: "og:locale:alternate" }), null);
|
|
580
|
+
}).filter((f) => f !== null), M = {
|
|
581
|
+
[n]: "i18n-can",
|
|
537
582
|
rel: "canonical",
|
|
538
|
-
href:
|
|
539
|
-
}, W =
|
|
540
|
-
if (!d || !
|
|
583
|
+
href: p
|
|
584
|
+
}, W = y.flatMap((f) => {
|
|
585
|
+
if (!d || !i)
|
|
541
586
|
return [];
|
|
542
|
-
const
|
|
543
|
-
if (
|
|
587
|
+
const x = i.getCurrentPath(), R = d(x, f.code), $ = typeof R == "string" ? R : R?.path || "/";
|
|
588
|
+
if (!$)
|
|
544
589
|
return [];
|
|
545
590
|
let H;
|
|
546
|
-
|
|
547
|
-
const
|
|
591
|
+
$.startsWith("http://") || $.startsWith("https://") ? H = $ : H = `${typeof s == "function" ? s() : s}${$.startsWith("/") ? "" : "/"}${$}`;
|
|
592
|
+
const X = [
|
|
548
593
|
{
|
|
549
|
-
[
|
|
594
|
+
[n]: `i18n-alternate-${f.code}`,
|
|
550
595
|
rel: "alternate",
|
|
551
596
|
href: H,
|
|
552
597
|
hreflang: f.code
|
|
553
598
|
}
|
|
554
599
|
];
|
|
555
|
-
return f.iso && f.iso !== f.code &&
|
|
556
|
-
[
|
|
600
|
+
return f.iso && f.iso !== f.code && X.push({
|
|
601
|
+
[n]: `i18n-alternate-${f.iso}`,
|
|
557
602
|
rel: "alternate",
|
|
558
603
|
href: H,
|
|
559
604
|
hreflang: f.iso
|
|
560
|
-
}),
|
|
561
|
-
}), D = k(
|
|
562
|
-
let
|
|
563
|
-
const
|
|
564
|
-
if (d &&
|
|
565
|
-
const f =
|
|
566
|
-
if (
|
|
567
|
-
let
|
|
568
|
-
|
|
569
|
-
[
|
|
605
|
+
}), X;
|
|
606
|
+
}), D = k(Q, void 0);
|
|
607
|
+
let A = null;
|
|
608
|
+
const K = D ? w.find((f) => f.code === D) : void 0;
|
|
609
|
+
if (d && i && D && K?.seo !== !1) {
|
|
610
|
+
const f = i.getCurrentPath(), x = d(f, D), R = typeof x == "string" ? x : x?.path || "/";
|
|
611
|
+
if (R) {
|
|
612
|
+
let $;
|
|
613
|
+
R.startsWith("http://") || R.startsWith("https://") ? $ = R : $ = `${typeof s == "function" ? s() : s}${R.startsWith("/") ? "" : "/"}${R}`, A = {
|
|
614
|
+
[n]: "i18n-xd",
|
|
570
615
|
rel: "alternate",
|
|
571
|
-
href:
|
|
616
|
+
href: $,
|
|
572
617
|
hreflang: "x-default"
|
|
573
618
|
};
|
|
574
619
|
}
|
|
575
620
|
}
|
|
576
|
-
|
|
621
|
+
r.value = {
|
|
622
|
+
htmlAttrs: c,
|
|
623
|
+
meta: [...L ? [L] : [], h, ...j],
|
|
624
|
+
link: [M, ...W, ...A ? [A] : []]
|
|
625
|
+
};
|
|
577
626
|
}
|
|
578
627
|
return {
|
|
579
|
-
metaObject:
|
|
580
|
-
updateMeta:
|
|
628
|
+
metaObject: r,
|
|
629
|
+
updateMeta: m
|
|
581
630
|
};
|
|
582
631
|
}
|
|
583
|
-
class
|
|
632
|
+
class ue extends ae {
|
|
584
633
|
constructor(e) {
|
|
585
|
-
const
|
|
634
|
+
const n = {
|
|
586
635
|
translations: /* @__PURE__ */ new Map()
|
|
587
636
|
};
|
|
588
637
|
if (super({
|
|
589
|
-
storage:
|
|
638
|
+
storage: n,
|
|
590
639
|
plural: e.plural,
|
|
591
640
|
missingWarn: e.missingWarn,
|
|
592
641
|
missingHandler: e.missingHandler
|
|
593
|
-
}), this.listeners = /* @__PURE__ */ new Set(), this.storage =
|
|
594
|
-
for (const [
|
|
595
|
-
this.helper.loadTranslations(
|
|
642
|
+
}), this.listeners = /* @__PURE__ */ new Set(), this.storage = n, this._locale = B(e.locale), this._fallbackLocale = B(e.fallbackLocale || e.locale), this._currentRoute = B("index"), this._revision = B(0), e.messages)
|
|
643
|
+
for (const [a, s] of Object.entries(e.messages))
|
|
644
|
+
this.helper.loadTranslations(a, s);
|
|
596
645
|
}
|
|
597
646
|
get locale() {
|
|
598
647
|
return this._locale;
|
|
@@ -621,69 +670,61 @@ class ie extends ee {
|
|
|
621
670
|
getRoute() {
|
|
622
671
|
return this._currentRoute.value;
|
|
623
672
|
}
|
|
624
|
-
addTranslations(e,
|
|
625
|
-
super.loadTranslationsCore(e,
|
|
673
|
+
addTranslations(e, n, a = !0) {
|
|
674
|
+
super.loadTranslationsCore(e, n, a), this._revision.value++, this.notifyListeners();
|
|
626
675
|
}
|
|
627
|
-
addRouteTranslations(e,
|
|
628
|
-
super.loadRouteTranslationsCore(e,
|
|
676
|
+
addRouteTranslations(e, n, a, s = !0) {
|
|
677
|
+
super.loadRouteTranslationsCore(e, n, a, s), this._revision.value++, this.notifyListeners();
|
|
629
678
|
}
|
|
630
|
-
mergeTranslations(e,
|
|
631
|
-
this.helper.mergeTranslation(e,
|
|
679
|
+
mergeTranslations(e, n, a) {
|
|
680
|
+
this.helper.mergeTranslation(e, n, a, !0), this._revision.value++, this.notifyListeners();
|
|
632
681
|
}
|
|
633
682
|
clearCache() {
|
|
634
683
|
super.clearCache(), this._revision.value++, this.notifyListeners();
|
|
635
684
|
}
|
|
685
|
+
onTranslationsChanged() {
|
|
686
|
+
this._revision.value++, this.notifyListeners();
|
|
687
|
+
}
|
|
636
688
|
subscribeToChanges(e) {
|
|
637
689
|
return this.listeners.add(e), () => this.listeners.delete(e);
|
|
638
690
|
}
|
|
639
691
|
notifyListeners() {
|
|
640
692
|
this.listeners.forEach((e) => e());
|
|
641
693
|
}
|
|
642
|
-
getAllTranslations() {
|
|
643
|
-
const e = {};
|
|
644
|
-
for (const [a, r] of this.storage.translations)
|
|
645
|
-
if (!a.includes(":"))
|
|
646
|
-
e[a] = r;
|
|
647
|
-
else {
|
|
648
|
-
const c = a.split(":")[0];
|
|
649
|
-
c && (e[c] || (e[c] = {}), Object.assign(e[c], r));
|
|
650
|
-
}
|
|
651
|
-
return e;
|
|
652
|
-
}
|
|
653
694
|
getStorage() {
|
|
654
695
|
return this.storage;
|
|
655
696
|
}
|
|
656
697
|
getRouteCache() {
|
|
657
698
|
const e = {};
|
|
658
|
-
for (const [
|
|
659
|
-
e[
|
|
699
|
+
for (const [n, a] of this.storage.translations)
|
|
700
|
+
e[n] = a;
|
|
660
701
|
return e;
|
|
661
702
|
}
|
|
662
703
|
}
|
|
663
|
-
function
|
|
664
|
-
const { routingStrategy: e, locales:
|
|
704
|
+
function me(t) {
|
|
705
|
+
const { routingStrategy: e, locales: n, defaultLocale: a, ...s } = t, o = new ue(s);
|
|
665
706
|
let u = null, d = e || null;
|
|
666
707
|
return {
|
|
667
708
|
global: o,
|
|
668
709
|
// Access to instance outside components
|
|
669
|
-
setRoutingStrategy: (
|
|
670
|
-
d =
|
|
710
|
+
setRoutingStrategy: (r) => {
|
|
711
|
+
d = r, u && u.provide(E, r);
|
|
671
712
|
},
|
|
672
713
|
// Method for setting adapter after creation
|
|
673
|
-
install(
|
|
674
|
-
u =
|
|
714
|
+
install(r) {
|
|
715
|
+
u = r, r.provide(N, o), d && r.provide(E, d), n && r.provide(J, n), a && r.provide(Q, a), r.config.globalProperties.$t = (l, m, v, b) => o.t(l, m, v, b), r.config.globalProperties.$ts = (l, m, v, b) => o.ts(l, m, v, b), r.config.globalProperties.$tc = (l, m, v) => o.tc(l, m, v), r.config.globalProperties.$tn = o.tn.bind(o), r.config.globalProperties.$td = o.td.bind(o), r.config.globalProperties.$tdr = o.tdr.bind(o), r.config.globalProperties.$has = (l, m) => o.has(l, m), r.config.globalProperties.$i18n = o, r.component("I18nT", ce), r.component("I18nLink", le), r.component("I18nGroup", re), r.component("I18nSwitcher", ie);
|
|
675
716
|
}
|
|
676
717
|
};
|
|
677
718
|
}
|
|
678
|
-
function
|
|
679
|
-
const
|
|
680
|
-
const
|
|
681
|
-
|
|
682
|
-
const
|
|
683
|
-
return u ===
|
|
719
|
+
function ve(t, e, n) {
|
|
720
|
+
const a = e.map((o) => o.code), s = (o, u) => {
|
|
721
|
+
const i = (typeof o == "string" ? o : o.path || "/").split("/").filter(Boolean), r = i[0];
|
|
722
|
+
r !== void 0 && a.includes(r) && i.shift();
|
|
723
|
+
const l = `/${i.join("/")}`;
|
|
724
|
+
return u === n ? l : `/${u}${l === "/" ? "" : l}`;
|
|
684
725
|
};
|
|
685
726
|
return {
|
|
686
|
-
linkComponent:
|
|
727
|
+
linkComponent: oe,
|
|
687
728
|
getCurrentPath: () => t.currentRoute.value.path,
|
|
688
729
|
push: (o) => {
|
|
689
730
|
t.push(o.path).catch(() => {
|
|
@@ -693,7 +734,7 @@ function ge(t, e, a) {
|
|
|
693
734
|
t.replace(o.path).catch(() => {
|
|
694
735
|
});
|
|
695
736
|
},
|
|
696
|
-
resolvePath: (o, u) =>
|
|
737
|
+
resolvePath: (o, u) => s(o, u),
|
|
697
738
|
getRoute: () => ({
|
|
698
739
|
fullPath: t.currentRoute.value.fullPath,
|
|
699
740
|
query: t.currentRoute.value.query
|
|
@@ -701,20 +742,20 @@ function ge(t, e, a) {
|
|
|
701
742
|
};
|
|
702
743
|
}
|
|
703
744
|
export {
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
745
|
+
Le as FormatService,
|
|
746
|
+
Q as I18nDefaultLocaleKey,
|
|
747
|
+
re as I18nGroup,
|
|
748
|
+
N as I18nInjectionKey,
|
|
749
|
+
le as I18nLink,
|
|
750
|
+
J as I18nLocalesKey,
|
|
751
|
+
ie as I18nSwitcher,
|
|
752
|
+
ce as I18nT,
|
|
753
|
+
ue as VueI18n,
|
|
754
|
+
me as createI18n,
|
|
755
|
+
ve as createVueRouterAdapter,
|
|
756
|
+
ke as defaultPlural,
|
|
757
|
+
Se as interpolate,
|
|
758
|
+
se as useI18n,
|
|
759
|
+
ye as useLocaleHead
|
|
719
760
|
};
|
|
720
761
|
//# sourceMappingURL=index.mjs.map
|