@i18n-micro/vue 1.4.10 → 2.0.0

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,7 +1,8 @@
1
- import { computed as e, defineComponent as t, h as n, inject as r, nextTick as i, onMounted as a, onUnmounted as o, ref as s, shallowRef as c } from "vue";
2
- import { BaseI18n as l, FormatService as u, defaultPlural as d, interpolate as f } from "@i18n-micro/core";
3
- //#region src/injection.ts
4
- var p = Symbol("i18n"), m = Symbol("i18n-locales"), h = Symbol("i18n-default-locale"), g = Symbol("i18n-router-strategy"), _ = t({
1
+ import { Fragment as e, computed as t, defineComponent as n, h as r, inject as i, onMounted as a, onUnmounted as o, ref as s, shallowRef as c } from "vue";
2
+ import { BaseI18n as l, FormatService as u, defaultPlural as d, externalLinkHref as f, interpolate as p, isPlainClick as m, isSamePage as h, localeIsoMap as g, urlPath as _ } from "@i18n-micro/core";
3
+ import { createLocaleSwitcher as v, renderI18nT as y } from "@i18n-micro/core/render";
4
+ // src/injection.ts
5
+ var b = Symbol("i18n"), x = Symbol("i18n-locales"), S = Symbol("i18n-default-locale"), C = Symbol("i18n-router-strategy"), w = /*#__PURE__*/ n({
5
6
  name: "I18nGroup",
6
7
  props: {
7
8
  prefix: {
@@ -14,15 +15,198 @@ var p = Symbol("i18n"), m = Symbol("i18n-locales"), h = Symbol("i18n-default-loc
14
15
  }
15
16
  },
16
17
  setup(e, { slots: t }) {
17
- let i = r(p);
18
- if (!i) throw Error("[i18n-micro] I18nGroup: i18n instance not found. Make sure i18n plugin is installed.");
19
- let a = (t, n) => i.t(`${e.prefix}.${t}`, n, void 0, i.getRoute());
20
- return () => n("div", { class: ["i18n-group", e.groupClass] }, t.default?.({
18
+ let n = i(b);
19
+ if (!n) throw Error("[i18n-micro] I18nGroup: i18n instance not found. Make sure i18n plugin is installed.");
20
+ let a = (t, r) => n.t(`${e.prefix}.${t}`, r, void 0, n.getRoute());
21
+ return () => r("div", { class: ["i18n-group", e.groupClass] }, t.default?.({
21
22
  prefix: e.prefix,
22
23
  t: a
23
24
  }));
24
25
  }
25
- }), v = t({
26
+ });
27
+ new Set("xml txt ico json js css png jpg jpeg gif svg webp avif pdf wasm map mp4 webm mp3 zip gz woff woff2 ttf eot".split(" "));
28
+ function T(e) {
29
+ let t = e.length;
30
+ for (; e[t - 1] === "/";) t--;
31
+ return e.slice(0, t);
32
+ }
33
+ // ../utils/dist/resolve-hreflang.mjs
34
+ function E(e) {
35
+ return e.iso?.trim() || String(e.code);
36
+ }
37
+ function D(e) {
38
+ let t = e.match(/^([A-Za-z]{2,3})(?:[-_](.+))?$/);
39
+ return t ? {
40
+ language: t[1],
41
+ region: t[2]
42
+ } : { language: e };
43
+ }
44
+ function ee(e, t = {}) {
45
+ let { hreflangBaseLanguage: n = !1 } = t;
46
+ if (!n) return e.map((e) => {
47
+ let t = String(e.code);
48
+ return {
49
+ hreflang: E(e),
50
+ localeCode: t
51
+ };
52
+ });
53
+ let r = /* @__PURE__ */ new Map();
54
+ for (let t of e) {
55
+ let e = String(t.code), n = E(t), { language: i, region: a } = D(n);
56
+ i && a && !r.has(i) && r.set(i, e), r.set(n, e);
57
+ }
58
+ let i = /* @__PURE__ */ new Set(), a = [];
59
+ for (let t of e) {
60
+ let e = String(t.code), n = E(t), { language: o, region: s } = D(n);
61
+ o && s && r.get(o) === e && !i.has(o) && (i.add(o), a.push({
62
+ hreflang: o,
63
+ localeCode: e
64
+ })), i.has(n) || (i.add(n), a.push({
65
+ hreflang: n,
66
+ localeCode: e
67
+ }));
68
+ }
69
+ return a;
70
+ }
71
+ // ../utils/dist/resolve-og-locale.mjs
72
+ function O(e) {
73
+ let t = e.og?.trim();
74
+ if (t) return t;
75
+ let n = e.iso?.trim();
76
+ return n ? A(n, "_") ?? A(n, "-") : null;
77
+ }
78
+ function k(e) {
79
+ for (let t = 0; t < e.length; t++) {
80
+ let n = e.charCodeAt(t) | 32;
81
+ if (n < 97 || n > 122) return !1;
82
+ }
83
+ return !0;
84
+ }
85
+ function A(e, t) {
86
+ let n = e.indexOf(t), r = e.slice(0, n), i = e.slice(n + 1);
87
+ return n < 2 || i.length !== 2 || !k(r) || !k(i) ? null : `${r.toLowerCase()}_${i.toUpperCase()}`;
88
+ }
89
+ function j(e, t = {}) {
90
+ if (O(e) !== null || t.missingWarn === !1 || process.env.NODE_ENV === "production") return;
91
+ let n = t.tag ?? "og:locale", r = String(e.code ?? "unknown"), i = e.iso ? `, iso: '${e.iso}'` : "";
92
+ console.warn(`[i18n] Cannot derive ${n} for locale '${r}'${i}. Set locale.og (e.g. 'en_US') or use iso with a 2-letter region (e.g. 'en-US').`);
93
+ }
94
+ // ../utils/dist/locale-head.mjs
95
+ function M(e) {
96
+ let t = e.indexOf("?"), n = e.indexOf("#");
97
+ return t === -1 ? n : n === -1 || t < n ? t : n;
98
+ }
99
+ function N(e, t) {
100
+ let n = M(e);
101
+ if (n === -1) return e;
102
+ let r = e.slice(0, n) || "/", i = e.indexOf("#", n), a = e.slice(n + 1, i === -1 ? void 0 : i), o = /* @__PURE__ */ new Map();
103
+ for (let e of a.split("&")) {
104
+ let [n] = new URLSearchParams(e);
105
+ if (!n || !t.includes(n[0])) continue;
106
+ let r = new URLSearchParams([n]).toString(), i = e.includes("=") ? r : r.slice(0, -1), a = o.get(n[0]);
107
+ a ? a.push(i) : o.set(n[0], [i]);
108
+ }
109
+ let s = [...new Set(t)].flatMap((e) => o.get(e) ?? []).join("&");
110
+ return s ? `${r}?${s}` : r;
111
+ }
112
+ function P(e) {
113
+ let t = [];
114
+ for (let [n, r] of Object.entries(e ?? {})) for (let e of [r].flat()) {
115
+ if (e === void 0) continue;
116
+ let r = new URLSearchParams([[n, e === null ? "" : String(e)]]).toString();
117
+ t.push(e === null ? r.slice(0, -1) : r);
118
+ }
119
+ return t.length ? `?${t.join("&")}` : "";
120
+ }
121
+ function F(e, t) {
122
+ let n = 0;
123
+ for (; n < t.length; n++) {
124
+ let e = t.charCodeAt(n);
125
+ if (e !== 47 && e !== 92 && e !== 9 && e !== 10 && e !== 13) break;
126
+ }
127
+ return `${T(e)}/${t.slice(n)}`;
128
+ }
129
+ var I = new Set("Adlm Arab Aran Armi Avst Chrs Cprt Elym Hatr Hebr Hung Khar Lydi Mand Mani Mend Merc Mero Narb Nbat Nkoo Orkh Ougr Palm Phli Phlp Phnx Prti Rohg Samr Sarb Sogd Sogo Syrc Thaa Yezi".split(" ")), L = (e) => I.has(new Intl.Locale(e).maximize().script ?? "");
130
+ function R(e) {
131
+ let [t, ...n] = e.split("_").join("-").split("-");
132
+ for (; n[0]?.length === 3 && Number.isNaN(Number(n[0]));) n.shift();
133
+ try {
134
+ return L([t, ...n].join("-"));
135
+ } catch {
136
+ try {
137
+ return !n.includes("") && L(t);
138
+ } catch {
139
+ return !1;
140
+ }
141
+ }
142
+ }
143
+ var z = /* @__PURE__ */ new Map();
144
+ function B(e) {
145
+ let t = z.get(e);
146
+ return t === void 0 && z.set(e, t = R(e)), t;
147
+ }
148
+ function V(e) {
149
+ return e.dir || (B(e.iso || e.code) ? "rtl" : void 0);
150
+ }
151
+ function H(e) {
152
+ let { locale: t, seoLocales: n, hrefOf: r, canonical: i, xDefault: a, alternates: o = !0, addDirAttribute: s = !0, addSeoAttributes: c = !0 } = e, { identifierAttribute: l = "id", hreflangBaseLanguage: u = !1, missingWarn: d = !0 } = e, f = { lang: t.iso || t.code }, p = s ? V(t) : void 0;
153
+ if (p && (f.dir = p), !c) return {
154
+ htmlAttrs: f,
155
+ link: [],
156
+ meta: []
157
+ };
158
+ let m = [], h = O(t);
159
+ h ? m.push({
160
+ [l]: "i18n-og",
161
+ property: "og:locale",
162
+ content: h
163
+ }) : j(t, {
164
+ missingWarn: d,
165
+ tag: "og:locale"
166
+ }), m.push({
167
+ [l]: "i18n-og-url",
168
+ property: "og:url",
169
+ content: i
170
+ });
171
+ for (let e of n) {
172
+ if (e.code === t.code) continue;
173
+ let n = O(e);
174
+ n ? m.push({
175
+ [l]: `i18n-og-alt-${n}`,
176
+ property: "og:locale:alternate",
177
+ content: n
178
+ }) : j(e, {
179
+ missingWarn: d,
180
+ tag: "og:locale:alternate"
181
+ });
182
+ }
183
+ let g = [{
184
+ [l]: "i18n-can",
185
+ rel: "canonical",
186
+ href: i
187
+ }];
188
+ if (o) for (let { hreflang: e, localeCode: t } of ee(n, { hreflangBaseLanguage: u })) {
189
+ let n = r(t);
190
+ n && g.push({
191
+ [l]: `i18n-alternate-${e}`,
192
+ rel: "alternate",
193
+ href: n,
194
+ hreflang: e
195
+ });
196
+ }
197
+ return o && a && g.push({
198
+ [l]: "i18n-xd",
199
+ rel: "alternate",
200
+ href: a,
201
+ hreflang: "x-default"
202
+ }), {
203
+ htmlAttrs: f,
204
+ link: g,
205
+ meta: m
206
+ };
207
+ }
208
+ // src/router/path.ts
209
+ var U = (e) => typeof e == "string" ? e : `${e.path || "/"}${P(e.query)}${e.hash ?? ""}`, W = (e) => e.getRoute?.().fullPath ?? e.getCurrentPath(), G = /*#__PURE__*/ n({
26
210
  name: "I18nLink",
27
211
  props: {
28
212
  to: {
@@ -38,74 +222,49 @@ var p = Symbol("i18n"), m = Symbol("i18n-locales"), h = Symbol("i18n-default-loc
38
222
  default: void 0
39
223
  }
40
224
  },
41
- setup(t, { slots: i }) {
42
- let a = r(p), o = r(g, void 0);
225
+ setup(e, { slots: n }) {
226
+ let a = i(b), o = i(C, void 0);
43
227
  if (!a) throw Error("[i18n-micro] I18nLink: i18n instance not found. Make sure i18n plugin is installed.");
44
- let s = e(() => typeof t.to == "string" && /^(?:https?:\/\/|\/\/|[a-zA-Z0-9-]+\.[a-zA-Z]{2,})|tel:|mailto:/.test(t.to)), c = e(() => {
45
- if (s.value) return t.to;
46
- if (t.localeRoute) {
47
- let e = t.localeRoute(t.to);
48
- return typeof e == "string" ? e : e.path || "/";
49
- }
50
- if (!o?.resolvePath) return typeof t.to == "string" ? t.to : t.to.path || "/";
51
- let e = o.resolvePath(t.to, a.locale.value);
52
- return typeof e == "string" ? e : e.path || "/";
53
- }), l = e(() => s.value || !o ? !1 : o.getCurrentPath().replace(/#.*$/, "").replace(/\/$/, "") === c.value.replace(/#.*$/, "").replace(/\/$/, "")), u = e(() => l.value ? t.activeStyle : {});
54
- return () => s.value ? n("a", {
55
- href: c.value,
56
- target: "_blank",
57
- rel: "noopener noreferrer",
58
- style: u.value
59
- }, i.default?.()) : o?.linkComponent ? n(o.linkComponent, {
60
- to: c.value,
61
- style: u.value
62
- }, { default: i.default }) : n("a", {
63
- href: c.value,
64
- style: u.value,
65
- onClick: (e) => {
66
- e.preventDefault(), o ? o.push({ path: c.value }) : window.location.href = c.value;
67
- }
68
- }, i.default?.());
228
+ let s = t(() => f(e.to)), c = t(() => e.localeRoute ? U(e.localeRoute(e.to)) : o?.resolvePath ? U(o.resolvePath(e.to, a.locale.value)) : U(e.to)), l = t(() => o !== void 0 && s.value === void 0 && h(o.getCurrentPath(), c.value) ? e.activeStyle : {}), u = (e) => {
229
+ m(e) && (e.preventDefault(), o ? o.push({ path: c.value }) : window.location.href = c.value);
230
+ };
231
+ return () => {
232
+ if (s.value !== void 0) return r("a", {
233
+ href: s.value,
234
+ target: "_blank",
235
+ rel: "noopener noreferrer",
236
+ style: l.value
237
+ }, n.default?.());
238
+ if (o?.linkComponent) return r(o.linkComponent, {
239
+ to: c.value,
240
+ style: l.value
241
+ }, { default: n.default });
242
+ let e = o?.toHref?.(c.value) ?? c.value;
243
+ return r("a", {
244
+ href: e,
245
+ style: l.value,
246
+ onClick: u
247
+ }, n.default?.());
248
+ };
69
249
  }
70
- }), y = t({
250
+ }), K = {
251
+ type: Object,
252
+ default: () => ({})
253
+ }, q = /*#__PURE__*/ n({
71
254
  name: "I18nSwitcher",
72
255
  props: {
73
256
  customLabels: {
74
257
  type: Object,
75
258
  default: () => ({})
76
259
  },
77
- customWrapperStyle: {
78
- type: Object,
79
- default: () => ({})
80
- },
81
- customButtonStyle: {
82
- type: Object,
83
- default: () => ({})
84
- },
85
- customDropdownStyle: {
86
- type: Object,
87
- default: () => ({})
88
- },
89
- customItemStyle: {
90
- type: Object,
91
- default: () => ({})
92
- },
93
- customLinkStyle: {
94
- type: Object,
95
- default: () => ({})
96
- },
97
- customActiveLinkStyle: {
98
- type: Object,
99
- default: () => ({})
100
- },
101
- customDisabledLinkStyle: {
102
- type: Object,
103
- default: () => ({})
104
- },
105
- customIconStyle: {
106
- type: Object,
107
- default: () => ({})
108
- },
260
+ customWrapperStyle: K,
261
+ customButtonStyle: K,
262
+ customDropdownStyle: K,
263
+ customItemStyle: K,
264
+ customLinkStyle: K,
265
+ customActiveLinkStyle: K,
266
+ customDisabledLinkStyle: K,
267
+ customIconStyle: K,
109
268
  locales: {
110
269
  type: Array,
111
270
  default: void 0
@@ -127,152 +286,45 @@ var p = Symbol("i18n"), m = Symbol("i18n-locales"), h = Symbol("i18n-default-loc
127
286
  default: void 0
128
287
  }
129
288
  },
130
- setup(t, { slots: c }) {
131
- let l = r(p), u = r(g, void 0), d = r(m, void 0);
132
- if (!l) throw Error("[i18n-micro] I18nSwitcher: i18n instance not found. Make sure i18n plugin is installed.");
133
- if (!d && !t.locales) throw Error("[i18n-micro] I18nSwitcher: locales not provided. Make sure app.provide(I18nLocalesKey, locales) is called or pass locales prop.");
134
- let f = e(() => t.locales || d || []), h = e(() => f.value.filter((e) => !e.disabled)), _ = e(() => t.currentLocale === void 0 ? l.locale.value : typeof t.currentLocale == "function" ? t.currentLocale() : t.currentLocale), v = e(() => f.value.some((e) => e.code === _.value && e.disabled)), y = e(() => t.getLocaleName ? t.getLocaleName() || null : f.value.find((e) => e.code === l.locale.value)?.displayName || null), b = s(!1), x = s(null), S = (e) => {
135
- e && (e.stopPropagation(), e.preventDefault()), b.value = !b.value;
136
- }, C = (e) => t.customLabels[e.code] || e.displayName || e.code, w = e(() => {
137
- let e = f.value.find((e) => e.code === _.value);
138
- return e ? C(e) : y.value || _.value;
139
- }), T = async (e) => {
140
- if (b.value = !1, await i(), t.switchLocale) {
141
- t.switchLocale(e);
142
- return;
143
- }
144
- if (l.locale.value = e, !u) return;
145
- let n = u.getCurrentPath(), r = t.localeRoute ? (() => {
146
- let r = t.localeRoute(n, e);
147
- return typeof r == "string" ? r : r.path || "/";
148
- })() : u?.resolvePath ? (() => {
149
- let t = u.resolvePath(n, e);
150
- return typeof t == "string" ? t : t.path || "/";
151
- })() : n;
152
- u.push({ path: r });
153
- }, E = {
154
- position: "relative",
155
- display: "inline-block",
156
- verticalAlign: "middle"
157
- }, D = {
158
- padding: "4px 12px",
159
- fontSize: "16px",
160
- cursor: "pointer",
161
- backgroundColor: "#fff",
162
- border: "1px solid #333",
163
- transition: "background-color 0.3s ease",
164
- display: "flex",
165
- alignItems: "center",
166
- justifyContent: "space-between"
167
- }, O = {
168
- position: "absolute",
169
- top: "100%",
170
- left: "0",
171
- zIndex: 1e3,
172
- backgroundColor: "#fff",
173
- border: "1px solid #333",
174
- listStyle: "none",
175
- padding: "0",
176
- margin: "4px 0 0 0",
177
- minWidth: "150px",
178
- boxShadow: "0 2px 8px rgba(0,0,0,0.15)"
179
- }, k = {
180
- margin: "0",
181
- padding: "0"
182
- }, A = {
183
- display: "block",
184
- padding: "8px 12px",
185
- color: "#333",
186
- textDecoration: "none",
187
- transition: "background-color 0.3s ease",
188
- cursor: "pointer"
189
- }, j = {
190
- fontWeight: "bold",
191
- color: "#007bff",
192
- cursor: "not-allowed"
193
- }, M = {
194
- marginLeft: "8px",
195
- display: "inline-block",
196
- transition: "transform 0.3s ease"
197
- }, N = { transform: "rotate(180deg)" }, P = (e) => e ? Array.isArray(e) ? e : [e] : [], F = (e) => {
198
- if (!b.value) return;
199
- let t = e.target;
200
- if (!t || !x.value) return;
201
- let n = x.value.contains(t), r = t.closest(".i18n-switcher-button") !== null;
202
- !n && !r && (b.value = !1);
289
+ setup(t, { slots: n }) {
290
+ let c = i(b), l = i(C, void 0), u = i(x, void 0);
291
+ if (!c) throw Error("[i18n-micro] I18nSwitcher: i18n instance not found. Make sure i18n plugin is installed.");
292
+ if (!u && !t.locales) throw Error("[i18n-micro] I18nSwitcher: locales not provided. Make sure app.provide(I18nLocalesKey, locales) is called or pass locales prop.");
293
+ let d = () => t.locales || u || [], f = (e) => {
294
+ let n = l ? W(l) : typeof window < "u" ? window.location.pathname + window.location.search + window.location.hash : "/";
295
+ return t.localeRoute ? t.localeRoute(n, e) : l?.resolvePath ? l.resolvePath(n, e) : n;
203
296
  };
204
- return a(() => {
205
- document.addEventListener("click", F);
206
- }), o(() => {
207
- document.removeEventListener("click", F);
208
- }), () => {
209
- let e = [];
210
- c["before-button"] && e.push(...P(c["before-button"]()));
211
- let r = [];
212
- if (c["before-selected-locale"] && r.push(...P(c["before-selected-locale"]())), r.push(n("span", w.value)), c["after-selected-locale"] && r.push(...P(c["after-selected-locale"]())), r.push(n("span", { style: {
213
- ...M,
214
- ...b.value ? N : {},
215
- ...t.customIconStyle
216
- } }, "▼")), e.push(n("button", {
217
- class: "i18n-switcher-button",
218
- style: {
219
- ...D,
220
- ...t.customButtonStyle,
221
- ...v.value ? t.customDisabledLinkStyle : {}
222
- },
223
- onClick: (e) => {
224
- e.preventDefault(), e.stopPropagation(), S(e);
225
- },
226
- type: "button",
227
- ariaHaspopup: !0,
228
- ariaExpanded: b.value
229
- }, r)), c["before-dropdown"] && e.push(...P(c["before-dropdown"]())), b.value) {
230
- let r = [];
231
- c["before-dropdown-items"] && r.push(...P(c["before-dropdown-items"]())), h.value.forEach((e) => {
232
- let i = [];
233
- c["before-item"] && i.push(...P(c["before-item"]({ locale: e })));
234
- let a = [];
235
- c["before-link-content"] && a.push(...P(c["before-link-content"]({ locale: e }))), a.push(C(e)), c["after-link-content"] && a.push(...P(c["after-link-content"]({ locale: e })));
236
- let o = typeof window < "u" ? window.location.pathname : "/", s = t.localeRoute ? t.localeRoute(o, e.code) : u?.resolvePath ? u.resolvePath(o, e.code) : o, l = typeof s == "string" ? s : s.path || "#", d = e.code === _.value;
237
- i.push(n("a", {
238
- class: `switcher-locale-${e.code}`,
239
- href: typeof l == "string" ? l : "#",
240
- style: {
241
- ...A,
242
- ...d ? j : {},
243
- ...t.customLinkStyle,
244
- ...d ? t.customActiveLinkStyle : {}
245
- },
246
- onClick: (t) => {
247
- t.preventDefault(), t.stopPropagation(), T(e.code);
248
- }
249
- }, a)), c["after-item"] && i.push(...P(c["after-item"]({ locale: e }))), r.push(n("li", {
250
- key: e.code,
251
- style: {
252
- ...k,
253
- ...t.customItemStyle
254
- }
255
- }, i));
256
- }), c["after-dropdown-items"] && r.push(...P(c["after-dropdown-items"]())), e.push(n("ul", {
257
- class: "i18n-switcher-dropdown",
258
- style: {
259
- ...O,
260
- ...t.customDropdownStyle
261
- }
262
- }, r));
297
+ return v({
298
+ h: r,
299
+ Fragment: e,
300
+ ref: s,
301
+ onMounted: a,
302
+ onUnmounted: o
303
+ }, {
304
+ locales: d,
305
+ locale: () => typeof t.currentLocale == "function" ? t.currentLocale() : t.currentLocale ?? c.locale.value,
306
+ localeName: () => t.getLocaleName ? t.getLocaleName() : d().find((e) => e.code === c.locale.value)?.displayName ?? null,
307
+ href: (e) => {
308
+ let t = f(e), n = typeof t == "string" ? t : t.path;
309
+ return n ? l?.toHref?.(n) ?? n : "#";
310
+ },
311
+ browserNavigates: () => !l && !t.switchLocale && t.localeRoute !== void 0,
312
+ select: (e) => {
313
+ if (t.switchLocale) return t.switchLocale(e);
314
+ let n = l && U(f(e));
315
+ c.locale.value = e, n && l.push({ path: n });
263
316
  }
264
- return c["after-dropdown"] && e.push(...P(c["after-dropdown"]())), n("div", {
265
- ref: x,
266
- class: "i18n-switcher-wrapper",
267
- style: {
268
- ...E,
269
- ...t.customWrapperStyle
270
- }
271
- }, e);
272
- };
317
+ }, t, n);
273
318
  }
274
- }), b = t({
275
- name: "I18nT",
319
+ }), J = {
320
+ h: r,
321
+ Fragment: e
322
+ }, Y = /*#__PURE__*/ Object.assign((e, { slots: t, attrs: n }) => {
323
+ let r = i(b);
324
+ if (!r) throw Error("[i18n-micro] I18nT: i18n instance not found. Make sure i18n plugin is installed.");
325
+ return y(J, r, e, t, n);
326
+ }, {
327
+ displayName: "I18nT",
276
328
  inheritAttrs: !1,
277
329
  props: {
278
330
  keypath: {
@@ -284,10 +336,7 @@ var p = Symbol("i18n"), m = Symbol("i18n-locales"), h = Symbol("i18n-default-loc
284
336
  type: String,
285
337
  default: "span"
286
338
  },
287
- params: {
288
- type: Object,
289
- default: () => ({})
290
- },
339
+ params: { type: Object },
291
340
  defaultValue: {
292
341
  type: String,
293
342
  default: ""
@@ -315,136 +364,19 @@ var p = Symbol("i18n"), m = Symbol("i18n-locales"), h = Symbol("i18n-default-loc
315
364
  String,
316
365
  Number
317
366
  ] }
318
- },
319
- setup(e, { slots: t, attrs: i }) {
320
- let a = r(p);
321
- if (!a) throw Error("[i18n-micro] I18nT: i18n instance not found. Make sure i18n plugin is installed.");
322
- return () => {
323
- let r = {}, o = a.getRoute(), s = { ...i };
324
- delete s.innerHTML;
325
- let c = (t) => e.html ? n(e.tag, {
326
- ...s,
327
- innerHTML: t
328
- }) : n(e.tag, s, t);
329
- if (e.number !== void 0) {
330
- let t = Number(e.number), n = a.tn(t), r = a.t(e.keypath, {
331
- number: n,
332
- ...e.params
333
- }, void 0, o);
334
- return c(String(r ?? ""));
335
- }
336
- if (e.date !== void 0) {
337
- let t = a.td(e.date), n = a.t(e.keypath, {
338
- date: t,
339
- ...e.params
340
- }, void 0, o);
341
- return c(String(n ?? ""));
342
- }
343
- if (e.relativeDate !== void 0) {
344
- let t = a.tdr(e.relativeDate), n = a.t(e.keypath, {
345
- relativeDate: t,
346
- ...e.params
347
- }, void 0, o);
348
- return c(String(n ?? ""));
349
- }
350
- if (e.plural !== void 0) {
351
- let t = Number.parseInt(e.plural.toString(), 10);
352
- return e.customPluralRule ? c(e.customPluralRule(e.keypath, t, e.params, a.locale.value, (e, t, n) => a.t(e, t, n, o)) || "") : c(a.tc(e.keypath, {
353
- count: t,
354
- ...e.params
355
- }));
356
- }
357
- let l = (a.t(e.keypath, {
358
- ...e.params,
359
- ...r
360
- }, void 0, o) ?? "").toString();
361
- if (e.hideIfEmpty && !l.trim()) return e.defaultValue ?? null;
362
- if (e.html) return c(l);
363
- if (t.default) return n(e.tag, s, t.default({ translation: l }));
364
- let u = [], d = 0;
365
- for (let [e, r] of Object.entries(t)) {
366
- if (e === "default") continue;
367
- let t = `{${e}}`, i = l.indexOf(t, d);
368
- i !== -1 && (i > d && u.push(l.slice(d, i)), r && u.push(n(r)), d = i + t.length);
369
- }
370
- return d < l.length && u.push(l.slice(d)), t.default ? n(e.tag, s, t.default({ children: u })) : u.length > 0 ? n(e.tag, s, u) : n(e.tag, s, l);
371
- };
372
367
  }
373
368
  });
374
- //#endregion
375
- //#region ../utils/dist/resolve-hreflang.mjs
376
- function x(e) {
377
- return e.iso?.trim() || String(e.code);
378
- }
379
- function S(e) {
380
- let t = e.match(/^([A-Za-z]{2,3})(?:[-_](.+))?$/);
381
- return t ? {
382
- language: t[1],
383
- region: t[2]
384
- } : { language: e };
385
- }
386
- function C(e, t = {}) {
387
- let { hreflangBaseLanguage: n = !1 } = t;
388
- if (!n) return e.map((e) => {
389
- let t = String(e.code);
390
- return {
391
- hreflang: x(e),
392
- localeCode: t
393
- };
394
- });
395
- let r = /* @__PURE__ */ new Map();
396
- for (let t of e) {
397
- let e = String(t.code), n = x(t), { language: i, region: a } = S(n);
398
- i && a && !r.has(i) && r.set(i, e), r.set(n, e);
399
- }
400
- let i = /* @__PURE__ */ new Set(), a = [];
401
- for (let t of e) {
402
- let e = String(t.code), n = x(t), { language: o, region: s } = S(n);
403
- o && s && r.get(o) === e && !i.has(o) && (i.add(o), a.push({
404
- hreflang: o,
405
- localeCode: e
406
- })), i.has(n) || (i.add(n), a.push({
407
- hreflang: n,
408
- localeCode: e
409
- }));
410
- }
411
- return a;
412
- }
413
- //#endregion
414
- //#region ../utils/dist/resolve-og-locale.mjs
415
- function w(e) {
416
- let t = e.og?.trim();
417
- if (t) return t;
418
- let n = e.iso?.trim();
419
- if (!n) return null;
420
- let r = n.indexOf("_");
421
- if (r > 0) {
422
- let e = n.slice(0, r), t = n.slice(r + 1);
423
- if (e.length >= 2 && t.length === 2) return `${e.toLowerCase()}_${t.toUpperCase()}`;
424
- }
425
- let i = n.indexOf("-");
426
- if (i > 0) {
427
- let e = n.slice(0, i), t = n.slice(i + 1);
428
- if (e.length >= 2 && t.length === 2 && /^[A-Za-z]{2}$/.test(t)) return `${e.toLowerCase()}_${t.toUpperCase()}`;
429
- }
430
- return null;
431
- }
432
- function T(e, t = {}) {
433
- if (w(e) !== null || t.missingWarn === !1 || process.env.NODE_ENV === "production") return;
434
- let n = t.tag ?? "og:locale", r = String(e.code ?? "unknown"), i = e.iso ? `, iso: '${e.iso}'` : "";
435
- console.warn(`[i18n] Cannot derive ${n} for locale '${r}'${i}. Set locale.og (e.g. 'en_US') or use iso with a 2-letter region (e.g. 'en-US').`);
436
- }
437
- //#endregion
438
- //#region src/use-i18n.ts
439
- function E(t) {
440
- let n = r(p), i = r(g, void 0), a = r(m, void 0), o = r(h, void 0);
369
+ // src/use-i18n.ts
370
+ function X(e) {
371
+ let n = i(b), r = i(C, void 0), a = i(x, void 0), o = i(S, void 0);
441
372
  if (!n) throw Error("[i18n-micro] useI18n() must be called after app.use(i18n). Make sure i18n plugin is installed.");
442
- if (!a) throw Error("[i18n-micro] I18nLocalesKey not provided. Make sure app.provide(I18nLocalesKey, locales) is called.");
443
- if (!o) throw Error("[i18n-micro] I18nDefaultLocaleKey not provided. Make sure app.provide(I18nDefaultLocaleKey, defaultLocale) is called.");
444
- let s = t?.locales || a, c = t?.defaultLocale || o, l = (e, t) => i?.resolvePath ? i.resolvePath(e, t || n.locale.value) : e;
373
+ let s = e?.locales || a, c = e?.defaultLocale || o;
374
+ if (!s) throw Error("[i18n-micro] I18nLocalesKey not provided. Make sure app.provide(I18nLocalesKey, locales) is called.");
375
+ if (!c) throw Error("[i18n-micro] I18nDefaultLocaleKey not provided. Make sure app.provide(I18nDefaultLocaleKey, defaultLocale) is called.");
376
+ let l = (e, t) => r?.resolvePath ? r.resolvePath(e, t || n.locale.value) : e;
445
377
  return {
446
378
  instance: n,
447
- locale: e({
379
+ locale: t({
448
380
  get: () => n.locale.value,
449
381
  set: (e) => {
450
382
  n.locale.value = e;
@@ -454,15 +386,10 @@ function E(t) {
454
386
  defaultLocale: () => c,
455
387
  getLocaleName: () => s.find((e) => e.code === n.locale.value)?.displayName || null,
456
388
  localeRoute: l,
457
- localePath: (e, t) => {
458
- let n = l(e, t);
459
- return typeof n == "string" ? n : n.path || "/";
460
- },
389
+ localePath: (e, t) => U(l(e, t)),
461
390
  switchLocale: (e) => {
462
- if (n.locale.value = e, i) {
463
- let t = i.getCurrentPath(), n = l(t, e);
464
- i.push(typeof n == "string" ? { path: n } : { path: n.path || "/" });
465
- }
391
+ let t = r && U(l(W(r), e));
392
+ n.locale.value = e, t && r.push({ path: t });
466
393
  },
467
394
  t: n.t.bind(n),
468
395
  ts: n.ts.bind(n),
@@ -482,129 +409,61 @@ function E(t) {
482
409
  clearCache: n.clearCache.bind(n)
483
410
  };
484
411
  }
485
- //#endregion
486
- //#region src/composables/use-locale-head.ts
487
- function D(e = {}) {
488
- let { addDirAttribute: t = !0, identifierAttribute: n = "id", addSeoAttributes: i = !0, baseUrl: a = "/", hreflangBaseLanguage: o = !1 } = e, { getLocale: c, getLocales: l, localeRoute: u } = E(), d = r(g, void 0), f = s({
412
+ // src/composables/use-locale-head.ts
413
+ var Z = (e) => e.startsWith("http://") || e.startsWith("https://");
414
+ function Q(e = {}) {
415
+ let { addDirAttribute: t = !0, identifierAttribute: n = "id", addSeoAttributes: r = !0, baseUrl: a = "/", hreflangBaseLanguage: o = !1 } = e, { getLocale: c, getLocales: l, localeRoute: u } = X(), d = i(C, void 0), f = i(S, void 0), p = s({
489
416
  htmlAttrs: {},
490
417
  link: [],
491
418
  meta: []
492
419
  });
493
- function p(e, t) {
494
- let n = new URL(e, "http://localhost"), r = new URLSearchParams(n.search), i = {};
495
- for (let e of t) r.has(e) && (i[e] = r.get(e));
496
- let a = new URLSearchParams(i);
497
- return a.toString() ? `${n.pathname}?${a.toString()}` : n.pathname;
498
- }
499
420
  function m(e = []) {
500
421
  if (!d) {
501
- f.value = {
422
+ p.value = {
502
423
  htmlAttrs: {},
503
424
  link: [],
504
425
  meta: []
505
426
  };
506
427
  return;
507
428
  }
508
- let s = c(), m = l(), g = m.find((e) => e.code === s);
509
- if (!g) return;
510
- let _ = g.iso || s, v = w(g), y = g.dir || "auto", b = d.getCurrentPath();
511
- b.startsWith("/") || (b = `/${b}`);
512
- let x = b.split("/").filter(Boolean), S = m.find((e) => x[0] === e.code), E = b, D, O, k = typeof a == "function" ? a() : a;
513
- S ? (E = b.slice(S.code.length + 1) || "/", D = p(E, e), O = `${k}${`/${s}`}${D.startsWith("/") ? "" : "/"}${D}`) : (D = p(b, e), O = `${k}${D.startsWith("/") ? "" : "/"}${D}`);
514
- let A = {
515
- lang: _,
516
- ...t ? { dir: y } : {}
517
- };
518
- if (!i) {
519
- f.value = {
520
- htmlAttrs: A,
521
- link: [],
522
- meta: []
523
- };
524
- return;
525
- }
526
- let j = m.filter((e) => !e.disabled && e.seo !== !1);
527
- v || T(g, { tag: "og:locale" });
528
- let M = v ? {
529
- [n]: "i18n-og",
530
- property: "og:locale",
531
- content: v
532
- } : null, N = {
533
- [n]: "i18n-og-url",
534
- property: "og:url",
535
- content: O
536
- }, P = j.filter((e) => e.code !== s).map((e) => {
537
- let t = w(e);
538
- return t ? {
539
- [n]: `i18n-og-alt-${t}`,
540
- property: "og:locale:alternate",
541
- content: t
542
- } : (T(e, { tag: "og:locale:alternate" }), null);
543
- }).filter((e) => e !== null), F = {
544
- [n]: "i18n-can",
545
- rel: "canonical",
546
- href: O
547
- }, I = (() => {
548
- if (!u || !d) return [];
549
- let e = /* @__PURE__ */ new Map(), t = d.getCurrentPath();
550
- for (let n of j) {
551
- let r = u(t, n.code), i = typeof r == "string" ? r : r?.path || "/";
552
- if (!i) continue;
553
- let o;
554
- o = i.startsWith("http://") || i.startsWith("https://") ? i : `${typeof a == "function" ? a() : a}${i.startsWith("/") ? "" : "/"}${i}`, e.set(String(n.code), o);
555
- }
556
- return C(j, { hreflangBaseLanguage: o }).flatMap(({ hreflang: t, localeCode: r }) => {
557
- let i = e.get(r);
558
- return i ? [{
559
- [n]: `i18n-alternate-${t}`,
560
- rel: "alternate",
561
- href: i,
562
- hreflang: t
563
- }] : [];
564
- });
565
- })(), L = r(h, void 0), R = null, z = L ? m.find((e) => e.code === L) : void 0;
566
- if (u && d && L && z?.seo !== !1) {
567
- let e = d.getCurrentPath(), t = u(e, L), r = typeof t == "string" ? t : t?.path || "/";
568
- if (r) {
569
- let e;
570
- e = r.startsWith("http://") || r.startsWith("https://") ? r : `${typeof a == "function" ? a() : a}${r.startsWith("/") ? "" : "/"}${r}`, R = {
571
- [n]: "i18n-xd",
572
- rel: "alternate",
573
- href: e,
574
- hreflang: "x-default"
575
- };
576
- }
577
- }
578
- f.value = {
579
- htmlAttrs: A,
580
- meta: [
581
- ...M ? [M] : [],
582
- N,
583
- ...P
584
- ],
585
- link: [
586
- F,
587
- ...I,
588
- ...R ? [R] : []
589
- ]
590
- };
429
+ let i = l(), s = i.find((e) => e.code === c());
430
+ if (!s) return;
431
+ let m = typeof a == "function" ? a() : a, h = _(d.getCurrentPath()) || "/", g = N(W(d), e), v = g.indexOf("?"), y = v === -1 ? "" : g.slice(v), b = (e) => {
432
+ let t = U(u(h, e));
433
+ return t ? `${Z(t) ? t : F(m, t)}${y}` : "";
434
+ }, x = i.find((e) => e.code === f);
435
+ p.value = H({
436
+ locale: s,
437
+ seoLocales: i.filter((e) => !e.disabled && e.seo !== !1),
438
+ hrefOf: b,
439
+ canonical: b(s.code),
440
+ xDefault: x && x.seo !== !1 ? b(x.code) : void 0,
441
+ addDirAttribute: t,
442
+ addSeoAttributes: r,
443
+ identifierAttribute: n,
444
+ hreflangBaseLanguage: o
445
+ });
591
446
  }
592
447
  return {
593
- metaObject: f,
448
+ metaObject: p,
594
449
  updateMeta: m
595
450
  };
596
451
  }
597
- //#endregion
598
- //#region src/composer.ts
599
- var O = class extends l {
452
+ // src/composer.ts
453
+ var $ = class extends l {
600
454
  constructor(e) {
601
455
  let t = { translations: /* @__PURE__ */ new Map() };
602
- if (super({
456
+ super({
603
457
  storage: t,
604
458
  plural: e.plural,
605
459
  missingWarn: e.missingWarn,
606
- missingHandler: e.missingHandler
607
- }), this.listeners = /* @__PURE__ */ new Set(), this.storage = t, this._locale = c(e.locale), this._fallbackLocale = c(e.fallbackLocale || e.locale), this._currentRoute = c("index"), this._revision = c(0), e.messages) for (let [t, n] of Object.entries(e.messages)) this.helper.loadTranslations(t, n);
460
+ missingHandler: e.missingHandler,
461
+ numberFormats: e.numberFormats,
462
+ datetimeFormats: e.datetimeFormats,
463
+ timeZone: e.timeZone,
464
+ localeIso: e.localeIso
465
+ }), this.listeners = /* @__PURE__ */ new Set(), this.storage = t, this._locale = c(e.locale), this._fallbackLocale = c(e.fallbackLocale || e.locale), this._currentRoute = c("index"), this._revision = c(0);
466
+ for (let [t, n] of Object.entries(e.messages ?? {})) this.helper.mergeTranslation(t, "index", n);
608
467
  }
609
468
  get locale() {
610
469
  return this._locale;
@@ -634,16 +493,16 @@ var O = class extends l {
634
493
  return this._currentRoute.value;
635
494
  }
636
495
  addTranslations(e, t, n = !0) {
637
- super.loadTranslationsCore(e, t, n), this._revision.value++, this.notifyListeners();
496
+ this.loadTranslationsCore(e, t, n);
638
497
  }
639
498
  addRouteTranslations(e, t, n, r = !0) {
640
- super.loadRouteTranslationsCore(e, t, n, r), this._revision.value++, this.notifyListeners();
499
+ this.loadTranslationsCore(e, n, r, t);
641
500
  }
642
501
  mergeTranslations(e, t, n) {
643
- this.helper.mergeTranslation(e, t, n, !0), this._revision.value++, this.notifyListeners();
502
+ this.loadTranslationsCore(e, n, !0, t);
644
503
  }
645
- clearCache() {
646
- super.clearCache(), this._revision.value++, this.notifyListeners();
504
+ touch() {
505
+ this._revision.value;
647
506
  }
648
507
  onTranslationsChanged() {
649
508
  this._revision.value++, this.notifyListeners();
@@ -652,7 +511,11 @@ var O = class extends l {
652
511
  return this.listeners.add(e), () => this.listeners.delete(e);
653
512
  }
654
513
  notifyListeners() {
655
- this.listeners.forEach((e) => e());
514
+ for (let e of [...this.listeners]) if (this.listeners.has(e)) try {
515
+ e();
516
+ } catch (e) {
517
+ console.error("[i18n-micro] change listener failed:", e);
518
+ }
656
519
  }
657
520
  getStorage() {
658
521
  return this.storage;
@@ -663,21 +526,22 @@ var O = class extends l {
663
526
  return e;
664
527
  }
665
528
  };
666
- //#endregion
667
- //#region src/plugin.ts
668
- function k(e) {
669
- let { routingStrategy: t, locales: n, defaultLocale: r, ...i } = e, a = new O(i), o = null, s = t || null;
529
+ // src/plugin.ts
530
+ function te(e) {
531
+ let { routingStrategy: t, locales: n, defaultLocale: r, ...i } = e, a = new $({
532
+ localeIso: n && g(n),
533
+ ...i
534
+ }), o = null, s = t || null;
670
535
  return {
671
536
  global: a,
672
537
  setRoutingStrategy: (e) => {
673
- s = e, o && o.provide(g, e);
538
+ s = e, o && o.provide(C, e);
674
539
  },
675
540
  install(e) {
676
- o = e, e.provide(p, a), s && e.provide(g, s), n && e.provide(m, n), r && e.provide(h, r), e.config.globalProperties.$t = (e, t, n, r) => a.t(e, t, n, r), e.config.globalProperties.$ts = (e, t, n, r) => a.ts(e, t, n, r), e.config.globalProperties.$tc = (e, t, n) => a.tc(e, t, n), e.config.globalProperties.$tn = a.tn.bind(a), e.config.globalProperties.$td = a.td.bind(a), e.config.globalProperties.$tdr = a.tdr.bind(a), e.config.globalProperties.$has = (e, t) => a.has(e, t), e.config.globalProperties.$i18n = a, e.component("I18nT", b), e.component("I18nLink", v), e.component("I18nGroup", _), e.component("I18nSwitcher", y);
541
+ o = e, e.provide(b, a), s && e.provide(C, s), n && e.provide(x, n), r && e.provide(S, r), e.config.globalProperties.$t = (e, t, n, r) => a.t(e, t, n, r), e.config.globalProperties.$ts = (e, t, n, r) => a.ts(e, t, n, r), e.config.globalProperties.$tc = (e, t, n) => a.tc(e, t, n), e.config.globalProperties.$tn = a.tn.bind(a), e.config.globalProperties.$td = a.td.bind(a), e.config.globalProperties.$tdr = a.tdr.bind(a), e.config.globalProperties.$has = (e, t) => a.has(e, t), e.config.globalProperties.$i18n = a, e.component("I18nT", Y), e.component("I18nLink", G), e.component("I18nGroup", w), e.component("I18nSwitcher", q);
677
542
  }
678
543
  };
679
544
  }
680
- //#endregion
681
- export { u as FormatService, h as I18nDefaultLocaleKey, _ as I18nGroup, p as I18nInjectionKey, v as I18nLink, m as I18nLocalesKey, y as I18nSwitcher, b as I18nT, O as VueI18n, k as createI18n, d as defaultPlural, f as interpolate, E as useI18n, D as useLocaleHead };
545
+ export { u as FormatService, S as I18nDefaultLocaleKey, w as I18nGroup, b as I18nInjectionKey, G as I18nLink, x as I18nLocalesKey, q as I18nSwitcher, Y as I18nT, $ as VueI18n, te as createI18n, d as defaultPlural, p as interpolate, X as useI18n, Q as useLocaleHead };
682
546
 
683
547
  //# sourceMappingURL=index.mjs.map