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