@i18n-micro/vue 1.3.4 → 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 +27 -3
- package/dist/index.d.ts +27 -3
- package/dist/index.mjs +236 -226
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -11
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { defineComponent as
|
|
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
2
|
import { BaseI18n as ae } from "@i18n-micro/core";
|
|
3
|
-
import { FormatService as Le, defaultPlural as ke, interpolate as
|
|
4
|
-
import { RouterLink as
|
|
5
|
-
const N = /* @__PURE__ */ Symbol("i18n"),
|
|
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: {
|
|
@@ -18,8 +18,8 @@ const N = /* @__PURE__ */ Symbol("i18n"), Z = /* @__PURE__ */ Symbol("i18n-local
|
|
|
18
18
|
const n = k(N);
|
|
19
19
|
if (!n)
|
|
20
20
|
throw new Error("[i18n-micro] I18nGroup: i18n instance not found. Make sure i18n plugin is installed.");
|
|
21
|
-
const a = (
|
|
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]
|
|
@@ -27,7 +27,7 @@ const N = /* @__PURE__ */ Symbol("i18n"), Z = /* @__PURE__ */ Symbol("i18n-local
|
|
|
27
27
|
e.default?.({ prefix: t.prefix, t: a })
|
|
28
28
|
);
|
|
29
29
|
}
|
|
30
|
-
}), le =
|
|
30
|
+
}), le = z({
|
|
31
31
|
name: "I18nLink",
|
|
32
32
|
props: {
|
|
33
33
|
to: {
|
|
@@ -47,8 +47,8 @@ const N = /* @__PURE__ */ Symbol("i18n"), Z = /* @__PURE__ */ Symbol("i18n-local
|
|
|
47
47
|
const n = k(N), a = k(E, void 0);
|
|
48
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
54
|
const r = t.localeRoute(t.to);
|
|
@@ -56,15 +56,15 @@ const N = /* @__PURE__ */ Symbol("i18n"), Z = /* @__PURE__ */ Symbol("i18n-local
|
|
|
56
56
|
}
|
|
57
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 N = /* @__PURE__ */ Symbol("i18n"), Z = /* @__PURE__ */ Symbol("i18n-local
|
|
|
73
73
|
style: d.value
|
|
74
74
|
},
|
|
75
75
|
e.default?.()
|
|
76
|
-
) : a?.linkComponent ?
|
|
76
|
+
) : a?.linkComponent ? g(
|
|
77
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
|
-
}), ie =
|
|
95
|
+
}), ie = z({
|
|
96
96
|
name: "I18nSwitcher",
|
|
97
97
|
props: {
|
|
98
98
|
customLabels: {
|
|
@@ -123,6 +123,13 @@ const N = /* @__PURE__ */ Symbol("i18n"), Z = /* @__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 N = /* @__PURE__ */ Symbol("i18n"), Z = /* @__PURE__ */ Symbol("i18n-local
|
|
|
153
160
|
}
|
|
154
161
|
},
|
|
155
162
|
setup(t, { slots: e }) {
|
|
156
|
-
const n = k(N), a = k(E, void 0),
|
|
163
|
+
const n = k(N), a = k(E, void 0), s = k(J, void 0);
|
|
157
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
|
-
}),
|
|
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) => {
|
|
169
176
|
if (l.value = !1, await ne(), t.switchLocale) {
|
|
170
|
-
t.switchLocale(
|
|
177
|
+
t.switchLocale(c);
|
|
171
178
|
return;
|
|
172
179
|
}
|
|
173
|
-
if (n.locale.value =
|
|
180
|
+
if (n.locale.value = c, !a)
|
|
174
181
|
return;
|
|
175
|
-
const y = a.getCurrentPath(),
|
|
176
|
-
const
|
|
177
|
-
return typeof
|
|
182
|
+
const y = a.getCurrentPath(), L = t.localeRoute ? (() => {
|
|
183
|
+
const h = t.localeRoute(y, c);
|
|
184
|
+
return typeof h == "string" ? h : h.path || "/";
|
|
178
185
|
})() : a?.resolvePath ? (() => {
|
|
179
|
-
const
|
|
180
|
-
return typeof
|
|
186
|
+
const h = a.resolvePath(y, c);
|
|
187
|
+
return typeof h == "string" ? h : h.path || "/";
|
|
181
188
|
})() : y;
|
|
182
|
-
a.push({ path:
|
|
183
|
-
},
|
|
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 N = /* @__PURE__ */ Symbol("i18n"), Z = /* @__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,60 +213,66 @@ const N = /* @__PURE__ */ Symbol("i18n"), Z = /* @__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 y =
|
|
231
|
-
if (!y || !
|
|
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
244
|
return ee(() => {
|
|
236
|
-
document.addEventListener("click",
|
|
245
|
+
document.addEventListener("click", U);
|
|
237
246
|
}), te(() => {
|
|
238
|
-
document.removeEventListener("click",
|
|
247
|
+
document.removeEventListener("click", U);
|
|
239
248
|
}), () => {
|
|
240
|
-
const
|
|
241
|
-
e["before-button"] &&
|
|
249
|
+
const c = [];
|
|
250
|
+
e["before-button"] && c.push(...p(e["before-button"]()));
|
|
242
251
|
const y = [];
|
|
243
|
-
if (e["before-selected-locale"] && y.push(...
|
|
244
|
-
|
|
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,
|
|
@@ -267,65 +280,68 @@ const N = /* @__PURE__ */ Symbol("i18n"), Z = /* @__PURE__ */ Symbol("i18n-local
|
|
|
267
280
|
},
|
|
268
281
|
y
|
|
269
282
|
)
|
|
270
|
-
), e["before-dropdown"] &&
|
|
271
|
-
const
|
|
272
|
-
e["before-dropdown-items"] &&
|
|
273
|
-
const
|
|
274
|
-
e["before-item"] &&
|
|
275
|
-
const
|
|
276
|
-
e["before-link-content"] &&
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
|
|
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 })));
|
|
288
|
+
const M = [];
|
|
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
|
-
}), ce =
|
|
344
|
+
}), ce = z({
|
|
329
345
|
name: "I18nT",
|
|
330
346
|
props: {
|
|
331
347
|
keypath: {
|
|
@@ -374,54 +390,54 @@ const N = /* @__PURE__ */ Symbol("i18n"), Z = /* @__PURE__ */ Symbol("i18n-local
|
|
|
374
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 r = Number(t.number),
|
|
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 r = a.td(t.date),
|
|
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 r = a.tdr(t.relativeDate),
|
|
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
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
413
|
a.locale.value,
|
|
398
|
-
(
|
|
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 = (a.t(t.keypath, { ...t.params, ...
|
|
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 [r,
|
|
430
|
+
let i = 0;
|
|
431
|
+
for (const [r, l] of Object.entries(e)) {
|
|
416
432
|
if (r === "default") continue;
|
|
417
|
-
const
|
|
418
|
-
|
|
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
|
|
440
|
+
function Z(t) {
|
|
425
441
|
const e = t.og?.trim();
|
|
426
442
|
if (e) return e;
|
|
427
443
|
const n = t.iso?.trim();
|
|
@@ -432,38 +448,38 @@ function G(t) {
|
|
|
432
448
|
if (o.length >= 2 && u.length === 2)
|
|
433
449
|
return `${o.toLowerCase()}_${u.toUpperCase()}`;
|
|
434
450
|
}
|
|
435
|
-
const
|
|
436
|
-
if (
|
|
437
|
-
const o = n.slice(0,
|
|
451
|
+
const s = n.indexOf("-");
|
|
452
|
+
if (s > 0) {
|
|
453
|
+
const o = n.slice(0, s), u = n.slice(s + 1);
|
|
438
454
|
if (o.length >= 2 && u.length === 2 && /^[A-Za-z]{2}$/.test(u))
|
|
439
455
|
return `${o.toLowerCase()}_${u.toUpperCase()}`;
|
|
440
456
|
}
|
|
441
457
|
return null;
|
|
442
458
|
}
|
|
443
|
-
function
|
|
444
|
-
if (
|
|
445
|
-
const n = e.tag ?? "og:locale", a = String(t.code ?? "unknown"),
|
|
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}'` : "";
|
|
446
462
|
console.warn(
|
|
447
|
-
`[i18n] Cannot derive ${n} for locale '${a}'${
|
|
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').`
|
|
448
464
|
);
|
|
449
465
|
}
|
|
450
466
|
function se(t) {
|
|
451
|
-
const e = k(N), n = k(E, void 0), a = k(
|
|
467
|
+
const e = k(N), n = k(E, void 0), a = k(J, void 0), s = k(Q, void 0);
|
|
452
468
|
if (!e)
|
|
453
469
|
throw new Error("[i18n-micro] useI18n() must be called after app.use(i18n). Make sure i18n plugin is installed.");
|
|
454
470
|
if (!a)
|
|
455
471
|
throw new Error("[i18n-micro] I18nLocalesKey not provided. Make sure app.provide(I18nLocalesKey, locales) is called.");
|
|
456
|
-
if (!
|
|
472
|
+
if (!s)
|
|
457
473
|
throw new Error("[i18n-micro] I18nDefaultLocaleKey not provided. Make sure app.provide(I18nDefaultLocaleKey, defaultLocale) is called.");
|
|
458
|
-
const o = t?.locales || a, u = t?.defaultLocale ||
|
|
474
|
+
const o = t?.locales || a, u = t?.defaultLocale || s, d = (i, r) => n?.resolvePath ? n.resolvePath(i, r || e.locale.value) : i;
|
|
459
475
|
return {
|
|
460
476
|
// Direct access to instance
|
|
461
477
|
instance: e,
|
|
462
478
|
// Locale (reactive)
|
|
463
|
-
locale:
|
|
479
|
+
locale: S({
|
|
464
480
|
get: () => e.locale.value,
|
|
465
|
-
set: (
|
|
466
|
-
e.locale.value =
|
|
481
|
+
set: (i) => {
|
|
482
|
+
e.locale.value = i;
|
|
467
483
|
}
|
|
468
484
|
}),
|
|
469
485
|
// Locale helpers
|
|
@@ -472,14 +488,14 @@ function se(t) {
|
|
|
472
488
|
getLocaleName: () => o.find((r) => r.code === e.locale.value)?.displayName || null,
|
|
473
489
|
// Routing helpers
|
|
474
490
|
localeRoute: d,
|
|
475
|
-
localePath: (
|
|
476
|
-
const
|
|
477
|
-
return typeof
|
|
491
|
+
localePath: (i, r) => {
|
|
492
|
+
const l = d(i, r);
|
|
493
|
+
return typeof l == "string" ? l : l.path || "/";
|
|
478
494
|
},
|
|
479
|
-
switchLocale: (
|
|
480
|
-
if (e.locale.value =
|
|
481
|
-
const r = n.getCurrentPath(),
|
|
482
|
-
n.push(typeof
|
|
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 || "/" });
|
|
483
499
|
}
|
|
484
500
|
},
|
|
485
501
|
// Translation methods (delegate to instance)
|
|
@@ -490,6 +506,8 @@ function se(t) {
|
|
|
490
506
|
td: e.td.bind(e),
|
|
491
507
|
tdr: e.tdr.bind(e),
|
|
492
508
|
has: e.has.bind(e),
|
|
509
|
+
resolveTranslations: e.resolveTranslations.bind(e),
|
|
510
|
+
setTranslation: e.setTranslation.bind(e),
|
|
493
511
|
// Route management
|
|
494
512
|
setRoute: e.setRoute.bind(e),
|
|
495
513
|
getRoute: e.getRoute.bind(e),
|
|
@@ -501,77 +519,77 @@ function se(t) {
|
|
|
501
519
|
clearCache: e.clearCache.bind(e)
|
|
502
520
|
};
|
|
503
521
|
}
|
|
504
|
-
function
|
|
505
|
-
const { addDirAttribute: e = !0, identifierAttribute: n = "id", addSeoAttributes: a = !0, baseUrl:
|
|
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({
|
|
506
524
|
htmlAttrs: {},
|
|
507
525
|
link: [],
|
|
508
526
|
meta: []
|
|
509
527
|
});
|
|
510
|
-
function
|
|
511
|
-
const w = new URL(
|
|
528
|
+
function l(v, b) {
|
|
529
|
+
const w = new URL(v, "http://localhost"), P = new URLSearchParams(w.search), _ = {};
|
|
512
530
|
for (const O of b)
|
|
513
|
-
|
|
514
|
-
const
|
|
515
|
-
return
|
|
531
|
+
P.has(O) && (_[O] = P.get(O));
|
|
532
|
+
const I = new URLSearchParams(_);
|
|
533
|
+
return I.toString() ? `${w.pathname}?${I.toString()}` : w.pathname;
|
|
516
534
|
}
|
|
517
|
-
function
|
|
518
|
-
if (!
|
|
535
|
+
function m(v = []) {
|
|
536
|
+
if (!i) {
|
|
519
537
|
r.value = { htmlAttrs: {}, link: [], meta: [] };
|
|
520
538
|
return;
|
|
521
539
|
}
|
|
522
|
-
const b = o(), w = u(),
|
|
523
|
-
if (!
|
|
540
|
+
const b = o(), w = u(), P = w.find((f) => f.code === b);
|
|
541
|
+
if (!P)
|
|
524
542
|
return;
|
|
525
|
-
const
|
|
526
|
-
let
|
|
527
|
-
|
|
528
|
-
const
|
|
529
|
-
let
|
|
530
|
-
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;
|
|
531
549
|
if (V) {
|
|
532
|
-
|
|
550
|
+
F = C.slice(V.code.length + 1) || "/", T = l(F, v);
|
|
533
551
|
const f = `/${b}`;
|
|
534
|
-
|
|
552
|
+
p = `${U}${f}${T.startsWith("/") ? "" : "/"}${T}`;
|
|
535
553
|
} else
|
|
536
|
-
|
|
537
|
-
const
|
|
538
|
-
lang:
|
|
554
|
+
T = l(C, v), p = `${U}${T.startsWith("/") ? "" : "/"}${T}`;
|
|
555
|
+
const c = {
|
|
556
|
+
lang: _,
|
|
539
557
|
...e ? { dir: O } : {}
|
|
540
558
|
};
|
|
541
559
|
if (!a) {
|
|
542
|
-
r.value = { htmlAttrs:
|
|
560
|
+
r.value = { htmlAttrs: c, link: [], meta: [] };
|
|
543
561
|
return;
|
|
544
562
|
}
|
|
545
|
-
const
|
|
546
|
-
|
|
547
|
-
const
|
|
563
|
+
const y = w.filter((f) => !f.disabled && f.seo !== !1);
|
|
564
|
+
I || Y(P, { tag: "og:locale" });
|
|
565
|
+
const L = I ? {
|
|
548
566
|
[n]: "i18n-og",
|
|
549
567
|
property: "og:locale",
|
|
550
|
-
content:
|
|
551
|
-
} : null,
|
|
568
|
+
content: I
|
|
569
|
+
} : null, h = {
|
|
552
570
|
[n]: "i18n-og-url",
|
|
553
571
|
property: "og:url",
|
|
554
|
-
content:
|
|
555
|
-
},
|
|
556
|
-
const x =
|
|
572
|
+
content: p
|
|
573
|
+
}, j = y.filter((f) => f.code !== b).map((f) => {
|
|
574
|
+
const x = Z(f);
|
|
557
575
|
return x ? {
|
|
558
576
|
[n]: `i18n-og-alt-${x}`,
|
|
559
577
|
property: "og:locale:alternate",
|
|
560
578
|
content: x
|
|
561
|
-
} : (
|
|
562
|
-
}).filter((f) => f !== null),
|
|
579
|
+
} : (Y(f, { tag: "og:locale:alternate" }), null);
|
|
580
|
+
}).filter((f) => f !== null), M = {
|
|
563
581
|
[n]: "i18n-can",
|
|
564
582
|
rel: "canonical",
|
|
565
|
-
href:
|
|
566
|
-
},
|
|
567
|
-
if (!d || !
|
|
583
|
+
href: p
|
|
584
|
+
}, W = y.flatMap((f) => {
|
|
585
|
+
if (!d || !i)
|
|
568
586
|
return [];
|
|
569
|
-
const x =
|
|
570
|
-
if (
|
|
587
|
+
const x = i.getCurrentPath(), R = d(x, f.code), $ = typeof R == "string" ? R : R?.path || "/";
|
|
588
|
+
if (!$)
|
|
571
589
|
return [];
|
|
572
590
|
let H;
|
|
573
|
-
|
|
574
|
-
const
|
|
591
|
+
$.startsWith("http://") || $.startsWith("https://") ? H = $ : H = `${typeof s == "function" ? s() : s}${$.startsWith("/") ? "" : "/"}${$}`;
|
|
592
|
+
const X = [
|
|
575
593
|
{
|
|
576
594
|
[n]: `i18n-alternate-${f.code}`,
|
|
577
595
|
rel: "alternate",
|
|
@@ -579,36 +597,36 @@ function pe(t = {}) {
|
|
|
579
597
|
hreflang: f.code
|
|
580
598
|
}
|
|
581
599
|
];
|
|
582
|
-
return f.iso && f.iso !== f.code &&
|
|
600
|
+
return f.iso && f.iso !== f.code && X.push({
|
|
583
601
|
[n]: `i18n-alternate-${f.iso}`,
|
|
584
602
|
rel: "alternate",
|
|
585
603
|
href: H,
|
|
586
604
|
hreflang: f.iso
|
|
587
|
-
}),
|
|
588
|
-
}),
|
|
605
|
+
}), X;
|
|
606
|
+
}), D = k(Q, void 0);
|
|
589
607
|
let A = null;
|
|
590
|
-
const
|
|
591
|
-
if (d &&
|
|
592
|
-
const f =
|
|
593
|
-
if (
|
|
594
|
-
let
|
|
595
|
-
|
|
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 = {
|
|
596
614
|
[n]: "i18n-xd",
|
|
597
615
|
rel: "alternate",
|
|
598
|
-
href:
|
|
616
|
+
href: $,
|
|
599
617
|
hreflang: "x-default"
|
|
600
618
|
};
|
|
601
619
|
}
|
|
602
620
|
}
|
|
603
621
|
r.value = {
|
|
604
|
-
htmlAttrs:
|
|
605
|
-
meta: [...
|
|
606
|
-
link: [
|
|
622
|
+
htmlAttrs: c,
|
|
623
|
+
meta: [...L ? [L] : [], h, ...j],
|
|
624
|
+
link: [M, ...W, ...A ? [A] : []]
|
|
607
625
|
};
|
|
608
626
|
}
|
|
609
627
|
return {
|
|
610
628
|
metaObject: r,
|
|
611
|
-
updateMeta:
|
|
629
|
+
updateMeta: m
|
|
612
630
|
};
|
|
613
631
|
}
|
|
614
632
|
class ue extends ae {
|
|
@@ -621,9 +639,9 @@ class ue extends ae {
|
|
|
621
639
|
plural: e.plural,
|
|
622
640
|
missingWarn: e.missingWarn,
|
|
623
641
|
missingHandler: e.missingHandler
|
|
624
|
-
}), this.listeners = /* @__PURE__ */ new Set(), this.storage = n, this._locale =
|
|
625
|
-
for (const [a,
|
|
626
|
-
this.helper.loadTranslations(a,
|
|
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);
|
|
627
645
|
}
|
|
628
646
|
get locale() {
|
|
629
647
|
return this._locale;
|
|
@@ -655,8 +673,8 @@ class ue extends ae {
|
|
|
655
673
|
addTranslations(e, n, a = !0) {
|
|
656
674
|
super.loadTranslationsCore(e, n, a), this._revision.value++, this.notifyListeners();
|
|
657
675
|
}
|
|
658
|
-
addRouteTranslations(e, n, a,
|
|
659
|
-
super.loadRouteTranslationsCore(e, n, a,
|
|
676
|
+
addRouteTranslations(e, n, a, s = !0) {
|
|
677
|
+
super.loadRouteTranslationsCore(e, n, a, s), this._revision.value++, this.notifyListeners();
|
|
660
678
|
}
|
|
661
679
|
mergeTranslations(e, n, a) {
|
|
662
680
|
this.helper.mergeTranslation(e, n, a, !0), this._revision.value++, this.notifyListeners();
|
|
@@ -664,23 +682,15 @@ class ue extends ae {
|
|
|
664
682
|
clearCache() {
|
|
665
683
|
super.clearCache(), this._revision.value++, this.notifyListeners();
|
|
666
684
|
}
|
|
685
|
+
onTranslationsChanged() {
|
|
686
|
+
this._revision.value++, this.notifyListeners();
|
|
687
|
+
}
|
|
667
688
|
subscribeToChanges(e) {
|
|
668
689
|
return this.listeners.add(e), () => this.listeners.delete(e);
|
|
669
690
|
}
|
|
670
691
|
notifyListeners() {
|
|
671
692
|
this.listeners.forEach((e) => e());
|
|
672
693
|
}
|
|
673
|
-
getAllTranslations() {
|
|
674
|
-
const e = {};
|
|
675
|
-
for (const [n, a] of this.storage.translations)
|
|
676
|
-
if (!n.includes(":"))
|
|
677
|
-
e[n] = a;
|
|
678
|
-
else {
|
|
679
|
-
const c = n.split(":")[0];
|
|
680
|
-
c && (e[c] || (e[c] = {}), Object.assign(e[c], a));
|
|
681
|
-
}
|
|
682
|
-
return e;
|
|
683
|
-
}
|
|
684
694
|
getStorage() {
|
|
685
695
|
return this.storage;
|
|
686
696
|
}
|
|
@@ -691,8 +701,8 @@ class ue extends ae {
|
|
|
691
701
|
return e;
|
|
692
702
|
}
|
|
693
703
|
}
|
|
694
|
-
function
|
|
695
|
-
const { routingStrategy: e, locales: n, defaultLocale: a, ...
|
|
704
|
+
function me(t) {
|
|
705
|
+
const { routingStrategy: e, locales: n, defaultLocale: a, ...s } = t, o = new ue(s);
|
|
696
706
|
let u = null, d = e || null;
|
|
697
707
|
return {
|
|
698
708
|
global: o,
|
|
@@ -702,19 +712,19 @@ function ye(t) {
|
|
|
702
712
|
},
|
|
703
713
|
// Method for setting adapter after creation
|
|
704
714
|
install(r) {
|
|
705
|
-
u = r, r.provide(N, o), d && r.provide(E, d), n && r.provide(
|
|
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);
|
|
706
716
|
}
|
|
707
717
|
};
|
|
708
718
|
}
|
|
709
|
-
function
|
|
710
|
-
const a = e.map((o) => o.code),
|
|
711
|
-
const
|
|
712
|
-
r !== void 0 && a.includes(r) &&
|
|
713
|
-
const
|
|
714
|
-
return u === n ?
|
|
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}`;
|
|
715
725
|
};
|
|
716
726
|
return {
|
|
717
|
-
linkComponent:
|
|
727
|
+
linkComponent: oe,
|
|
718
728
|
getCurrentPath: () => t.currentRoute.value.path,
|
|
719
729
|
push: (o) => {
|
|
720
730
|
t.push(o.path).catch(() => {
|
|
@@ -724,7 +734,7 @@ function me(t, e, n) {
|
|
|
724
734
|
t.replace(o.path).catch(() => {
|
|
725
735
|
});
|
|
726
736
|
},
|
|
727
|
-
resolvePath: (o, u) =>
|
|
737
|
+
resolvePath: (o, u) => s(o, u),
|
|
728
738
|
getRoute: () => ({
|
|
729
739
|
fullPath: t.currentRoute.value.fullPath,
|
|
730
740
|
query: t.currentRoute.value.query
|
|
@@ -733,19 +743,19 @@ function me(t, e, n) {
|
|
|
733
743
|
}
|
|
734
744
|
export {
|
|
735
745
|
Le as FormatService,
|
|
736
|
-
|
|
737
|
-
|
|
746
|
+
Q as I18nDefaultLocaleKey,
|
|
747
|
+
re as I18nGroup,
|
|
738
748
|
N as I18nInjectionKey,
|
|
739
749
|
le as I18nLink,
|
|
740
|
-
|
|
750
|
+
J as I18nLocalesKey,
|
|
741
751
|
ie as I18nSwitcher,
|
|
742
752
|
ce as I18nT,
|
|
743
753
|
ue as VueI18n,
|
|
744
|
-
|
|
745
|
-
|
|
754
|
+
me as createI18n,
|
|
755
|
+
ve as createVueRouterAdapter,
|
|
746
756
|
ke as defaultPlural,
|
|
747
|
-
|
|
757
|
+
Se as interpolate,
|
|
748
758
|
se as useI18n,
|
|
749
|
-
|
|
759
|
+
ye as useLocaleHead
|
|
750
760
|
};
|
|
751
761
|
//# sourceMappingURL=index.mjs.map
|