@i18n-micro/vue 1.3.3 → 1.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.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 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({
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 = (s, o) => n.t(`${t.prefix}.${s}`, o, void 0, n.getRoute());
22
+ return () => g(
23
23
  "div",
24
24
  {
25
25
  class: ["i18n-group", t.groupClass]
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 = z({
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(() => {
51
- if (c.value)
50
+ const s = S(() => typeof t.to == "string" ? /^(?:https?:\/\/|\/\/|[a-zA-Z0-9-]+\.[a-zA-Z]{2,})|tel:|mailto:/.test(t.to) : !1), o = S(() => {
51
+ if (s.value)
52
52
  return t.to;
53
53
  if (t.localeRoute) {
54
- 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);
60
- return typeof l == "string" ? l : l.path || "/";
61
- }), u = C(() => {
62
- if (c.value || !r)
59
+ const i = a.resolvePath(t.to, n.locale.value);
60
+ return typeof i == "string" ? i : i.path || "/";
61
+ }), u = S(() => {
62
+ if (s.value || !a)
63
63
  return !1;
64
- const 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 i = a.getCurrentPath().replace(/\/$/, ""), r = o.value.replace(/\/$/, "");
65
+ return i === r;
66
+ }), d = S(() => u.value ? t.activeStyle : {});
67
+ return () => s.value ? g(
68
68
  "a",
69
69
  {
70
70
  href: o.value,
@@ -73,26 +73,26 @@ const 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 ? g(
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
+ ) : g(
84
84
  "a",
85
85
  {
86
86
  href: o.value,
87
87
  style: d.value,
88
- onClick: (l) => {
89
- l.preventDefault(), r ? r.push({ path: o.value }) : window.location.href = o.value;
88
+ onClick: (i) => {
89
+ i.preventDefault(), a ? a.push({ path: o.value }) : window.location.href = o.value;
90
90
  }
91
91
  },
92
92
  e.default?.()
93
93
  );
94
94
  }
95
- }), re = B({
95
+ }), ie = z({
96
96
  name: "I18nSwitcher",
97
97
  props: {
98
98
  customLabels: {
@@ -123,6 +123,13 @@ const E = /* @__PURE__ */ Symbol("i18n"), G = /* @__PURE__ */ Symbol("i18n-local
123
123
  type: Object,
124
124
  default: () => ({})
125
125
  },
126
+ /**
127
+ * Inline style applied to the switcher button when the *current* locale is
128
+ * marked as `disabled: true` in the locale config.
129
+ *
130
+ * Note: disabled locales are omitted from the dropdown list, but the current
131
+ * locale label is still shown on the button.
132
+ */
126
133
  customDisabledLinkStyle: {
127
134
  type: Object,
128
135
  default: () => ({})
@@ -153,38 +160,38 @@ const E = /* @__PURE__ */ Symbol("i18n"), G = /* @__PURE__ */ Symbol("i18n-local
153
160
  }
154
161
  },
155
162
  setup(t, { slots: e }) {
156
- const a = k(E), r = k(A, void 0), c = k(G, void 0);
157
- if (!a)
163
+ const n = k(N), a = k(E, void 0), s = k(J, void 0);
164
+ if (!n)
158
165
  throw new Error("[i18n-micro] I18nSwitcher: i18n instance not found. Make sure i18n plugin is installed.");
159
- if (!c && !t.locales)
166
+ if (!s && !t.locales)
160
167
  throw new Error(
161
168
  "[i18n-micro] I18nSwitcher: locales not provided. Make sure app.provide(I18nLocalesKey, locales) is called or pass locales prop."
162
169
  );
163
- const o = 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) => {
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);
167
- return s ? h(s) : d.value || u.value;
168
- }), b = async (s) => {
169
- if (l.value = !1, await Y(), t.switchLocale) {
170
- t.switchLocale(s);
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);
171
178
  return;
172
179
  }
173
- if (a.locale.value = s, !r)
180
+ if (n.locale.value = c, !a)
174
181
  return;
175
- const p = r.getCurrentPath(), v = t.localeRoute ? (() => {
176
- const g = t.localeRoute(p, s);
177
- return typeof g == "string" ? g : g.path || "/";
178
- })() : r?.resolvePath ? (() => {
179
- const g = r.resolvePath(p, s);
180
- return typeof g == "string" ? g : g.path || "/";
181
- })() : p;
182
- r.push({ path: v });
183
- }, S = {
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 || "/";
188
+ })() : y;
189
+ a.push({ path: L });
190
+ }, _ = {
184
191
  position: "relative",
185
192
  display: "inline-block",
186
193
  verticalAlign: "middle"
187
- }, R = {
194
+ }, I = {
188
195
  padding: "4px 12px",
189
196
  fontSize: "16px",
190
197
  cursor: "pointer",
@@ -194,7 +201,7 @@ const E = /* @__PURE__ */ Symbol("i18n"), G = /* @__PURE__ */ Symbol("i18n-local
194
201
  display: "flex",
195
202
  alignItems: "center",
196
203
  justifyContent: "space-between"
197
- }, T = {
204
+ }, O = {
198
205
  position: "absolute",
199
206
  top: "100%",
200
207
  left: "0",
@@ -206,126 +213,135 @@ const E = /* @__PURE__ */ Symbol("i18n"), G = /* @__PURE__ */ Symbol("i18n-local
206
213
  margin: "4px 0 0 0",
207
214
  minWidth: "150px",
208
215
  boxShadow: "0 2px 8px rgba(0,0,0,0.15)"
209
- }, O = {
216
+ }, C = {
210
217
  margin: "0",
211
218
  padding: "0"
212
- }, j = {
219
+ }, q = {
213
220
  display: "block",
214
221
  padding: "8px 12px",
215
222
  color: "#333",
216
223
  textDecoration: "none",
217
224
  transition: "background-color 0.3s ease",
218
225
  cursor: "pointer"
219
- }, $ = {
226
+ }, V = {
220
227
  fontWeight: "bold",
221
- color: "#007bff"
222
- }, z = {
228
+ color: "#007bff",
229
+ // Current locale is not a meaningful switch target
230
+ cursor: "not-allowed"
231
+ }, F = {
223
232
  marginLeft: "8px",
224
233
  display: "inline-block",
225
234
  transition: "transform 0.3s ease"
226
- }, V = {
235
+ }, T = {
227
236
  transform: "rotate(180deg)"
228
- }, L = (s) => s ? Array.isArray(s) ? s : [s] : [], x = (s) => {
237
+ }, p = (c) => c ? Array.isArray(c) ? c : [c] : [], U = (c) => {
229
238
  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;
233
- !v && !g && (l.value = !1);
239
+ const y = c.target;
240
+ if (!y || !m.value) return;
241
+ const L = m.value.contains(y), h = y.closest(".i18n-switcher-button") !== null;
242
+ !L && !h && (l.value = !1);
234
243
  };
235
- return Q(() => {
236
- document.addEventListener("click", x);
237
- }), X(() => {
238
- document.removeEventListener("click", x);
244
+ return ee(() => {
245
+ document.addEventListener("click", U);
246
+ }), te(() => {
247
+ document.removeEventListener("click", U);
239
248
  }), () => {
240
- const s = [];
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(
249
+ const c = [];
250
+ e["before-button"] && c.push(...p(e["before-button"]()));
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(
253
+ g(
245
254
  "span",
246
255
  {
247
256
  style: {
248
- ...z,
249
- ...l.value ? V : {},
257
+ ...F,
258
+ ...l.value ? T : {},
250
259
  ...t.customIconStyle
251
260
  }
252
261
  },
253
262
  "▼"
254
263
  )
255
- ), s.push(
256
- y(
264
+ ), c.push(
265
+ g(
257
266
  "button",
258
267
  {
259
268
  class: "i18n-switcher-button",
260
- style: { ...R, ...t.customButtonStyle },
261
- onClick: (v) => {
262
- v.preventDefault(), v.stopPropagation(), i(v);
269
+ style: {
270
+ ...I,
271
+ ...t.customButtonStyle,
272
+ ...i.value ? t.customDisabledLinkStyle : {}
273
+ },
274
+ onClick: (L) => {
275
+ L.preventDefault(), L.stopPropagation(), v(L);
263
276
  },
264
277
  type: "button",
265
278
  ariaHaspopup: !0,
266
279
  ariaExpanded: l.value
267
280
  },
268
- p
281
+ y
269
282
  )
270
- ), e["before-dropdown"] && s.push(...L(e["before-dropdown"]())), l.value) {
271
- const v = [];
272
- e["before-dropdown-items"] && v.push(...L(e["before-dropdown-items"]())), o.value.forEach((g) => {
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 })));
273
288
  const M = [];
274
- e["before-item"] && M.push(...L(e["before-item"]({ locale: g })));
275
- const _ = [];
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(
289
+ e["before-link-content"] && M.push(...p(e["before-link-content"]({ locale: h }))), M.push(b(h)), e["after-link-content"] && M.push(...p(e["after-link-content"]({ locale: h })));
290
+ const W = typeof window < "u" ? window.location.pathname : "/", D = t.localeRoute ? t.localeRoute(W, h.code) : a?.resolvePath ? a.resolvePath(W, h.code) : W, A = typeof D == "string" ? D : D.path || "#", K = h.code === d.value;
291
+ j.push(
292
+ g(
280
293
  "a",
281
294
  {
282
- class: `switcher-locale-${g.code}`,
283
- href: typeof D == "string" ? D : "#",
295
+ class: `switcher-locale-${h.code}`,
296
+ href: typeof A == "string" ? A : "#",
284
297
  style: {
285
- ...j,
286
- ...U ? $ : {},
287
- ...t.customLinkStyle
298
+ ...q,
299
+ ...K ? V : {},
300
+ ...t.customLinkStyle,
301
+ // active-specific customization wins over the generic link style
302
+ // (matches the React/Preact/Solid switchers)
303
+ ...K ? t.customActiveLinkStyle : {}
288
304
  },
289
305
  // Prevent default navigation, use only handleSwitchLocale
290
- onClick: (F) => {
291
- F.preventDefault(), F.stopPropagation(), b(g.code);
306
+ onClick: (f) => {
307
+ f.preventDefault(), f.stopPropagation(), P(h.code);
292
308
  }
293
309
  },
294
- _
310
+ M
295
311
  )
296
- ), e["after-item"] && M.push(...L(e["after-item"]({ locale: g }))), v.push(
297
- y(
312
+ ), e["after-item"] && j.push(...p(e["after-item"]({ locale: h }))), L.push(
313
+ g(
298
314
  "li",
299
315
  {
300
- key: g.code,
301
- style: { ...O, ...t.customItemStyle }
316
+ key: h.code,
317
+ style: { ...C, ...t.customItemStyle }
302
318
  },
303
- M
319
+ j
304
320
  )
305
321
  );
306
- }), e["after-dropdown-items"] && v.push(...L(e["after-dropdown-items"]())), s.push(
307
- y(
322
+ }), e["after-dropdown-items"] && L.push(...p(e["after-dropdown-items"]())), c.push(
323
+ g(
308
324
  "ul",
309
325
  {
310
326
  class: "i18n-switcher-dropdown",
311
- style: { ...T, ...t.customDropdownStyle }
327
+ style: { ...O, ...t.customDropdownStyle }
312
328
  },
313
- v
329
+ L
314
330
  )
315
331
  );
316
332
  }
317
- return e["after-dropdown"] && s.push(...L(e["after-dropdown"]())), y(
333
+ return e["after-dropdown"] && c.push(...p(e["after-dropdown"]())), g(
318
334
  "div",
319
335
  {
320
- ref: n,
336
+ ref: m,
321
337
  class: "i18n-switcher-wrapper",
322
- style: { ...S, ...t.customWrapperStyle }
338
+ style: { ..._, ...t.customWrapperStyle }
323
339
  },
324
- s
340
+ c
325
341
  );
326
342
  };
327
343
  }
328
- }), oe = B({
344
+ }), ce = z({
329
345
  name: "I18nT",
330
346
  props: {
331
347
  keypath: {
@@ -369,91 +385,117 @@ const E = /* @__PURE__ */ Symbol("i18n"), G = /* @__PURE__ */ Symbol("i18n-local
369
385
  type: [Date, String, Number]
370
386
  }
371
387
  },
372
- setup(t, { slots: e, attrs: a }) {
373
- const r = k(E);
374
- if (!r)
388
+ setup(t, { slots: e, attrs: n }) {
389
+ const a = k(N);
390
+ if (!a)
375
391
  throw new Error("[i18n-micro] I18nT: i18n instance not found. Make sure i18n plugin is installed.");
376
392
  return () => {
377
- const c = {}, o = r.getRoute();
393
+ const s = {}, o = a.getRoute();
378
394
  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 });
395
+ const r = Number(t.number), l = a.tn(r), m = a.t(t.keypath, { number: l, ...t.params }, void 0, o);
396
+ return g(t.tag, { ...n, innerHTML: m });
381
397
  }
382
398
  if (t.date !== void 0) {
383
- const 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 });
399
+ const r = a.td(t.date), l = a.t(t.keypath, { date: r, ...t.params }, void 0, o);
400
+ return g(t.tag, { ...n, innerHTML: l });
385
401
  }
386
402
  if (t.relativeDate !== void 0) {
387
- const 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 });
403
+ const r = a.tdr(t.relativeDate), l = a.t(t.keypath, { relativeDate: r, ...t.params }, void 0, o);
404
+ return g(t.tag, { ...n, innerHTML: l });
389
405
  }
390
406
  if (t.plural !== void 0) {
391
- const n = Number.parseInt(t.plural.toString(), 10);
407
+ const r = Number.parseInt(t.plural.toString(), 10);
392
408
  if (t.customPluralRule) {
393
- const i = t.customPluralRule(
409
+ const l = t.customPluralRule(
394
410
  t.keypath,
395
- n,
411
+ r,
396
412
  t.params,
397
- r.locale.value,
398
- (h, m, b) => r.t(h, m, b, o)
413
+ a.locale.value,
414
+ (m, v, b) => a.t(m, v, b, o)
399
415
  );
400
- return y(t.tag, { ...a, innerHTML: i || "" });
416
+ return g(t.tag, { ...n, innerHTML: l || "" });
401
417
  } else {
402
- const i = r.tc(t.keypath, { count: n, ...t.params });
403
- return y(t.tag, { ...a, innerHTML: i });
418
+ const l = a.tc(t.keypath, { count: r, ...t.params });
419
+ return g(t.tag, { ...n, innerHTML: l });
404
420
  }
405
421
  }
406
- const u = (r.t(t.keypath, { ...t.params, ...c }, void 0, o) ?? "").toString();
422
+ const u = (a.t(t.keypath, { ...t.params, ...s }, void 0, o) ?? "").toString();
407
423
  if (t.hideIfEmpty && !u.trim())
408
424
  return t.defaultValue ?? null;
409
425
  if (t.html)
410
- return y(t.tag, { ...a, innerHTML: u });
426
+ return g(t.tag, { ...n, innerHTML: u });
411
427
  if (e.default)
412
- return y(t.tag, a, e.default({ translation: u }));
428
+ return g(t.tag, n, e.default({ translation: u }));
413
429
  const d = [];
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);
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);
419
435
  }
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);
436
+ return i < u.length && d.push(u.slice(i)), e.default ? g(t.tag, n, e.default({ children: d })) : d.length > 0 ? g(t.tag, n, d) : g(t.tag, n, u);
421
437
  };
422
438
  }
423
439
  });
424
- function le(t) {
425
- const e = k(E), a = k(A, void 0), r = k(G, void 0), c = k(Z, void 0);
440
+ function Z(t) {
441
+ const e = t.og?.trim();
442
+ 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()}`;
450
+ }
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()}`;
456
+ }
457
+ return null;
458
+ }
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}'` : "";
462
+ 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').`
464
+ );
465
+ }
466
+ function se(t) {
467
+ const e = k(N), n = k(E, void 0), a = k(J, void 0), s = k(Q, void 0);
426
468
  if (!e)
427
469
  throw new Error("[i18n-micro] useI18n() must be called after app.use(i18n). Make sure i18n plugin is installed.");
428
- if (!r)
470
+ if (!a)
429
471
  throw new Error("[i18n-micro] I18nLocalesKey not provided. Make sure app.provide(I18nLocalesKey, locales) is called.");
430
- if (!c)
472
+ if (!s)
431
473
  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;
474
+ const o = t?.locales || a, u = t?.defaultLocale || s, d = (i, r) => n?.resolvePath ? n.resolvePath(i, r || e.locale.value) : i;
433
475
  return {
434
476
  // Direct access to instance
435
477
  instance: e,
436
478
  // Locale (reactive)
437
- locale: C({
479
+ locale: S({
438
480
  get: () => e.locale.value,
439
- set: (l) => {
440
- e.locale.value = l;
481
+ set: (i) => {
482
+ e.locale.value = i;
441
483
  }
442
484
  }),
443
485
  // Locale helpers
444
486
  getLocales: () => o,
445
487
  defaultLocale: () => u,
446
- getLocaleName: () => o.find((n) => n.code === e.locale.value)?.displayName || null,
488
+ getLocaleName: () => o.find((r) => r.code === e.locale.value)?.displayName || null,
447
489
  // Routing helpers
448
490
  localeRoute: d,
449
- localePath: (l, n) => {
450
- const i = d(l, n);
451
- return typeof i == "string" ? i : i.path || "/";
491
+ localePath: (i, r) => {
492
+ const l = d(i, r);
493
+ return typeof l == "string" ? l : l.path || "/";
452
494
  },
453
- 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 || "/" });
495
+ switchLocale: (i) => {
496
+ if (e.locale.value = i, n) {
497
+ const r = n.getCurrentPath(), l = d(r, i);
498
+ n.push(typeof l == "string" ? { path: l } : { path: l.path || "/" });
457
499
  }
458
500
  },
459
501
  // Translation methods (delegate to instance)
@@ -464,6 +506,8 @@ function le(t) {
464
506
  td: e.td.bind(e),
465
507
  tdr: e.tdr.bind(e),
466
508
  has: e.has.bind(e),
509
+ resolveTranslations: e.resolveTranslations.bind(e),
510
+ setTranslation: e.setTranslation.bind(e),
467
511
  // Route management
468
512
  setRoute: e.setRoute.bind(e),
469
513
  getRoute: e.getRoute.bind(e),
@@ -475,124 +519,129 @@ function le(t) {
475
519
  clearCache: e.clearCache.bind(e)
476
520
  };
477
521
  }
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({
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({
480
524
  htmlAttrs: {},
481
525
  link: [],
482
526
  meta: []
483
527
  });
484
- 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;
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;
490
534
  }
491
- function h(m = []) {
492
- if (!l) {
493
- n.value = { htmlAttrs: {}, link: [], meta: [] };
535
+ function m(v = []) {
536
+ if (!i) {
537
+ r.value = { htmlAttrs: {}, link: [], meta: [] };
494
538
  return;
495
539
  }
496
- const b = o(), S = u(), R = S.find((f) => f.code === b);
497
- if (!R)
540
+ const b = o(), w = u(), P = w.find((f) => f.code === b);
541
+ if (!P)
498
542
  return;
499
- const T = R.iso || b, O = R.og || T, j = R.dir || "auto";
500
- let $ = l.getCurrentPath();
501
- $.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;
543
+ const _ = P.iso || b, I = Z(P), O = P.dir || "auto";
544
+ let C = i.getCurrentPath();
545
+ C.startsWith("/") || (C = `/${C}`);
546
+ const q = C.split("/").filter(Boolean), V = w.find((f) => q[0] === f.code);
547
+ let F = C, T, p;
548
+ const U = typeof s == "function" ? s() : s;
505
549
  if (V) {
506
- L = $.slice(V.code.length + 1) || "/", x = i(L, m);
550
+ F = C.slice(V.code.length + 1) || "/", T = l(F, v);
507
551
  const f = `/${b}`;
508
- s = `${p}${f}${x.startsWith("/") ? "" : "/"}${x}`;
552
+ p = `${U}${f}${T.startsWith("/") ? "" : "/"}${T}`;
509
553
  } 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)
554
+ T = l(C, v), p = `${U}${T.startsWith("/") ? "" : "/"}${T}`;
555
+ const c = {
556
+ lang: _,
557
+ ...e ? { dir: O } : {}
558
+ };
559
+ if (!a) {
560
+ r.value = { htmlAttrs: c, link: [], meta: [] };
519
561
  return;
520
- const v = S.filter((f) => !f.disabled && f.seo !== !1), g = {
521
- [a]: "i18n-og",
562
+ }
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",
522
567
  property: "og:locale",
523
- content: O
524
- }, M = {
525
- [a]: "i18n-og-url",
568
+ content: I
569
+ } : null, h = {
570
+ [n]: "i18n-og-url",
526
571
  property: "og:url",
527
- 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}`,
572
+ content: p
573
+ }, j = y.filter((f) => f.code !== b).map((f) => {
574
+ const x = Z(f);
575
+ return x ? {
576
+ [n]: `i18n-og-alt-${x}`,
532
577
  property: "og:locale:alternate",
533
- content: I
534
- };
535
- }), N = {
536
- [a]: "i18n-can",
578
+ content: x
579
+ } : (Y(f, { tag: "og:locale:alternate" }), null);
580
+ }).filter((f) => f !== null), M = {
581
+ [n]: "i18n-can",
537
582
  rel: "canonical",
538
- href: s
539
- }, W = v.flatMap((f) => {
540
- if (!d || !l)
583
+ href: p
584
+ }, W = y.flatMap((f) => {
585
+ if (!d || !i)
541
586
  return [];
542
- const I = l.getCurrentPath(), w = d(I, f.code), P = typeof w == "string" ? w : w?.path || "/";
543
- if (!P)
587
+ const x = i.getCurrentPath(), R = d(x, f.code), $ = typeof R == "string" ? R : R?.path || "/";
588
+ if (!$)
544
589
  return [];
545
590
  let H;
546
- P.startsWith("http://") || P.startsWith("https://") ? H = P : H = `${typeof c == "function" ? c() : c}${P.startsWith("/") ? "" : "/"}${P}`;
547
- const J = [
591
+ $.startsWith("http://") || $.startsWith("https://") ? H = $ : H = `${typeof s == "function" ? s() : s}${$.startsWith("/") ? "" : "/"}${$}`;
592
+ const X = [
548
593
  {
549
- [a]: `i18n-alternate-${f.code}`,
594
+ [n]: `i18n-alternate-${f.code}`,
550
595
  rel: "alternate",
551
596
  href: H,
552
597
  hreflang: f.code
553
598
  }
554
599
  ];
555
- return f.iso && f.iso !== f.code && J.push({
556
- [a]: `i18n-alternate-${f.iso}`,
600
+ return f.iso && f.iso !== f.code && X.push({
601
+ [n]: `i18n-alternate-${f.iso}`,
557
602
  rel: "alternate",
558
603
  href: H,
559
604
  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",
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",
570
615
  rel: "alternate",
571
- href: P,
616
+ href: $,
572
617
  hreflang: "x-default"
573
618
  };
574
619
  }
575
620
  }
576
- n.value.meta = [g, M, ..._], n.value.link = [N, ...W, ...U ? [U] : []];
621
+ r.value = {
622
+ htmlAttrs: c,
623
+ meta: [...L ? [L] : [], h, ...j],
624
+ link: [M, ...W, ...A ? [A] : []]
625
+ };
577
626
  }
578
627
  return {
579
- metaObject: n,
580
- updateMeta: h
628
+ metaObject: r,
629
+ updateMeta: m
581
630
  };
582
631
  }
583
- class ie extends ee {
632
+ class ue extends ae {
584
633
  constructor(e) {
585
- const a = {
634
+ const n = {
586
635
  translations: /* @__PURE__ */ new Map()
587
636
  };
588
637
  if (super({
589
- storage: a,
638
+ storage: n,
590
639
  plural: e.plural,
591
640
  missingWarn: e.missingWarn,
592
641
  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);
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);
596
645
  }
597
646
  get locale() {
598
647
  return this._locale;
@@ -621,69 +670,61 @@ class ie extends ee {
621
670
  getRoute() {
622
671
  return this._currentRoute.value;
623
672
  }
624
- addTranslations(e, a, r = !0) {
625
- super.loadTranslationsCore(e, a, r), this._revision.value++, this.notifyListeners();
673
+ addTranslations(e, n, a = !0) {
674
+ super.loadTranslationsCore(e, n, a), this._revision.value++, this.notifyListeners();
626
675
  }
627
- addRouteTranslations(e, a, r, c = !0) {
628
- super.loadRouteTranslationsCore(e, a, r, c), this._revision.value++, this.notifyListeners();
676
+ addRouteTranslations(e, n, a, s = !0) {
677
+ super.loadRouteTranslationsCore(e, n, a, s), this._revision.value++, this.notifyListeners();
629
678
  }
630
- mergeTranslations(e, a, r) {
631
- this.helper.mergeTranslation(e, a, r, !0), this._revision.value++, this.notifyListeners();
679
+ mergeTranslations(e, n, a) {
680
+ this.helper.mergeTranslation(e, n, a, !0), this._revision.value++, this.notifyListeners();
632
681
  }
633
682
  clearCache() {
634
683
  super.clearCache(), this._revision.value++, this.notifyListeners();
635
684
  }
685
+ onTranslationsChanged() {
686
+ this._revision.value++, this.notifyListeners();
687
+ }
636
688
  subscribeToChanges(e) {
637
689
  return this.listeners.add(e), () => this.listeners.delete(e);
638
690
  }
639
691
  notifyListeners() {
640
692
  this.listeners.forEach((e) => e());
641
693
  }
642
- getAllTranslations() {
643
- const e = {};
644
- for (const [a, r] of this.storage.translations)
645
- if (!a.includes(":"))
646
- e[a] = r;
647
- else {
648
- const c = a.split(":")[0];
649
- c && (e[c] || (e[c] = {}), Object.assign(e[c], r));
650
- }
651
- return e;
652
- }
653
694
  getStorage() {
654
695
  return this.storage;
655
696
  }
656
697
  getRouteCache() {
657
698
  const e = {};
658
- for (const [a, r] of this.storage.translations)
659
- e[a] = r;
699
+ for (const [n, a] of this.storage.translations)
700
+ e[n] = a;
660
701
  return e;
661
702
  }
662
703
  }
663
- function he(t) {
664
- const { routingStrategy: e, locales: a, defaultLocale: r, ...c } = t, o = new ie(c);
704
+ function me(t) {
705
+ const { routingStrategy: e, locales: n, defaultLocale: a, ...s } = t, o = new ue(s);
665
706
  let u = null, d = e || null;
666
707
  return {
667
708
  global: o,
668
709
  // Access to instance outside components
669
- setRoutingStrategy: (n) => {
670
- d = n, u && u.provide(A, n);
710
+ setRoutingStrategy: (r) => {
711
+ d = r, u && u.provide(E, r);
671
712
  },
672
713
  // 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);
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);
675
716
  }
676
717
  };
677
718
  }
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();
682
- const i = `/${l.join("/")}`;
683
- return u === a ? i : `/${u}${i === "/" ? "" : i}`;
719
+ function ve(t, e, n) {
720
+ const a = e.map((o) => o.code), s = (o, u) => {
721
+ const i = (typeof o == "string" ? o : o.path || "/").split("/").filter(Boolean), r = i[0];
722
+ r !== void 0 && a.includes(r) && i.shift();
723
+ const l = `/${i.join("/")}`;
724
+ return u === n ? l : `/${u}${l === "/" ? "" : l}`;
684
725
  };
685
726
  return {
686
- linkComponent: te,
727
+ linkComponent: oe,
687
728
  getCurrentPath: () => t.currentRoute.value.path,
688
729
  push: (o) => {
689
730
  t.push(o.path).catch(() => {
@@ -693,7 +734,7 @@ function ge(t, e, a) {
693
734
  t.replace(o.path).catch(() => {
694
735
  });
695
736
  },
696
- resolvePath: (o, u) => c(o, u),
737
+ resolvePath: (o, u) => s(o, u),
697
738
  getRoute: () => ({
698
739
  fullPath: t.currentRoute.value.fullPath,
699
740
  query: t.currentRoute.value.query
@@ -701,20 +742,20 @@ function ge(t, e, a) {
701
742
  };
702
743
  }
703
744
  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
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
719
760
  };
720
761
  //# sourceMappingURL=index.mjs.map