@i18n-micro/vue 1.3.7 → 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.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { defineComponent as z, inject as k, h as g, computed as S, ref as G, onMounted as ee, onUnmounted as te, nextTick as ne, shallowRef as B } from "vue";
2
- import { BaseI18n as ae } from "@i18n-micro/core";
3
- import { FormatService as Le, defaultPlural as ke, interpolate as Se } from "@i18n-micro/core";
4
- import { RouterLink as oe } from "vue-router";
5
- const N = /* @__PURE__ */ Symbol("i18n"), J = /* @__PURE__ */ Symbol("i18n-locales"), Q = /* @__PURE__ */ Symbol("i18n-default-locale"), E = /* @__PURE__ */ Symbol("i18n-router-strategy"), re = z({
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 n = k(N);
19
- if (!n)
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 a = (s, o) => n.t(`${t.prefix}.${s}`, o, void 0, n.getRoute());
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: a })
27
+ e.default?.({ prefix: t.prefix, t: o })
28
28
  );
29
29
  }
30
- }), le = z({
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 n = k(N), a = k(E, void 0);
48
- if (!n)
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 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)
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 r = t.localeRoute(t.to);
55
- return typeof r == "string" ? r : r.path || "/";
54
+ const n = t.localeRoute(t.to);
55
+ return typeof n == "string" ? n : n.path || "/";
56
56
  }
57
- if (!a?.resolvePath)
57
+ if (!o?.resolvePath)
58
58
  return typeof t.to == "string" ? t.to : t.to.path || "/";
59
- const i = a.resolvePath(t.to, n.locale.value);
59
+ const i = o.resolvePath(t.to, a.locale.value);
60
60
  return typeof i == "string" ? i : i.path || "/";
