@i18n-micro/vue 1.3.3 → 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.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { defineComponent as B, inject as k, h as y, computed as C, ref as q, onMounted as Q, onUnmounted as X, nextTick as Y, shallowRef as K } from "vue";
2
- import { BaseI18n as ee } from "@i18n-micro/core";
3
- import { FormatService as me, defaultPlural as ve, interpolate as be } from "@i18n-micro/core";
4
- import { RouterLink as te } from "vue-router";
5
- const E = /* @__PURE__ */ Symbol("i18n"), G = /* @__PURE__ */ Symbol("i18n-locales"), Z = /* @__PURE__ */ Symbol("i18n-default-locale"), A = /* @__PURE__ */ Symbol("i18n-router-strategy"), ne = B({
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 a = k(E);
19
- if (!a)
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 r = (c, o) => a.t(`${t.prefix}.${c}`, o, void 0, a.getRoute());
22
- return () => y(
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: r })
27
+ e.default?.({ prefix: t.prefix, t: a })
28
28
  );
29
29
  }
30
- }), ae = B({
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 a = k(E), r = k(A, void 0);
48
- if (!a)
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 = C(() => typeof t.to == "string" ? /^(?:https?:\/\/|\/\/|[a-zA-Z0-9-]+\.[a-zA-Z]{2,})|tel:|mailto:/.test(t.to) : !1), o = 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 n = t.localeRoute(t.to);
55
- return typeof n == "string" ? n : n.path || "/";
54
+ const r = t.localeRoute(t.to);
55
+ return typeof r == "string" ? r : r.path || "/";
56
56
  }
57
- if (!r?.resolvePath)
57
+ if (!a?.resolvePath)
58
58
  return typeof t.to == "string" ? t.to : t.to.path || "/";
59
- const l = r.resolvePath(t.to, a.locale.value);
59
+ const l = a.resolvePath(t.to, n.locale.value);
60
60
  return typeof l == "string" ? l : l.path || "/";
61
- }), u = C(() => {
62
- if (c.value || !r)
61
+ }), u = I(() => {
62
+ if (c.value || !a)
63
63
  return !1;
64
- const l = r.getCurrentPath().replace(/\/$/, ""), n = o.value.replace(/\/$/, "");
65
- return l === n;
66
- }), d = C(() => u.value ? t.activeStyle : {});
67
- return () => c.value ? y(
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
- ) : r?.linkComponent ? y(
77
- r.linkComponent,
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
- ) : y(
83
+ ) : p(
84
84
  "a",
85
85
  {
86
86
  href: o.value,
87
87
  style: d.value,
88
88
  onClick: (l) => {
89
- l.preventDefault(), r ? r.push({ path: o.value }) : window.location.href = o.value;
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
- }), re = B({
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 a = k(E), r = k(A, void 0), c = k(G, void 0);
157
- if (!a)
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 = C(() => t.locales || c || []), u = C(() => t.currentLocale !== void 0 ? typeof t.currentLocale == "function" ? t.currentLocale() : t.currentLocale : a.locale.value), d = C(() => t.getLocaleName ? t.getLocaleName() || null : o.value.find((p) => p.code === a.locale.value)?.displayName || null), l = q(!1), n = q(null), i = (s) => {
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 = C(() => {
166
- const s = o.value.find((p) => p.code === u.value);
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 Y(), t.switchLocale) {
169
+ if (l.value = !1, await ne(), t.switchLocale) {
170
170
  t.switchLocale(s);
171
171
  return;
172
172
  }
173
- if (a.locale.value = s, !r)
173
+ if (n.locale.value = s, !a)
174
174
  return;
175
- const p = r.getCurrentPath(), v = t.localeRoute ? (() => {
176
- const g = t.localeRoute(p, s);
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
- })() : r?.resolvePath ? (() => {
179
- const g = r.resolvePath(p, s);
178
+ })() : a?.resolvePath ? (() => {
179
+ const g = a.resolvePath(y, s);
180
180
  return typeof g == "string" ? g : g.path || "/";
181
- })() : p;
182
- r.push({ path: v });
183
- }, S = {
181
+ })() : y;
182
+ a.push({ path: v });
183
+ }, w = {
184
184
  position: "relative",
185
185
  display: "inline-block",
186
186
  verticalAlign: "middle"
187
- }, R = {
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
- }, T = {
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
- }, O = {
209
+ }, D = {
210
210
  margin: "0",
211
211
  padding: "0"
212
- }, j = {
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] : [], x = (s) => {
228
+ }, L = (s) => s ? Array.isArray(s) ? s : [s] : [], C = (s) => {
229
229
  if (!l.value) return;
230
- const p = s.target;
231
- if (!p || !n.value) return;
232
- const v = n.value.contains(p), g = p.closest(".i18n-switcher-button") !== null;
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 Q(() => {
236
- document.addEventListener("click", x);
237
- }), X(() => {
238
- document.removeEventListener("click", x);
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 p = [];
243
- if (e["before-selected-locale"] && p.push(...L(e["before-selected-locale"]())), p.push(y("span", m.value)), e["after-selected-locale"] && p.push(...L(e["after-selected-locale"]())), p.push(
244
- y(
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
- y(
256
+ p(
257
257
  "button",
258
258
  {
259
259
  class: "i18n-switcher-button",
260
- style: { ...R, ...t.customButtonStyle },
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
- p
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 M = [];
274
- e["before-item"] && M.push(...L(e["before-item"]({ locale: g })));
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 N = typeof window < "u" ? window.location.pathname : "/", W = t.localeRoute ? t.localeRoute(N, g.code) : r?.resolvePath ? r.resolvePath(N, g.code) : N, D = typeof W == "string" ? W : W.path || "#", U = g.code === u.value;
278
- M.push(
279
- y(
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 D == "string" ? D : "#",
283
+ href: typeof F == "string" ? F : "#",
284
284
  style: {
285
- ...j,
286
- ...U ? $ : {},
285
+ ...O,
286
+ ...M ? $ : {},
287
287
  ...t.customLinkStyle
288
288
  },
289
289
  // Prevent default navigation, use only handleSwitchLocale
290
- onClick: (F) => {
291
- F.preventDefault(), F.stopPropagation(), b(g.code);
290
+ onClick: (A) => {
291
+ A.preventDefault(), A.stopPropagation(), b(g.code);
292
292
  }
293
293
  },
294
294
  _
295
295
  )
296
- ), e["after-item"] && M.push(...L(e["after-item"]({ locale: g }))), v.push(
297
- y(
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: { ...O, ...t.customItemStyle }
301
+ style: { ...D, ...t.customItemStyle }
302
302
  },
303
- M
303
+ T
304
304
  )
305
305
  );
306
306
  }), e["after-dropdown-items"] && v.push(...L(e["after-dropdown-items"]())), s.push(
307
- y(
307
+ p(
308
308
  "ul",
309
309
  {
310
310
  class: "i18n-switcher-dropdown",
311
- style: { ...T, ...t.customDropdownStyle }
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"]())), y(
317
+ return e["after-dropdown"] && s.push(...L(e["after-dropdown"]())), p(
318
318
  "div",
319
319
  {
320
- ref: n,
320
+ ref: r,
321
321
  class: "i18n-switcher-wrapper",
322
- style: { ...S, ...t.customWrapperStyle }
322
+ style: { ...w, ...t.customWrapperStyle }
323
323
  },
324
324
  s
325
325
  );
326
326
  };
327
327
  }
328
- }), oe = B({
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: a }) {
373
- const r = k(E);
374
- if (!r)
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 = r.getRoute();
377
+ const c = {}, o = a.getRoute();
378
378
  if (t.number !== void 0) {
379
- const n = Number(t.number), i = r.tn(n), h = r.t(t.keypath, { number: i, ...t.params }, void 0, o);
380
- return y(t.tag, { ...a, innerHTML: h });
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 n = r.td(t.date), i = r.t(t.keypath, { date: n, ...t.params }, void 0, o);
384
- return y(t.tag, { ...a, innerHTML: i });
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 n = r.tdr(t.relativeDate), i = r.t(t.keypath, { relativeDate: n, ...t.params }, void 0, o);
388
- return y(t.tag, { ...a, innerHTML: i });
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 n = Number.parseInt(t.plural.toString(), 10);
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
- n,
395
+ r,
396
396
  t.params,
397
- r.locale.value,
398
- (h, m, b) => r.t(h, m, b, o)
397
+ a.locale.value,
398
+ (h, m, b) => a.t(h, m, b, o)
399
399
  );
400
- return y(t.tag, { ...a, innerHTML: i || "" });
400
+ return p(t.tag, { ...n, innerHTML: i || "" });
401
401
  } else {
402
- const i = r.tc(t.keypath, { count: n, ...t.params });
403
- return y(t.tag, { ...a, innerHTML: i });
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 = (r.t(t.keypath, { ...t.params, ...c }, void 0, o) ?? "").toString();
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 y(t.tag, { ...a, innerHTML: u });
410
+ return p(t.tag, { ...n, innerHTML: u });
411
411
  if (e.default)
412
- return y(t.tag, a, e.default({ translation: u }));
412
+ return p(t.tag, n, e.default({ translation: u }));
413
413
  const d = [];
414
414
  let l = 0;
415
- for (const [n, i] of Object.entries(e)) {
416
- if (n === "default") continue;
417
- const h = `{${n}}`, m = u.indexOf(h, l);
418
- m !== -1 && (m > l && d.push(u.slice(l, m)), i && d.push(y(i)), l = m + h.length);
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 ? y(t.tag, a, e.default({ children: d })) : d.length > 0 ? y(t.tag, a, d) : y(t.tag, a, u);
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 le(t) {
425
- const e = k(E), a = k(A, void 0), r = k(G, void 0), c = k(Z, void 0);
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 (!r)
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 || r, u = t?.defaultLocale || c, d = (l, n) => a?.resolvePath ? a.resolvePath(l, n || e.locale.value) : l;
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: C({
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((n) => n.code === e.locale.value)?.displayName || null,
472
+ getLocaleName: () => o.find((r) => r.code === e.locale.value)?.displayName || null,
447
473
  // Routing helpers
448
474
  localeRoute: d,
449
- localePath: (l, n) => {
450
- const i = d(l, n);
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, a) {
455
- const n = a.getCurrentPath(), i = d(n, l);
456
- a.push(typeof i == "string" ? { path: i } : { path: i.path || "/" });
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 de(t = {}) {
479
- const { addDirAttribute: e = !0, identifierAttribute: a = "id", addSeoAttributes: r = !0, baseUrl: c = "/" } = t, { getLocale: o, getLocales: u, localeRoute: d } = le(), l = k(A, void 0), n = q({
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 S = new URL(m, "http://localhost"), R = new URLSearchParams(S.search), T = {};
486
- for (const j of b)
487
- R.has(j) && (T[j] = R.get(j));
488
- const O = new URLSearchParams(T);
489
- return O.toString() ? `${S.pathname}?${O.toString()}` : S.pathname;
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
- n.value = { htmlAttrs: {}, link: [], meta: [] };
519
+ r.value = { htmlAttrs: {}, link: [], meta: [] };
494
520
  return;
495
521
  }
496
- const b = o(), S = u(), R = S.find((f) => f.code === b);
497
- if (!R)
522
+ const b = o(), w = u(), S = w.find((f) => f.code === b);
523
+ if (!S)
498
524
  return;
499
- const T = R.iso || b, O = R.og || T, j = R.dir || "auto";
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 = S.find((f) => z[0] === f.code);
503
- let L = $, x, s;
504
- const p = typeof c == "function" ? c() : c;
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) || "/", x = i(L, m);
532
+ L = $.slice(V.code.length + 1) || "/", C = i(L, m);
507
533
  const f = `/${b}`;
508
- s = `${p}${f}${x.startsWith("/") ? "" : "/"}${x}`;
534
+ s = `${y}${f}${C.startsWith("/") ? "" : "/"}${C}`;
509
535
  } else
510
- x = i($, m), s = `${p}${x.startsWith("/") ? "" : "/"}${x}`;
511
- if (n.value = {
512
- htmlAttrs: {
513
- lang: T,
514
- ...e ? { dir: j } : {}
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
- const v = S.filter((f) => !f.disabled && f.seo !== !1), g = {
521
- [a]: "i18n-og",
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: O
524
- }, M = {
525
- [a]: "i18n-og-url",
550
+ content: D
551
+ } : null, _ = {
552
+ [n]: "i18n-og-url",
526
553
  property: "og:url",
527
554
  content: s
528
- }, _ = v.filter((f) => f.code !== b).map((f) => {
529
- const I = f.og || f.iso || f.code;
530
- return {
531
- [a]: `i18n-og-alt-${I}`,
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: I
534
- };
535
- }), N = {
536
- [a]: "i18n-can",
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
- }, W = v.flatMap((f) => {
566
+ }, F = g.flatMap((f) => {
540
567
  if (!d || !l)
541
568
  return [];
542
- const I = l.getCurrentPath(), w = d(I, f.code), P = typeof w == "string" ? w : w?.path || "/";
543
- if (!P)
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
- P.startsWith("http://") || P.startsWith("https://") ? H = P : H = `${typeof c == "function" ? c() : c}${P.startsWith("/") ? "" : "/"}${P}`;
547
- const J = [
573
+ R.startsWith("http://") || R.startsWith("https://") ? H = R : H = `${typeof c == "function" ? c() : c}${R.startsWith("/") ? "" : "/"}${R}`;
574
+ const Q = [
548
575
  {
549
- [a]: `i18n-alternate-${f.code}`,
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 && J.push({
556
- [a]: `i18n-alternate-${f.iso}`,
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
- }), J;
561
- }), D = k(Z, void 0);
562
- let U = null;
563
- const F = D ? S.find((f) => f.code === D) : void 0;
564
- if (d && l && D && F?.seo !== !1) {
565
- const f = l.getCurrentPath(), I = d(f, D), w = typeof I == "string" ? I : I?.path || "/";
566
- if (w) {
567
- let P;
568
- w.startsWith("http://") || w.startsWith("https://") ? P = w : P = `${typeof c == "function" ? c() : c}${w.startsWith("/") ? "" : "/"}${w}`, U = {
569
- [a]: "i18n-xd",
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: P,
598
+ href: R,
572
599
  hreflang: "x-default"
573
600
  };
574
601
  }
575
602
  }
576
- n.value.meta = [g, M, ..._], n.value.link = [N, ...W, ...U ? [U] : []];
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: n,
610
+ metaObject: r,
580
611
  updateMeta: h
581
612
  };
582
613
  }
583
- class ie extends ee {
614
+ class ue extends ae {
584
615
  constructor(e) {
585
- const a = {
616
+ const n = {
586
617
  translations: /* @__PURE__ */ new Map()
587
618
  };
588
619
  if (super({
589
- storage: a,
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 = a, this._locale = K(e.locale), this._fallbackLocale = K(e.fallbackLocale || e.locale), this._currentRoute = K("index"), this._revision = K(0), e.messages)
594
- for (const [r, c] of Object.entries(e.messages))
595
- this.helper.loadTranslations(r, c);
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, a, r = !0) {
625
- super.loadTranslationsCore(e, a, r), this._revision.value++, this.notifyListeners();
655
+ addTranslations(e, n, a = !0) {
656
+ super.loadTranslationsCore(e, n, a), this._revision.value++, this.notifyListeners();
626
657
  }
627
- addRouteTranslations(e, a, r, c = !0) {
628
- super.loadRouteTranslationsCore(e, a, r, c), this._revision.value++, this.notifyListeners();
658
+ addRouteTranslations(e, n, a, c = !0) {
659
+ super.loadRouteTranslationsCore(e, n, a, c), this._revision.value++, this.notifyListeners();
629
660
  }
630
- mergeTranslations(e, a, r) {
631
- this.helper.mergeTranslation(e, a, r, !0), this._revision.value++, this.notifyListeners();
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 [a, r] of this.storage.translations)
645
- if (!a.includes(":"))
646
- e[a] = r;
675
+ for (const [n, a] of this.storage.translations)
676
+ if (!n.includes(":"))
677
+ e[n] = a;
647
678
  else {
648
- const c = a.split(":")[0];
649
- c && (e[c] || (e[c] = {}), Object.assign(e[c], r));
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 [a, r] of this.storage.translations)
659
- e[a] = r;
689
+ for (const [n, a] of this.storage.translations)
690
+ e[n] = a;
660
691
  return e;
661
692
  }
662
693
  }
663
- function he(t) {
664
- const { routingStrategy: e, locales: a, defaultLocale: r, ...c } = t, o = new ie(c);
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: (n) => {
670
- d = n, u && u.provide(A, n);
700
+ setRoutingStrategy: (r) => {
701
+ d = r, u && u.provide(E, r);
671
702
  },
672
703
  // Method for setting adapter after creation
673
- install(n) {
674
- u = n, n.provide(E, o), d && n.provide(A, d), a && n.provide(G, a), r && n.provide(Z, r), n.config.globalProperties.$t = (i, h, m, b) => o.t(i, h, m, b), n.config.globalProperties.$ts = (i, h, m, b) => o.ts(i, h, m, b), n.config.globalProperties.$tc = (i, h, m) => o.tc(i, h, m), n.config.globalProperties.$tn = (i, h) => o.tn(i, h), n.config.globalProperties.$td = (i, h) => o.td(i, h), n.config.globalProperties.$tdr = (i, h) => o.tdr(i, h), n.config.globalProperties.$has = (i, h) => o.has(i, h), n.config.globalProperties.$i18n = o, n.component("I18nT", oe), n.component("I18nLink", ae), n.component("I18nGroup", ne), n.component("I18nSwitcher", re);
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 ge(t, e, a) {
679
- const r = e.map((o) => o.code), c = (o, u) => {
680
- const l = (typeof o == "string" ? o : o.path || "/").split("/").filter(Boolean), n = l[0];
681
- n !== void 0 && r.includes(n) && l.shift();
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 === a ? i : `/${u}${i === "/" ? "" : i}`;
714
+ return u === n ? i : `/${u}${i === "/" ? "" : i}`;
684
715
  };
685
716
  return {
686
- linkComponent: te,
717
+ linkComponent: re,
687
718
  getCurrentPath: () => t.currentRoute.value.path,
688
719
  push: (o) => {
689
720
  t.push(o.path).catch(() => {
@@ -701,20 +732,20 @@ function ge(t, e, a) {
701
732
  };
702
733
  }
703
734
  export {
704
- me as FormatService,
705
- Z as I18nDefaultLocaleKey,
706
- ne as I18nGroup,
707
- E as I18nInjectionKey,
708
- ae as I18nLink,
709
- G as I18nLocalesKey,
710
- re as I18nSwitcher,
711
- oe as I18nT,
712
- ie as VueI18n,
713
- he as createI18n,
714
- ge as createVueRouterAdapter,
715
- ve as defaultPlural,
716
- be as interpolate,
717
- le as useI18n,
718
- de as useLocaleHead
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
  };
720
751
  //# sourceMappingURL=index.mjs.map