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