@i18n-micro/astro 1.3.4 → 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,38 +1,40 @@
1
- import { BaseI18n as I } from "@i18n-micro/core";
2
- import { FormatService as le, defaultPlural as re, interpolate as ie } from "@i18n-micro/core";
3
- import { existsSync as $, readdirSync as O, statSync as _, readFileSync as C } from "node:fs";
4
- import { resolve as N, join as q } from "node:path";
5
- class j extends I {
1
+ import { BaseI18n as O } from "@i18n-micro/core";
2
+ import { FormatService as ie, defaultPlural as ce, interpolate as ue } from "@i18n-micro/core";
3
+ import { existsSync as k, readdirSync as _, statSync as C, readFileSync as N } from "node:fs";
4
+ import { resolve as M, join as W, relative as A, sep as q } from "node:path";
5
+ import { mergeRouteTranslationsWithRoot as H, storeLoadedTranslationFile as U } from "@i18n-micro/utils/parse-path";
6
+ import { detectLocaleFromAcceptLanguage as z } from "@i18n-micro/utils/accept-language";
7
+ class R extends O {
6
8
  constructor(e) {
7
- const s = e._storage || {
9
+ const l = e._storage || {
8
10
  translations: /* @__PURE__ */ new Map()
9
11
  };
10
12
  if (super({
11
- storage: s,
13
+ storage: l,
12
14
  plural: e.plural,
13
15
  missingWarn: e.missingWarn,
14
16
  missingHandler: e.missingHandler
15
- }), this.initialMessages = {}, this.storage = s, this._locale = e.locale, this._fallbackLocale = e.fallbackLocale || e.locale, this._currentRoute = "index", e.messages) {
17
+ }), this.initialMessages = {}, this.storage = l, this._locale = e.locale, this._fallbackLocale = e.fallbackLocale || e.locale, this._currentRoute = "index", e.messages) {
16
18
  this.initialMessages = { ...e.messages };
17
- for (const [a, i] of Object.entries(e.messages))
18
- this.helper.loadTranslations(a, i);
19
+ for (const [r, i] of Object.entries(e.messages))
20
+ this.helper.loadTranslations(r, i);
19
21
  }
20
22
  }
21
23
  cloneStorage(e) {
22
- const s = /* @__PURE__ */ new Map();
23
- for (const [a, i] of e.translations)
24
- s.set(a, { ...i });
25
- return { translations: s };
24
+ const l = /* @__PURE__ */ new Map();
25
+ for (const [r, i] of e.translations)
26
+ l.set(r, { ...i });
27
+ return { translations: l };
26
28
  }
27
29
  clone(e) {
28
- const s = this.cloneStorage(this.storage);
29
- return new j({
30
+ const l = this.cloneStorage(this.storage);
31
+ return new R({
30
32
  locale: e || this._locale,
31
33
  fallbackLocale: this._fallbackLocale,
32
34
  plural: this.pluralFunc,
33
35
  missingWarn: this.missingWarn,
34
36
  missingHandler: this.missingHandler,
35
- _storage: s
37
+ _storage: l
36
38
  });
37
39
  }
38
40
  get locale() {
@@ -59,60 +61,60 @@ class j extends I {
59
61
  getRoute() {
60
62
  return this._currentRoute;
61
63
  }
62
- getRouteTranslations(e, s) {
63
- const a = `${e}:${s}`;
64
- return this.storage.translations.get(a) ?? null;
64
+ getRouteTranslations(e, l) {
65
+ const r = `${e}:${l}`;
66
+ return this.storage.translations.get(r) ?? null;
65
67
  }
66
- addTranslations(e, s, a = !0) {
67
- super.loadTranslationsCore(e, s, a);
68
+ addTranslations(e, l, r = !0) {
69
+ super.loadTranslationsCore(e, l, r);
68
70
  }
69
- addRouteTranslations(e, s, a, i = !0) {
70
- super.loadRouteTranslationsCore(e, s, a, i);
71
+ addRouteTranslations(e, l, r, i = !0) {
72
+ super.loadRouteTranslationsCore(e, l, r, i);
71
73
  }
72
- mergeTranslations(e, s, a) {
73
- this.helper.mergeTranslation(e, s, a, !0);
74
+ mergeTranslations(e, l, r) {
75
+ this.helper.mergeTranslation(e, l, r, !0);
74
76
  }
75
77
  clearCache() {
76
78
  const e = { ...this.initialMessages };
77
79
  if (super.clearCache(), Object.keys(e).length > 0)
78
- for (const [s, a] of Object.entries(e))
79
- this.helper.loadTranslations(s, a);
80
+ for (const [l, r] of Object.entries(e))
81
+ this.helper.loadTranslations(l, r);
80
82
  }
81
83
  }
82
84
  let v = null;
83
- function k() {
85
+ function $() {
84
86
  return v;
85
87
  }
86
- function E(t) {
87
- const { locale: e, fallbackLocale: s, translationDir: a, routingStrategy: i } = t;
88
+ function X(o) {
89
+ const { locale: e, fallbackLocale: l, translationDir: r, routingStrategy: i } = o;
88
90
  return v = i || null, {
89
91
  name: "@i18n-micro/astro",
90
92
  hooks: {
91
93
  // 1. Vite setup (virtual module) happens here
92
94
  "astro:config:setup": (c) => {
93
- const { updateConfig: u } = c, n = "virtual:i18n-micro/config", l = `\0${n}`, r = {
95
+ const { updateConfig: u } = c, t = "virtual:i18n-micro/config", a = `\0${t}`, s = {
94
96
  defaultLocale: e,
95
- fallbackLocale: s || e,
96
- locales: t.locales || [],
97
- localeCodes: (t.locales || []).map((o) => o.code),
98
- translationDir: a || null,
99
- autoDetect: t.autoDetect ?? !0,
100
- redirectToDefault: t.redirectToDefault ?? !1,
101
- localeCookie: t.localeCookie === null ? null : t.localeCookie || "i18n-locale",
102
- missingWarn: t.missingWarn ?? !1
97
+ fallbackLocale: l || e,
98
+ locales: o.locales || [],
99
+ localeCodes: (o.locales || []).map((n) => n.code),
100
+ translationDir: r || null,
101
+ autoDetect: o.autoDetect ?? !0,
102
+ redirectToDefault: o.redirectToDefault ?? !1,
103
+ localeCookie: o.localeCookie === null ? null : o.localeCookie || "i18n-locale",
104
+ missingWarn: o.missingWarn ?? !1
103
105
  };
104
106
  u({
105
107
  vite: {
106
108
  plugins: [
107
109
  {
108
110
  name: "vite-plugin-i18n-micro-config",
109
- resolveId(o) {
110
- if (o === n)
111
- return l;
111
+ resolveId(n) {
112
+ if (n === t)
113
+ return a;
112
114
  },
113
- load(o) {
114
- if (o === l)
115
- return `export const config = ${JSON.stringify(r)}`;
115
+ load(n) {
116
+ if (n === a)
117
+ return `export const config = ${JSON.stringify(s)}`;
116
118
  }
117
119
  }
118
120
  ]
@@ -146,159 +148,141 @@ function E(t) {
146
148
  }
147
149
  };
148
150
  }
149
- function J(t) {
150
- return new j(t);
151
+ function Y(o) {
152
+ return new R(o);
151
153
  }
152
- function M(t) {
153
- const { translationDir: e, rootDir: s = process.cwd(), disablePageLocales: a = !1 } = t, i = N(s, e);
154
- if (!$(i))
155
- return console.warn(`[i18n] Translation directory not found: ${i}`), { root: {}, routes: {} };
156
- const c = {}, u = {}, n = (l, r = "") => {
157
- if (!$(l)) return;
158
- const o = O(l);
159
- for (const f of o) {
160
- const g = q(l, f);
161
- if (_(g).isDirectory())
162
- f === "pages" && !a ? n(g, "") : r || a ? n(g, r) : n(g, f);
163
- else if (f.endsWith(".json")) {
164
- const p = f.replace(".json", "");
165
- try {
166
- const m = C(g, "utf-8"), L = JSON.parse(m);
167
- r && !a ? (u[r] || (u[r] = {}), u[r][p] = L) : c[p] = L;
168
- } catch (m) {
169
- console.error(`[i18n] Failed to load translation file: ${g}`, m);
170
- }
154
+ function D(o, e) {
155
+ if (k(o))
156
+ for (const l of _(o)) {
157
+ const r = W(o, l);
158
+ if (C(r).isDirectory()) {
159
+ D(r, e);
160
+ continue;
171
161
  }
162
+ l.endsWith(".json") && e(r);
172
163
  }
173
- };
174
- return n(i), { root: c, routes: u };
175
164
  }
176
- function V(t, e) {
177
- const { root: s, routes: a } = M(e);
178
- for (const [i, c] of Object.entries(s))
179
- t.addTranslations(i, c, !1);
180
- for (const [i, c] of Object.entries(a))
181
- for (const [u, n] of Object.entries(c)) {
182
- const l = s[u] || {};
183
- t.addRouteTranslations(u, i, { ...l, ...n }, !1);
165
+ function E(o) {
166
+ const { translationDir: e, rootDir: l = process.cwd(), disablePageLocales: r = !1 } = o, i = M(l, e);
167
+ if (!k(i))
168
+ return console.warn(`[i18n] Translation directory not found: ${i}`), { root: {}, routes: {} };
169
+ const c = { root: {}, routes: {} };
170
+ return D(i, (u) => {
171
+ const t = A(i, u).split(q).join("/");
172
+ try {
173
+ const a = N(u, "utf-8"), s = JSON.parse(a);
174
+ U(c, t, s, r);
175
+ } catch (a) {
176
+ console.error(`[i18n] Failed to load translation file: ${u}`, a);
184
177
  }
178
+ }), c;
179
+ }
180
+ function Z(o, e) {
181
+ const { root: l, routes: r } = E(e);
182
+ for (const [i, c] of Object.entries(l))
183
+ o.addTranslations(i, c, !1);
184
+ for (const [i, c] of Object.entries(r))
185
+ for (const [u, t] of Object.entries(c))
186
+ o.addRouteTranslations(u, i, H(l[u], t), !1);
185
187
  }
186
- function G(t) {
188
+ function ee(o) {
187
189
  const {
188
190
  i18n: e,
189
191
  // This is the global singleton with cache
190
- defaultLocale: s,
191
- locales: a,
192
+ defaultLocale: l,
193
+ locales: r,
192
194
  localeObjects: i,
193
195
  autoDetect: c = !0,
194
196
  redirectToDefault: u = !1,
195
- routingStrategy: n
196
- } = t, l = n || k();
197
- return async (r, o) => {
198
- if (r.locals.locale && r.locals.i18n)
199
- return o();
200
- const f = r.url, g = f.pathname;
201
- if (!l) {
202
- const P = e.clone(s), S = g === "/" || g === "" ? "index" : g.split("/").filter(Boolean).join("-");
203
- return P.setRoute(S), r.locals.i18n = P, r.locals.locale = s, r.locals.defaultLocale = s, r.locals.locales = i || a.map((w) => ({ code: w })), r.locals.currentUrl = f, o();
197
+ routingStrategy: t
198
+ } = o, a = t || $();
199
+ return async (s, n) => {
200
+ if (s.locals.locale && s.locals.i18n)
201
+ return n();
202
+ const f = s.url, d = f.pathname;
203
+ if (!a) {
204
+ const L = e.clone(l), S = d === "/" || d === "" ? "index" : d.split("/").filter(Boolean).join("-");
205
+ return L.setRoute(S), s.locals.i18n = L, s.locals.locale = l, s.locals.defaultLocale = l, s.locals.locales = i || r.map((w) => ({ code: w })), s.locals.currentUrl = f, n();
204
206
  }
205
- const h = {
206
- ...l,
207
- getCurrentPath: () => g,
207
+ const g = {
208
+ ...a,
209
+ getCurrentPath: () => d,
208
210
  getRoute: () => ({
209
211
  fullPath: f.pathname + f.search,
210
212
  query: Object.fromEntries(f.searchParams)
211
213
  })
212
- }, m = g.split("/").filter(Boolean)[0], L = m !== void 0 && a.includes(m);
214
+ }, m = d.split("/").filter(Boolean)[0], P = m !== void 0 && r.includes(m);
213
215
  let y;
214
- L && m ? y = m : h.getLocaleFromPath ? y = h.getLocaleFromPath(g, s, a) : y = s;
215
- const d = e.clone(y), b = h.getRouteName ? h.getRouteName(g, a) : "index";
216
- return d.setRoute(b), r.locals.i18n = d, r.locals.locale = y, r.locals.defaultLocale = s, r.locals.locales = i || a.map((P) => ({ code: P })), r.locals.currentUrl = f, r.locals.routingStrategy = h, o();
216
+ P && m ? y = m : g.getLocaleFromPath ? y = g.getLocaleFromPath(d, l, r) : y = l;
217
+ const h = e.clone(y), b = g.getRouteName ? g.getRouteName(d, r) : "index";
218
+ return h.setRoute(b), s.locals.i18n = h, s.locals.locale = y, s.locals.defaultLocale = l, s.locals.locales = i || r.map((L) => ({ code: L })), s.locals.currentUrl = f, s.locals.routingStrategy = g, n();
217
219
  };
218
220
  }
219
- function W(t) {
220
- const e = [], s = t.split(",");
221
- for (const a of s) {
222
- const [i, c = "1.0"] = a.trim().split(";q=");
223
- if (Number.parseFloat(c) > 0 && i) {
224
- const n = i.split("-")[0]?.toLowerCase();
225
- n && (e.push(n), i !== n && e.push(i.toLowerCase()));
226
- }
227
- }
228
- return e;
229
- }
230
- function K(t, e, s, a, i, c = "i18n-locale") {
231
- const u = k();
232
- let n = a;
221
+ function te(o, e, l, r, i, c = "i18n-locale") {
222
+ const u = $();
223
+ let t = r;
233
224
  if (u?.getLocaleFromPath)
234
- n = u.getLocaleFromPath(t, a, i);
225
+ t = u.getLocaleFromPath(o, r, i);
235
226
  else {
236
- const r = t.split("/").filter(Boolean)[0];
237
- r && i.includes(r) && (n = r);
227
+ const s = o.split("/").filter(Boolean)[0];
228
+ s && i.includes(s) && (t = s);
238
229
  }
239
- if (c !== null && n === a && e.get(c)) {
240
- const l = e.get(c)?.value;
241
- l && i.includes(l) && (n = l);
230
+ if (c !== null && t === r && e.get(c)) {
231
+ const a = e.get(c)?.value;
232
+ a && i.includes(a) && (t = a);
242
233
  }
243
- if (n === a)
234
+ if (t === r)
244
235
  try {
245
- const l = s.get("accept-language");
246
- if (l) {
247
- const r = W(l);
248
- for (const o of r)
249
- if (i.includes(o)) {
250
- n = o;
251
- break;
252
- }
253
- }
236
+ const a = z(l.get("accept-language") ?? void 0, i);
237
+ a && (t = a);
254
238
  } catch {
255
239
  }
256
- return n;
240
+ return t;
257
241
  }
258
- function x(t, e, s) {
259
- const a = t.map((o) => o.code), i = (o, f = []) => {
260
- const g = o.replace(/^\//, "").replace(/\/$/, "");
261
- if (!g)
242
+ function ne(o, e, l) {
243
+ const r = o.map((n) => n.code), i = (n, f = []) => {
244
+ const d = n.replace(/^\//, "").replace(/\/$/, "");
245
+ if (!d)
262
246
  return "index";
263
- const h = g.split("/").filter(Boolean), p = h[0];
264
- return p && f.includes(p) && h.shift(), h.length === 0 ? "index" : h.join("-");
265
- }, c = (o, f = "en", g = []) => {
266
- const p = o.split("/").filter(Boolean)[0];
267
- return p && g.includes(p) ? p : f;
268
- }, u = (o, f, g = [], h) => {
269
- const p = o.split("/").filter(Boolean), m = p[0];
270
- return m && g.includes(m) && p.shift(), (f !== h || h === void 0) && p.unshift(f), `/${p.join("/")}`;
271
- }, n = (o, f, g = [], h) => {
272
- const m = (o.replace(/^\//, "").replace(/\/$/, "") || "").split("/").filter(Boolean), L = m[0];
273
- return L && g.includes(L) && m.shift(), (f !== h || h === void 0) && m.unshift(f), `/${m.join("/")}`;
247
+ const g = d.split("/").filter(Boolean), p = g[0];
248
+ return p && f.includes(p) && g.shift(), g.length === 0 ? "index" : g.join("-");
249
+ }, c = (n, f = "en", d = []) => {
250
+ const p = n.split("/").filter(Boolean)[0];
251
+ return p && d.includes(p) ? p : f;
252
+ }, u = (n, f, d = [], g) => {
253
+ const p = n.split("/").filter(Boolean), m = p[0];
254
+ return m && d.includes(m) && p.shift(), (f !== g || g === void 0) && p.unshift(f), `/${p.join("/")}`;
255
+ }, t = (n, f, d = [], g) => {
256
+ const m = (n.replace(/^\//, "").replace(/\/$/, "") || "").split("/").filter(Boolean), P = m[0];
257
+ return P && d.includes(P) && m.shift(), (f !== g || g === void 0) && m.unshift(f), `/${m.join("/")}`;
274
258
  };
275
259
  return {
276
- getCurrentPath: () => s ? s().pathname : typeof window < "u" ? window.location.pathname : "/",
260
+ getCurrentPath: () => l ? l().pathname : typeof window < "u" ? window.location.pathname : "/",
277
261
  getRouteName: i,
278
262
  getLocaleFromPath: c,
279
263
  switchLocalePath: u,
280
- localizePath: n,
281
- removeLocaleFromPath: (o, f = []) => {
282
- const g = o.split("/").filter(Boolean), h = g[0];
283
- return h && f.includes(h) && g.shift(), `/${g.join("/")}`;
264
+ localizePath: t,
265
+ removeLocaleFromPath: (n, f = []) => {
266
+ const d = n.split("/").filter(Boolean), g = d[0];
267
+ return g && f.includes(g) && d.shift(), `/${d.join("/")}`;
284
268
  },
285
- resolvePath: (o, f) => {
286
- const g = typeof o == "string" ? o : o.path || "/";
287
- return n(g, f, a, e);
269
+ resolvePath: (n, f) => {
270
+ const d = typeof n == "string" ? n : n.path || "/";
271
+ return t(d, f, r, e);
288
272
  },
289
273
  getRoute: () => {
290
- if (s) {
291
- const o = s();
274
+ if (l) {
275
+ const n = l();
292
276
  return {
293
- fullPath: o.pathname + o.search,
294
- query: Object.fromEntries(o.searchParams)
277
+ fullPath: n.pathname + n.search,
278
+ query: Object.fromEntries(n.searchParams)
295
279
  };
296
280
  }
297
281
  if (typeof window < "u") {
298
- const o = new URL(window.location.href);
282
+ const n = new URL(window.location.href);
299
283
  return {
300
- fullPath: o.pathname + o.search,
301
- query: Object.fromEntries(o.searchParams)
284
+ fullPath: n.pathname + n.search,
285
+ query: Object.fromEntries(n.searchParams)
302
286
  };
303
287
  }
304
288
  return {
@@ -307,242 +291,214 @@ function x(t, e, s) {
307
291
  };
308
292
  },
309
293
  // Optional: client-side navigation for islands
310
- push: (o) => {
311
- typeof window < "u" && (window.location.href = o.path);
294
+ push: (n) => {
295
+ typeof window < "u" && (window.location.href = n.path);
312
296
  },
313
- replace: (o) => {
314
- typeof window < "u" && window.location.replace(o.path);
297
+ replace: (n) => {
298
+ typeof window < "u" && window.location.replace(n.path);
315
299
  }
316
300
  };
317
301
  }
318
- function Q(t, e = []) {
319
- const s = t.replace(/^\//, "").replace(/\/$/, "");
320
- if (!s)
321
- return "index";
322
- const a = s.split("/").filter(Boolean), i = a[0];
323
- return i && e.includes(i) && a.shift(), a.length === 0 ? "index" : a.join("-");
324
- }
325
- function X(t, e = "en", s = []) {
326
- const i = t.split("/").filter(Boolean)[0];
327
- return i && s.includes(i) ? i : e;
328
- }
329
- function Y(t, e, s = [], a) {
330
- const i = t.split("/").filter(Boolean), c = i[0];
331
- return c && s.includes(c) && i.shift(), (e !== a || a === void 0) && i.unshift(e), `/${i.join("/")}`;
332
- }
333
- function Z(t, e, s = [], a) {
334
- const c = (t.replace(/^\//, "").replace(/\/$/, "") || "").split("/").filter(Boolean), u = c[0];
335
- return u && s.includes(u) && c.shift(), (e !== a || a === void 0) && c.unshift(e), `/${c.join("/")}`;
336
- }
337
- function ee(t, e = []) {
338
- const s = t.split("/").filter(Boolean), a = s[0];
339
- return a && e.includes(a) && s.shift(), `/${s.join("/")}`;
340
- }
341
- function D(t) {
342
- const e = t.locals.i18n;
302
+ function F(o) {
303
+ const e = o.locals.i18n;
343
304
  if (!e)
344
305
  throw new Error("i18n instance not found. Make sure i18n middleware is configured.");
345
306
  return e;
346
307
  }
347
- function R(t) {
348
- return t.locals.locale || "en";
308
+ function T(o) {
309
+ return o.locals.locale || "en";
349
310
  }
350
- function T(t) {
351
- return t.locals.defaultLocale || "en";
311
+ function j(o) {
312
+ return o.locals.defaultLocale || "en";
352
313
  }
353
- function B(t) {
354
- return t.locals.locales || [];
314
+ function B(o) {
315
+ return o.locals.locales || [];
355
316
  }
356
- function F(t) {
357
- return t.locals.routingStrategy || null;
317
+ function I(o) {
318
+ return o.locals.routingStrategy || null;
358
319
  }
359
- function te(t) {
360
- const e = D(t), s = R(t), a = T(t), i = B(t), c = i.map((n) => n.code), u = F(t);
320
+ function oe(o) {
321
+ const e = F(o), l = T(o), r = j(o), i = B(o), c = i.map((t) => t.code), u = I(o);
361
322
  return {
362
323
  // Current locale
363
- locale: s,
364
- defaultLocale: a,
324
+ locale: l,
325
+ defaultLocale: r,
365
326
  locales: i,
366
327
  // Translation methods
367
- t: (n, l, r, o) => e.t(n, l, r, o),
368
- ts: (n, l, r, o) => e.ts(n, l, r, o),
369
- tc: (n, l, r) => e.tc(n, l, r),
370
- tn: (n, l) => e.tn(n, l),
371
- td: (n, l) => e.td(n, l),
372
- tdr: (n, l) => e.tdr(n, l),
373
- has: (n, l) => e.has(n, l),
328
+ t: (t, a, s, n) => e.t(t, a, s, n),
329
+ ts: (t, a, s, n) => e.ts(t, a, s, n),
330
+ tc: (t, a, s) => e.tc(t, a, s),
331
+ tn: (t, a) => e.tn(t, a),
332
+ td: (t, a) => e.td(t, a),
333
+ tdr: (t, a) => e.tdr(t, a),
334
+ has: (t, a) => e.has(t, a),
374
335
  // Route management
375
336
  getRoute: () => e.getRoute(),
376
- getRouteName: (n) => {
377
- const l = n || t.url.pathname;
337
+ getRouteName: (t) => {
338
+ const a = t || o.url.pathname;
378
339
  if (u?.getRouteName)
379
- return u.getRouteName(l, c);
380
- const r = l.replace(/^\//, "").replace(/\/$/, "");
381
- if (!r) return "index";
382
- const o = r.split("/").filter(Boolean), f = o[0];
383
- return f && c.includes(f) && o.shift(), o.length === 0 ? "index" : o.join("-");
340
+ return u.getRouteName(a, c);
341
+ const s = a.replace(/^\//, "").replace(/\/$/, "");
342
+ if (!s) return "index";
343
+ const n = s.split("/").filter(Boolean), f = n[0];
344
+ return f && c.includes(f) && n.shift(), n.length === 0 ? "index" : n.join("-");
384
345
  },
385
- getLocaleFromPath: (n) => {
386
- const l = n || t.url.pathname;
346
+ getLocaleFromPath: (t) => {
347
+ const a = t || o.url.pathname;
387
348
  if (u?.getLocaleFromPath)
388
- return u.getLocaleFromPath(l, a, c);
389
- const o = l.split("/").filter(Boolean)[0];
390
- return o && c.includes(o) ? o : a;
349
+ return u.getLocaleFromPath(a, r, c);
350
+ const n = a.split("/").filter(Boolean)[0];
351
+ return n && c.includes(n) ? n : r;
391
352
  },
392
353
  // Path utilities
393
- switchLocalePath: (n) => {
354
+ switchLocalePath: (t) => {
394
355
  if (u?.switchLocalePath)
395
- return u.switchLocalePath(t.url.pathname, n, c, a);
396
- const l = t.url.pathname.split("/").filter(Boolean), r = l[0];
397
- return r && c.includes(r) && l.shift(), n !== a && l.unshift(n), `/${l.join("/")}`;
356
+ return u.switchLocalePath(o.url.pathname, t, c, r);
357
+ const a = o.url.pathname.split("/").filter(Boolean), s = a[0];
358
+ return s && c.includes(s) && a.shift(), t !== r && a.unshift(t), `/${a.join("/")}`;
398
359
  },
399
- localizePath: (n, l) => {
360
+ localizePath: (t, a) => {
400
361
  if (u?.localizePath)
401
- return u.localizePath(n, l || s, c, a);
402
- const o = (n.replace(/^\//, "").replace(/\/$/, "") || "").split("/").filter(Boolean), f = o[0];
403
- return f && c.includes(f) && o.shift(), l && l !== a && o.unshift(l), `/${o.join("/")}`;
362
+ return u.localizePath(t, a || l, c, r);
363
+ const n = (t.replace(/^\//, "").replace(/\/$/, "") || "").split("/").filter(Boolean), f = n[0];
364
+ return f && c.includes(f) && n.shift(), a && a !== r && n.unshift(a), `/${n.join("/")}`;
404
365
  },
405
366
  // Get i18n instance
406
367
  getI18n: () => e,
407
368
  // Get base path without locale (for rewrite)
408
- getBasePath: (n) => {
409
- const o = (n || t.url).pathname.split("/").filter(Boolean), f = o[0];
410
- return f && c.includes(f) && o.shift(), o.length > 0 ? `/${o.join("/")}` : "/";
369
+ getBasePath: (t) => {
370
+ const n = (t || o.url).pathname.split("/").filter(Boolean), f = n[0];
371
+ return f && c.includes(f) && n.shift(), n.length > 0 ? `/${n.join("/")}` : "/";
411
372
  },
412
373
  // Translation management
413
- addTranslations: (n, l, r = !0) => {
414
- e.addTranslations(n, l, r);
374
+ addTranslations: (t, a, s = !0) => {
375
+ e.addTranslations(t, a, s);
415
376
  },
416
- addRouteTranslations: (n, l, r, o = !0) => {
417
- e.addRouteTranslations(n, l, r, o);
377
+ addRouteTranslations: (t, a, s, n = !0) => {
378
+ e.addRouteTranslations(t, a, s, n);
418
379
  },
419
- mergeTranslations: (n, l, r) => {
420
- e.mergeTranslations(n, l, r);
380
+ mergeTranslations: (t, a, s) => {
381
+ e.mergeTranslations(t, a, s);
421
382
  },
422
383
  clearCache: () => {
423
384
  e.clearCache();
424
385
  }
425
386
  };
426
387
  }
427
- function ne(t, e = {}) {
428
- const { baseUrl: s = "/", addDirAttribute: a = !0, addSeoAttributes: i = !0 } = e, c = R(t), u = T(t), l = B(t).filter((d) => !d.disabled), r = l.filter((d) => d.seo !== !1), o = l.find((d) => d.code === c);
429
- if (!o)
388
+ function ae(o, e = {}) {
389
+ const { baseUrl: l = "/", addDirAttribute: r = !0, addSeoAttributes: i = !0 } = e, c = T(o), u = j(o), a = B(o).filter((h) => !h.disabled), s = a.filter((h) => h.seo !== !1), n = a.find((h) => h.code === c);
390
+ if (!n)
430
391
  return { htmlAttrs: {}, link: [], meta: [] };
431
- const f = o.iso || c, g = o.dir || "auto", h = {
392
+ const f = n.iso || c, d = n.dir || "auto", g = {
432
393
  htmlAttrs: {
433
394
  lang: f,
434
- ...a ? { dir: g } : {}
395
+ ...r ? { dir: d } : {}
435
396
  },
436
397
  link: [],
437
398
  meta: []
438
399
  };
439
400
  if (!i)
440
- return h;
441
- const p = `${s}${t.url.pathname}`;
442
- h.link.push({
401
+ return g;
402
+ const p = `${l}${o.url.pathname}`;
403
+ g.link.push({
443
404
  rel: "canonical",
444
405
  href: p
445
406
  });
446
- const m = F(t), L = l.map((d) => d.code);
447
- for (const d of r) {
448
- let b = t.url.pathname;
407
+ const m = I(o), P = a.map((h) => h.code);
408
+ for (const h of s) {
409
+ let b = o.url.pathname;
449
410
  if (m?.switchLocalePath)
450
- b = m.switchLocalePath(t.url.pathname, d.code, L, u);
411
+ b = m.switchLocalePath(o.url.pathname, h.code, P, u);
451
412
  else {
452
- const S = t.url.pathname.split("/").filter(Boolean), w = S[0];
453
- w && L.includes(w) && S.shift(), d.code !== u && S.unshift(d.code), b = `/${S.join("/")}`;
413
+ const S = o.url.pathname.split("/").filter(Boolean), w = S[0];
414
+ w && P.includes(w) && S.shift(), h.code !== u && S.unshift(h.code), b = `/${S.join("/")}`;
454
415
  }
455
- const P = `${s}${b}`;
456
- h.link.push({
416
+ const L = `${l}${b}`;
417
+ g.link.push({
457
418
  rel: "alternate",
458
- href: P,
459
- hreflang: d.code
460
- }), d.iso && d.iso !== d.code && h.link.push({
419
+ href: L,
420
+ hreflang: h.code
421
+ }), h.iso && h.iso !== h.code && g.link.push({
461
422
  rel: "alternate",
462
- href: P,
463
- hreflang: d.iso
423
+ href: L,
424
+ hreflang: h.iso
464
425
  });
465
426
  }
466
- if (l.find((d) => d.code === u)?.seo !== !1) {
467
- let d = t.url.pathname;
427
+ if (a.find((h) => h.code === u)?.seo !== !1) {
428
+ let h = o.url.pathname;
468
429
  if (m?.switchLocalePath)
469
- d = m.switchLocalePath(t.url.pathname, u, L, u);
430
+ h = m.switchLocalePath(o.url.pathname, u, P, u);
470
431
  else {
471
- const b = t.url.pathname.split("/").filter(Boolean), P = b[0];
472
- P && L.includes(P) && b.shift(), d = `/${b.join("/")}`;
432
+ const b = o.url.pathname.split("/").filter(Boolean), L = b[0];
433
+ L && P.includes(L) && b.shift(), h = `/${b.join("/")}`;
473
434
  }
474
- h.link.push({
435
+ g.link.push({
475
436
  rel: "alternate",
476
- href: `${s}${d}`,
437
+ href: `${l}${h}`,
477
438
  hreflang: "x-default"
478
439
  });
479
440
  }
480
- h.meta.push({
441
+ g.meta.push({
481
442
  property: "og:locale",
482
443
  content: f
483
- }), h.meta.push({
444
+ }), g.meta.push({
484
445
  property: "og:url",
485
446
  content: p
486
447
  });
487
- for (const d of r)
488
- d.code !== c && h.meta.push({
448
+ for (const h of s)
449
+ h.code !== c && g.meta.push({
489
450
  property: "og:locale:alternate",
490
- content: d.og || d.iso || d.code
451
+ content: h.og || h.iso || h.code
491
452
  });
492
- return h;
453
+ return g;
493
454
  }
494
- function A(t, e, s) {
495
- const a = e.split(".");
496
- let i = t;
497
- for (let u = 0; u < a.length - 1; u++) {
498
- const n = a[u];
499
- i[n] || (i[n] = {}), i = i[n];
455
+ function x(o, e, l) {
456
+ const r = e.split(".");
457
+ let i = o;
458
+ for (let u = 0; u < r.length - 1; u++) {
459
+ const t = r[u];
460
+ i[t] || (i[t] = {}), i = i[t];
500
461
  }
501
- const c = a[a.length - 1];
502
- c !== void 0 && (i[c] = s);
462
+ const c = r[r.length - 1];
463
+ c !== void 0 && (i[c] = l);
503
464
  }
504
- function oe(t, e) {
505
- const s = D(t), a = R(t), i = T(t), c = s.getRoute(), u = {};
465
+ function le(o, e) {
466
+ const l = F(o), r = T(o), i = j(o), c = l.getRoute(), u = {};
506
467
  if (e && e.length > 0) {
507
- const n = {};
508
- for (const l of e) {
509
- const r = s.t(l, void 0, void 0, c);
510
- r != null && r !== l && A(n, l, r);
468
+ const t = {};
469
+ for (const a of e) {
470
+ const s = l.t(a, void 0, void 0, c);
471
+ s != null && s !== a && x(t, a, s);
511
472
  }
512
- Object.keys(n).length > 0 && (u[c] = n);
473
+ Object.keys(t).length > 0 && (u[c] = t);
513
474
  } else {
514
- const n = s.getRouteTranslations(a, c);
515
- n && (u[c] = n);
475
+ const t = l.getRouteTranslations(r, c);
476
+ t && (u[c] = t);
516
477
  }
517
478
  return {
518
- locale: a,
479
+ locale: r,
519
480
  fallbackLocale: i,
520
481
  currentRoute: c,
521
482
  translations: u
522
483
  };
523
484
  }
524
485
  export {
525
- j as AstroI18n,
526
- le as FormatService,
527
- x as createAstroRouterAdapter,
528
- J as createI18n,
529
- G as createI18nMiddleware,
530
- re as defaultPlural,
531
- K as detectLocale,
532
- T as getDefaultLocale,
533
- D as getI18n,
534
- oe as getI18nProps,
535
- R as getLocale,
536
- X as getLocaleFromPath,
486
+ R as AstroI18n,
487
+ ie as FormatService,
488
+ ne as createAstroRouterAdapter,
489
+ Y as createI18n,
490
+ ee as createI18nMiddleware,
491
+ ce as defaultPlural,
492
+ te as detectLocale,
493
+ j as getDefaultLocale,
494
+ F as getI18n,
495
+ le as getI18nProps,
496
+ T as getLocale,
537
497
  B as getLocales,
538
- Q as getRouteName,
539
- E as i18nIntegration,
540
- ie as interpolate,
541
- M as loadTranslationsFromDir,
542
- V as loadTranslationsIntoI18n,
543
- Z as localizePath,
544
- ee as removeLocaleFromPath,
545
- Y as switchLocalePath,
546
- te as useI18n,
547
- ne as useLocaleHead
498
+ X as i18nIntegration,
499
+ ue as interpolate,
500
+ E as loadTranslationsFromDir,
501
+ Z as loadTranslationsIntoI18n,
502
+ oe as useI18n,
503
+ ae as useLocaleHead
548
504
  };