61
- }), u = S(() => {
62
- if (s.value || !a)
61
+ }), s = k(() => {
62
+ if (c.value || !o)
63
63
  return !1;
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(
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: o.value,
70
+ href: r.value,
71
71
  target: "_blank",
72
72
  rel: "noopener noreferrer",
73
- style: d.value
73
+ style: f.value
74
74
  },
75
75
  e.default?.()
76
- ) : a?.linkComponent ? g(
77
- a.linkComponent,
76
+ ) : o?.linkComponent ? g(
77
+ o.linkComponent,
78
78
  {
79
- to: o.value,
80
- style: d.value
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: o.value,
87
- style: d.value,
86
+ href: r.value,
87
+ style: f.value,
88
88
  onClick: (i) => {
89
- i.preventDefault(), a ? a.push({ path: o.value }) : window.location.href = o.value;
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
- }), ie = z({
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 n = k(N), a = k(E, void 0), s = k(J, void 0);
164
- if (!n)
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 (!s && !t.locales)
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 o = S(() => t.locales || s || []), u = S(() => o.value.filter((c) => !c.disabled)), d = S(() => t.currentLocale !== void 0 ? typeof t.currentLocale == "function" ? t.currentLocale() : t.currentLocale : n.locale.value), i = S(() => o.value.some((c) => c.code === d.value && c.disabled)), r = S(() => t.getLocaleName ? t.getLocaleName() || null : o.value.find((y) => y.code === n.locale.value)?.displayName || null), l = G(!1), m = G(null), v = (c) => {
171
- c && (c.stopPropagation(), c.preventDefault()), l.value = !l.value;
172
- }, b = (c) => t.customLabels[c.code] || c.displayName || c.code, w = S(() => {
173
- const c = o.value.find((y) => y.code === d.value);
174
- return c ? b(c) : r.value || d.value;
175
- }), P = async (c) => {
176
- if (l.value = !1, await ne(), t.switchLocale) {
177
- t.switchLocale(c);
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 (n.locale.value = c, !a)
180
+ if (a.locale.value = u, !o)
181
181
  return;
182
- const y = a.getCurrentPath(), L = t.localeRoute ? (() => {
183
- const h = t.localeRoute(y, c);
184
- return typeof h == "string" ? h : h.path || "/";
185
- })() : a?.resolvePath ? (() => {
186
- const h = a.resolvePath(y, c);
187
- return typeof h == "string" ? h : h.path || "/";
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
- a.push({ path: L });
190
- }, _ = {
189
+ o.push({ path: b });
190
+ }, R = {
191
191
  position: "relative",
192
192
  display: "inline-block",
193
193
  verticalAlign: "middle"
194
- }, I = {
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
- }, O = {
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
- }, C = {
216
+ }, _ = {
217
217
  margin: "0",
218
218
  padding: "0"
219
- }, q = {
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
- }, V = {
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
- }, F = {
231
+ }, V = {
232
232
  marginLeft: "8px",
233
233
  display: "inline-block",
234
234
  transition: "transform 0.3s ease"
235
- }, T = {
235
+ }, F = {
236
236
  transform: "rotate(180deg)"
237
- }, p = (c) => c ? Array.isArray(c) ? c : [c] : [], U = (c) => {
237
+ }, p = (u) => u ? Array.isArray(u) ? u : [u] : [], O = (u) => {
238
238
  if (!l.value) return;
239
- const y = c.target;
239
+ const y = u.target;
240
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);
241
+ const b = m.value.contains(y), d = y.closest(".i18n-switcher-button") !== null;
242
+ !b && !d && (l.value = !1);
243
243
  };
244
- return ee(() => {
245
- document.addEventListener("click", U);
246
- }), te(() => {
247
- document.removeEventListener("click", U);
244
+ return ae(() => {
245
+ document.addEventListener("click", O);
246
+ }), oe(() => {
247
+ document.removeEventListener("click", O);
248
248
  }), () => {
249
- const c = [];
250
- e["before-button"] && c.push(...p(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", w.value)), e["after-selected-locale"] && y.push(...p(e["after-selected-locale"]())), y.push(
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
- ...F,
258
- ...l.value ? T : {},
257
+ ...V,
258
+ ...l.value ? F : {},
259
259
  ...t.customIconStyle
260
260
  }
261
261
  },
262
262
  "▼"
263
263
  )
264
- ), c.push(
264
+ ), u.push(
265
265
  g(
266
266
  "button",
267
267
  {
268
268
  class: "i18n-switcher-button",
269
269
  style: {
270
- ...I,
270
+ ...M,
271
271
  ...t.customButtonStyle,
272
272
  ...i.value ? t.customDisabledLinkStyle : {}
273
273
  },
274
- onClick: (L) => {
275
- L.preventDefault(), L.stopPropagation(), v(L);
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"] && 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(
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-${h.code}`,
296
- href: typeof A == "string" ? A : "#",
295
+ class: `switcher-locale-${d.code}`,
296
+ href: typeof j == "string" ? j : "#",
297
297
  style: {
298
- ...q,
299
- ...K ? V : {},
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
- ...K ? t.customActiveLinkStyle : {}
303
+ ...N ? t.customActiveLinkStyle : {}
304
304
  },
305
305
  // Prevent default navigation, use only handleSwitchLocale
306
- onClick: (f) => {
307
- f.preventDefault(), f.stopPropagation(), P(h.code);
306
+ onClick: (K) => {
307
+ K.preventDefault(), K.stopPropagation(), P(d.code);
308
308
  }
309
309
  },
310
- M
310
+ E
311
311
  )
312
- ), e["after-item"] && j.push(...p(e["after-item"]({ locale: h }))), L.push(
312
+ ), e["after-item"] && A.push(...p(e["after-item"]({ locale: d }))), b.push(
313
313
  g(
314
314
  "li",
315
315
  {
316
- key: h.code,
317
- style: { ...C, ...t.customItemStyle }
316
+ key: d.code,
317
+ style: { ..._, ...t.customItemStyle }
318
318
  },
319
- j
319
+ A
320
320
  )
321
321
  );
322
- }), e["after-dropdown-items"] && L.push(...p(e["after-dropdown-items"]())), c.push(
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: { ...O, ...t.customDropdownStyle }
327
+ style: { ...D, ...t.customDropdownStyle }
328
328
  },
329
- L
329
+ b
330
330
  )
331
331
  );
332
332
  }
333
- return e["after-dropdown"] && c.push(...p(e["after-dropdown"]())), g(
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: { ..._, ...t.customWrapperStyle }
338
+ style: { ...R, ...t.customWrapperStyle }
339
339
  },
340
- c
340
+ u
341
341
  );
342
342
  };
343
343
  }
344
- }), ce = z({
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: n }) {
389
- const a = k(N);
390
- if (!a)
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 s = {}, o = a.getRoute();
393
+ const c = {}, r = o.getRoute();
394
394
  if (t.number !== void 0) {
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 });
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 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 });
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 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 });
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 r = Number.parseInt(t.plural.toString(), 10);
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
- r,
411
+ n,
412
412
  t.params,
413
- a.locale.value,
414
- (m, v, b) => a.t(m, v, b, o)
413
+ o.locale.value,
414
+ (m, v, L) => o.t(m, v, L, r)
415
415
  );
416
- return g(t.tag, { ...n, innerHTML: l || "" });
416
+ return g(t.tag, { ...a, innerHTML: l || "" });
417
417
  } else {
418
- const l = a.tc(t.keypath, { count: r, ...t.params });
419
- return g(t.tag, { ...n, innerHTML: l });
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 u = (a.t(t.keypath, { ...t.params, ...s }, void 0, o) ?? "").toString();
423
- if (t.hideIfEmpty && !u.trim())
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, { ...n, innerHTML: u });
426
+ return g(t.tag, { ...a, innerHTML: s });
427
427
  if (e.default)
428
- return g(t.tag, n, e.default({ translation: u }));
429
- const d = [];
428
+ return g(t.tag, a, e.default({ translation: s }));
429
+ const f = [];
430
430
  let i = 0;
431
- for (const [r, l] of Object.entries(e)) {
432
- if (r === "default") continue;
433
- const m = `{${r}}`, v = u.indexOf(m, i);
434
- v !== -1 && (v > i && d.push(u.slice(i, v)), l && d.push(g(l)), i = v + m.length);
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 < 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);
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 Z(t) {
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 n = t.iso?.trim();
444
- if (!n) return null;
445
- const a = n.indexOf("_");
446
- if (a > 0) {
447
- const o = n.slice(0, a), u = n.slice(a + 1);
448
- if (o.length >= 2 && u.length === 2)
449
- return `${o.toLowerCase()}_${u.toUpperCase()}`;
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 s = n.indexOf("-");
452
- if (s > 0) {
453
- const o = n.slice(0, s), u = n.slice(s + 1);
454
- if (o.length >= 2 && u.length === 2 && /^[A-Za-z]{2}$/.test(u))
455
- return `${o.toLowerCase()}_${u.toUpperCase()}`;
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 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}'` : "";
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 ${n} for locale '${a}'${s}. Set locale.og (e.g. 'en_US') or use iso with a 2-letter region (e.g. 'en-US').`
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 se(t) {
467
- const e = k(N), n = k(E, void 0), a = k(J, void 0), s = k(Q, void 0);
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 (!a)
496
+ if (!o)
471
497
  throw new Error("[i18n-micro] I18nLocalesKey not provided. Make sure app.provide(I18nLocalesKey, locales) is called.");
472
- if (!s)
498
+ if (!c)
473
499
  throw new Error("[i18n-micro] I18nDefaultLocaleKey not provided. Make sure app.provide(I18nDefaultLocaleKey, defaultLocale) is called.");
474
- const o = t?.locales || a, u = t?.defaultLocale || s, d = (i, r) => n?.resolvePath ? n.resolvePath(i, r || e.locale.value) : i;
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: S({
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: () => o,
487
- defaultLocale: () => u,
488
- getLocaleName: () => o.find((r) => r.code === e.locale.value)?.displayName || null,
512
+ getLocales: () => r,
513
+ defaultLocale: () => s,
514
+ getLocaleName: () => r.find((n) => n.code === e.locale.value)?.displayName || null,
489
515
  // Routing helpers
490
- localeRoute: d,
491
- localePath: (i, r) => {
492
- const l = d(i, r);
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, n) {
497
- const r = n.getCurrentPath(), l = d(r, i);
498
- n.push(typeof l == "string" ? { path: l } : { path: l.path || "/" });
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 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({
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 l(v, b) {
529
- const w = new URL(v, "http://localhost"), P = new URLSearchParams(w.search), _ = {};
530
- for (const O of b)
531
- P.has(O) && (_[O] = P.get(O));
532
- const I = new URLSearchParams(_);
533
- return I.toString() ? `${w.pathname}?${I.toString()}` : w.pathname;
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 m(v = []) {
536
- if (!i) {
537
- r.value = { htmlAttrs: {}, link: [], meta: [] };
561
+ function v(L = []) {
562
+ if (!n) {
563
+ l.value = { htmlAttrs: {}, link: [], meta: [] };
538
564
  return;
539
565
  }
540
- const b = o(), w = u(), P = w.find((f) => f.code === b);
541
- if (!P)
566
+ const T = s(), P = f(), R = P.find((h) => h.code === T);
567
+ if (!R)
542
568
  return;
543
- const _ = P.iso || b, I = Z(P), O = P.dir || "auto";
544
- let C = i.getCurrentPath();
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 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;
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) || "/", T = l(F, v);
551
- const f = `/${b}`;
552
- p = `${U}${f}${T.startsWith("/") ? "" : "/"}${T}`;
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
- T = l(C, v), p = `${U}${T.startsWith("/") ? "" : "/"}${T}`;
555
- const c = {
556
- lang: _,
557
- ...e ? { dir: O } : {}
580
+ p = m(C, L), O = `${u}${p.startsWith("/") ? "" : "/"}${p}`;
581
+ const y = {
582
+ lang: M,
583
+ ...e ? { dir: _ } : {}
558
584
  };
559
- if (!a) {
560
- r.value = { htmlAttrs: c, link: [], meta: [] };
585
+ if (!o) {
586
+ l.value = { htmlAttrs: y, link: [], meta: [] };
561
587
  return;
562
588
  }
563
- const y = w.filter((f) => !f.disabled && f.seo !== !1);
564
- I || Y(P, { tag: "og:locale" });
565
- const L = I ? {
566
- [n]: "i18n-og",
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: I
569
- } : null, h = {
570
- [n]: "i18n-og-url",
594
+ content: D
595
+ } : null, A = {
596
+ [a]: "i18n-og-url",
571
597
  property: "og:url",
572
- content: p
573
- }, j = y.filter((f) => f.code !== b).map((f) => {
574
- const x = Z(f);
598
+ content: O
599
+ }, E = b.filter((h) => h.code !== T).map((h) => {
600
+ const x = X(h);
575
601
  return x ? {
576
- [n]: `i18n-og-alt-${x}`,
602
+ [a]: `i18n-og-alt-${x}`,
577
603
  property: "og:locale:alternate",
578
604
  content: x
579
- } : (Y(f, { tag: "og:locale:alternate" }), null);
580
- }).filter((f) => f !== null), M = {
581
- [n]: "i18n-can",
605
+ } : (ne(h, { tag: "og:locale:alternate" }), null);
606
+ }).filter((h) => h !== null), B = {
607
+ [a]: "i18n-can",
582
608
  rel: "canonical",
583
- href: p
584
- }, W = y.flatMap((f) => {
585
- if (!d || !i)
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
- let H;
591
- $.startsWith("http://") || $.startsWith("https://") ? H = $ : H = `${typeof s == "function" ? s() : s}${$.startsWith("/") ? "" : "/"}${$}`;
592
- const X = [
593
- {
594
- [n]: `i18n-alternate-${f.code}`,
595
- rel: "alternate",
596
- href: H,
597
- hreflang: f.code
598
- }
599
- ];
600
- return f.iso && f.iso !== f.code && X.push({
601
- [n]: `i18n-alternate-${f.iso}`,
602
- rel: "alternate",
603
- href: H,
604
- hreflang: f.iso
605
- }), X;
606
- }), D = k(Q, void 0);
607
- let A = null;
608
- const K = D ? w.find((f) => f.code === D) : void 0;
609
- if (d && i && D && K?.seo !== !1) {
610
- const f = i.getCurrentPath(), x = d(f, D), R = typeof x == "string" ? x : x?.path || "/";
611
- if (R) {
612
- let $;
613
- R.startsWith("http://") || R.startsWith("https://") ? $ = R : $ = `${typeof s == "function" ? s() : s}${R.startsWith("/") ? "" : "/"}${R}`, A = {
614
- [n]: "i18n-xd",
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
- r.value = {
622
- htmlAttrs: c,
623
- meta: [...L ? [L] : [], h, ...j],
624
- link: [M, ...W, ...A ? [A] : []]
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: r,
629
- updateMeta: m
653
+ metaObject: l,
654
+ updateMeta: v
630
655
  };
631
656
  }
632
- class ue extends ae {
657
+ class ge extends le {
633
658
  constructor(e) {
634
- const n = {
659
+ const a = {
635
660
  translations: /* @__PURE__ */ new Map()
636
661
  };
637
662
  if (super({
638
- storage: n,
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 = 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);
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, n, a = !0) {
674
- super.loadTranslationsCore(e, n, a), this._revision.value++, this.notifyListeners();
698
+ addTranslations(e, a, o = !0) {
699
+ super.loadTranslationsCore(e, a, o), this._revision.value++, this.notifyListeners();
675
700
  }
676
- addRouteTranslations(e, n, a, s = !0) {
677
- super.loadRouteTranslationsCore(e, n, a, s), this._revision.value++, this.notifyListeners();
701
+ addRouteTranslations(e, a, o, c = !0) {
702
+ super.loadRouteTranslationsCore(e, a, o, c), this._revision.value++, this.notifyListeners();
678
703
  }
679
- mergeTranslations(e, n, a) {
680
- this.helper.mergeTranslation(e, n, a, !0), this._revision.value++, this.notifyListeners();
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 [n, a] of this.storage.translations)
700
- e[n] = a;
724
+ for (const [a, o] of this.storage.translations)
725
+ e[a] = o;
701
726
  return e;
702
727
  }
703
728
  }
704
- function me(t) {
705
- const { routingStrategy: e, locales: n, defaultLocale: a, ...s } = t, o = new ue(s);
706
- let u = null, d = e || null;
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: o,
733
+ global: r,
709
734
  // Access to instance outside components
710
- setRoutingStrategy: (r) => {
711
- d = r, u && u.provide(E, r);
735
+ setRoutingStrategy: (n) => {
736
+ f = n, s && s.provide(U, n);
712
737
  },
713
738
  // Method for setting adapter after creation
714
- install(r) {
715
- u = r, r.provide(N, o), d && r.provide(E, d), n && r.provide(J, n), a && r.provide(Q, a), r.config.globalProperties.$t = (l, m, v, b) => o.t(l, m, v, b), r.config.globalProperties.$ts = (l, m, v, b) => o.ts(l, m, v, b), r.config.globalProperties.$tc = (l, m, v) => o.tc(l, m, v), r.config.globalProperties.$tn = o.tn.bind(o), r.config.globalProperties.$td = o.td.bind(o), r.config.globalProperties.$tdr = o.tdr.bind(o), r.config.globalProperties.$has = (l, m) => o.has(l, m), r.config.globalProperties.$i18n = o, r.component("I18nT", ce), r.component("I18nLink", le), r.component("I18nGroup", re), r.component("I18nSwitcher", ie);
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 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();
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 u === n ? l : `/${u}${l === "/" ? "" : l}`;
749
+ return s === a ? l : `/${s}${l === "/" ? "" : l}`;
725
750
  };
726
751
  return {
727
- linkComponent: oe,
752
+ linkComponent: ie,
728
753
  getCurrentPath: () => t.currentRoute.value.path,
729
- push: (o) => {
730
- t.push(o.path).catch(() => {
754
+ push: (r) => {
755
+ t.push(r.path).catch(() => {
731
756
  });
732
757
  },
733
- replace: (o) => {
734
- t.replace(o.path).catch(() => {
758
+ replace: (r) => {
759
+ t.replace(r.path).catch(() => {
735
760
  });
736
761
  },
737
- resolvePath: (o, u) => s(o, u),
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
- Le as FormatService,
746
- Q as I18nDefaultLocaleKey,
747
- re as I18nGroup,
748
- N as I18nInjectionKey,
749
- le as I18nLink,
750
- J as I18nLocalesKey,
751
- ie as I18nSwitcher,
752
- ce as I18nT,
753
- ue as VueI18n,
754
- me as createI18n,
755
- ve as createVueRouterAdapter,
756
- ke as defaultPlural,
757
- Se as interpolate,
758
- se as useI18n,
759
- ye as useLocaleHead
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