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