@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/client/vue.js +6 -6
- package/dist/composer.d.ts +4 -19
- package/dist/index.cjs +4 -4
- package/dist/index.mjs +264 -290
- package/dist/integration.d.ts +1 -1
- package/dist/middleware.d.ts +1 -1
- package/package.json +11 -11
- package/src/composer.ts +18 -90
- package/src/integration.ts +4 -4
- package/src/middleware.ts +3 -3
- package/src/utils.ts +8 -4
package/dist/index.mjs
CHANGED
|
@@ -1,78 +1,55 @@
|
|
|
1
|
-
import { BaseI18n as
|
|
2
|
-
import { FormatService as le, defaultPlural as re, interpolate as
|
|
3
|
-
import { existsSync as
|
|
4
|
-
import { resolve as
|
|
5
|
-
class
|
|
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.
|
|
8
|
-
|
|
9
|
-
routeLocaleCache: {},
|
|
10
|
-
dynamicTranslationsCaches: [],
|
|
11
|
-
serverTranslationCache: {}
|
|
7
|
+
const s = e._storage || {
|
|
8
|
+
translations: /* @__PURE__ */ new Map()
|
|
12
9
|
};
|
|
13
10
|
if (super({
|
|
14
|
-
|
|
11
|
+
storage: s,
|
|
15
12
|
plural: e.plural,
|
|
16
13
|
missingWarn: e.missingWarn,
|
|
17
14
|
missingHandler: e.missingHandler
|
|
18
|
-
}), this.initialMessages = {}, this.
|
|
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 [
|
|
21
|
-
this.helper.loadTranslations(
|
|
17
|
+
for (const [o, i] of Object.entries(e.messages))
|
|
18
|
+
this.helper.loadTranslations(o, i);
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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.
|
|
44
|
-
return new
|
|
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
|
-
|
|
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
|
|
92
|
-
return
|
|
63
|
+
const o = `${e}:${s}`;
|
|
64
|
+
return this.storage.translations.get(o) ?? null;
|
|
93
65
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
super.loadTranslationsCore(e, s, n);
|
|
66
|
+
addTranslations(e, s, o = !0) {
|
|
67
|
+
super.loadTranslationsCore(e, s, o);
|
|
97
68
|
}
|
|
98
|
-
addRouteTranslations(e, s,
|
|
99
|
-
super.loadRouteTranslationsCore(e, s,
|
|
69
|
+
addRouteTranslations(e, s, o, i = !0) {
|
|
70
|
+
super.loadRouteTranslationsCore(e, s, o, i);
|
|
100
71
|
}
|
|
101
|
-
mergeTranslations(e, s,
|
|
102
|
-
this.helper.mergeTranslation(e, s,
|
|
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,
|
|
111
|
-
this.helper.loadTranslations(s,
|
|
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(
|
|
89
|
+
function U(n) {
|
|
119
90
|
const {
|
|
120
91
|
locale: e,
|
|
121
92
|
fallbackLocale: s,
|
|
122
|
-
translationDir:
|
|
123
|
-
routingStrategy:
|
|
124
|
-
} =
|
|
125
|
-
return j =
|
|
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": (
|
|
130
|
-
const { updateConfig: f } =
|
|
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:
|
|
134
|
-
localeCodes: (
|
|
135
|
-
translationDir:
|
|
136
|
-
autoDetect:
|
|
137
|
-
redirectToDefault:
|
|
138
|
-
localeCookie:
|
|
139
|
-
missingWarn:
|
|
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(
|
|
147
|
-
if (
|
|
117
|
+
resolveId(a) {
|
|
118
|
+
if (a === t)
|
|
148
119
|
return l;
|
|
149
120
|
},
|
|
150
|
-
load(
|
|
151
|
-
if (
|
|
152
|
-
return `export const config = ${JSON.stringify(
|
|
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": (
|
|
161
|
-
const { injectTypes: f } =
|
|
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(
|
|
187
|
-
return new
|
|
157
|
+
function E(n) {
|
|
158
|
+
return new S(n);
|
|
188
159
|
}
|
|
189
|
-
function J(
|
|
160
|
+
function J(n) {
|
|
190
161
|
const {
|
|
191
162
|
i18n: e,
|
|
192
163
|
// Это глобальный синглтон с кэшем
|
|
193
164
|
defaultLocale: s,
|
|
194
|
-
locales:
|
|
195
|
-
localeObjects:
|
|
196
|
-
autoDetect:
|
|
165
|
+
locales: o,
|
|
166
|
+
localeObjects: i,
|
|
167
|
+
autoDetect: c = !0,
|
|
197
168
|
redirectToDefault: f = !1,
|
|
198
169
|
routingStrategy: t
|
|
199
|
-
} =
|
|
200
|
-
return async (
|
|
201
|
-
if (
|
|
202
|
-
return
|
|
203
|
-
const u =
|
|
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
|
|
206
|
-
return
|
|
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: () =>
|
|
181
|
+
getCurrentPath: () => h,
|
|
211
182
|
getRoute: () => ({
|
|
212
183
|
fullPath: u.pathname + u.search,
|
|
213
184
|
query: Object.fromEntries(u.searchParams)
|
|
214
185
|
})
|
|
215
|
-
},
|
|
216
|
-
let
|
|
217
|
-
p &&
|
|
218
|
-
const
|
|
219
|
-
return
|
|
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
|
|
223
|
-
const e = [], s =
|
|
224
|
-
for (const
|
|
225
|
-
const [
|
|
226
|
-
if (Number.parseFloat(
|
|
227
|
-
const t =
|
|
228
|
-
t && (e.push(t),
|
|
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
|
|
204
|
+
function V(n, e, s, o, i, c = "i18n-locale") {
|
|
234
205
|
const f = v();
|
|
235
|
-
let t =
|
|
206
|
+
let t = o;
|
|
236
207
|
if (f?.getLocaleFromPath)
|
|
237
|
-
t = f.getLocaleFromPath(
|
|
208
|
+
t = f.getLocaleFromPath(n, o, i);
|
|
238
209
|
else {
|
|
239
|
-
const
|
|
240
|
-
|
|
210
|
+
const r = n.split("/").filter(Boolean)[0];
|
|
211
|
+
r && i.includes(r) && (t = r);
|
|
241
212
|
}
|
|
242
|
-
if (t ===
|
|
243
|
-
const l = e.get(
|
|
244
|
-
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 ===
|
|
217
|
+
if (t === o)
|
|
247
218
|
try {
|
|
248
219
|
const l = s.get("accept-language");
|
|
249
220
|
if (l) {
|
|
250
|
-
const
|
|
251
|
-
for (const
|
|
252
|
-
if (
|
|
253
|
-
t =
|
|
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
|
|
262
|
-
const e =
|
|
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
|
|
268
|
-
return
|
|
238
|
+
function T(n) {
|
|
239
|
+
return n.locals.locale || "en";
|
|
269
240
|
}
|
|
270
|
-
function
|
|
271
|
-
return
|
|
241
|
+
function w(n) {
|
|
242
|
+
return n.locals.defaultLocale || "en";
|
|
272
243
|
}
|
|
273
|
-
function
|
|
274
|
-
return
|
|
244
|
+
function $(n) {
|
|
245
|
+
return n.locals.locales || [];
|
|
275
246
|
}
|
|
276
|
-
function
|
|
277
|
-
return
|
|
247
|
+
function D(n) {
|
|
248
|
+
return n.locals.routingStrategy || null;
|
|
278
249
|
}
|
|
279
|
-
function
|
|
280
|
-
const e =
|
|
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:
|
|
285
|
-
locales:
|
|
255
|
+
defaultLocale: o,
|
|
256
|
+
locales: i,
|
|
286
257
|
// Translation methods
|
|
287
|
-
t: (t, l,
|
|
288
|
-
ts: (t, l,
|
|
289
|
-
tc: (t, l,
|
|
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 ||
|
|
268
|
+
const l = t || n.url.pathname;
|
|
298
269
|
if (f?.getRouteName)
|
|
299
|
-
return f.getRouteName(l,
|
|
300
|
-
const
|
|
301
|
-
if (!
|
|
302
|
-
const
|
|
303
|
-
return u &&
|
|
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 ||
|
|
277
|
+
const l = t || n.url.pathname;
|
|
307
278
|
if (f?.getLocaleFromPath)
|
|
308
|
-
return f.getLocaleFromPath(l,
|
|
309
|
-
const
|
|
310
|
-
return
|
|
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(
|
|
316
|
-
const l =
|
|
317
|
-
return
|
|
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,
|
|
322
|
-
const
|
|
323
|
-
return u &&
|
|
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
|
|
330
|
-
return u &&
|
|
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,
|
|
334
|
-
e.addTranslations(t, l,
|
|
304
|
+
addTranslations: (t, l, r = !0) => {
|
|
305
|
+
e.addTranslations(t, l, r);
|
|
335
306
|
},
|
|
336
|
-
addRouteTranslations: (t, l,
|
|
337
|
-
e.addRouteTranslations(t, l,
|
|
307
|
+
addRouteTranslations: (t, l, r, a = !0) => {
|
|
308
|
+
e.addRouteTranslations(t, l, r, a);
|
|
338
309
|
},
|
|
339
|
-
mergeTranslations: (t, l,
|
|
340
|
-
e.mergeTranslations(t, l,
|
|
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
|
|
321
|
+
function Q(n, e = {}) {
|
|
351
322
|
const {
|
|
352
323
|
baseUrl: s = "/",
|
|
353
|
-
addDirAttribute:
|
|
354
|
-
addSeoAttributes:
|
|
355
|
-
} = e,
|
|
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
|
|
329
|
+
const r = l.iso || c, a = l.dir || "auto", u = {
|
|
359
330
|
htmlAttrs: {
|
|
360
|
-
lang:
|
|
361
|
-
...
|
|
331
|
+
lang: r,
|
|
332
|
+
...o ? { dir: a } : {}
|
|
362
333
|
},
|
|
363
334
|
link: [],
|
|
364
335
|
meta: []
|
|
365
336
|
};
|
|
366
|
-
if (!
|
|
337
|
+
if (!i)
|
|
367
338
|
return u;
|
|
368
|
-
const
|
|
339
|
+
const h = `${s}${n.url.pathname}`;
|
|
369
340
|
u.link.push({
|
|
370
341
|
rel: "canonical",
|
|
371
|
-
href:
|
|
342
|
+
href: h
|
|
372
343
|
});
|
|
373
|
-
const d =
|
|
374
|
-
for (const
|
|
375
|
-
if (
|
|
376
|
-
let p =
|
|
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(
|
|
349
|
+
p = d.switchLocalePath(n.url.pathname, g.code, m, f);
|
|
379
350
|
else {
|
|
380
|
-
const
|
|
381
|
-
|
|
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
|
|
354
|
+
const P = `${s}${p}`;
|
|
384
355
|
u.link.push({
|
|
385
356
|
rel: "alternate",
|
|
386
|
-
href:
|
|
387
|
-
hreflang:
|
|
388
|
-
}),
|
|
357
|
+
href: P,
|
|
358
|
+
hreflang: g.code
|
|
359
|
+
}), g.iso && g.iso !== g.code && u.link.push({
|
|
389
360
|
rel: "alternate",
|
|
390
|
-
href:
|
|
391
|
-
hreflang:
|
|
361
|
+
href: P,
|
|
362
|
+
hreflang: g.iso
|
|
392
363
|
});
|
|
393
364
|
}
|
|
394
365
|
u.meta.push({
|
|
395
366
|
property: "og:locale",
|
|
396
|
-
content:
|
|
367
|
+
content: r
|
|
397
368
|
}), u.meta.push({
|
|
398
369
|
property: "og:url",
|
|
399
|
-
content:
|
|
370
|
+
content: h
|
|
400
371
|
});
|
|
401
|
-
for (const
|
|
402
|
-
|
|
372
|
+
for (const g of t)
|
|
373
|
+
g.code !== c && u.meta.push({
|
|
403
374
|
property: "og:locale:alternate",
|
|
404
|
-
content:
|
|
375
|
+
content: g.iso || g.code
|
|
405
376
|
});
|
|
406
377
|
return u;
|
|
407
378
|
}
|
|
408
|
-
function
|
|
409
|
-
const
|
|
410
|
-
let
|
|
411
|
-
for (let
|
|
412
|
-
|
|
413
|
-
|
|
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
|
|
416
|
-
const s =
|
|
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
|
|
421
|
-
|
|
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[
|
|
397
|
+
Object.keys(t).length > 0 && (f[c] = t);
|
|
424
398
|
} else {
|
|
425
|
-
const t = s.getRouteTranslations(
|
|
426
|
-
t && (f[
|
|
399
|
+
const t = s.getRouteTranslations(o, c);
|
|
400
|
+
t && (f[c] = t);
|
|
427
401
|
}
|
|
428
402
|
return {
|
|
429
|
-
locale:
|
|
430
|
-
fallbackLocale:
|
|
431
|
-
currentRoute:
|
|
403
|
+
locale: o,
|
|
404
|
+
fallbackLocale: i,
|
|
405
|
+
currentRoute: c,
|
|
432
406
|
translations: f
|
|
433
407
|
};
|
|
434
408
|
}
|
|
435
|
-
function
|
|
436
|
-
const
|
|
437
|
-
const
|
|
438
|
-
if (!
|
|
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 =
|
|
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
|
-
},
|
|
443
|
-
const m =
|
|
444
|
-
return m &&
|
|
445
|
-
}, f = (
|
|
446
|
-
const m =
|
|
447
|
-
return
|
|
448
|
-
}, t = (
|
|
449
|
-
const
|
|
450
|
-
return p &&
|
|
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:
|
|
455
|
-
getLocaleFromPath:
|
|
428
|
+
getRouteName: i,
|
|
429
|
+
getLocaleFromPath: c,
|
|
456
430
|
switchLocalePath: f,
|
|
457
431
|
localizePath: t,
|
|
458
|
-
removeLocaleFromPath: (
|
|
459
|
-
const
|
|
460
|
-
return d && u.includes(d) &&
|
|
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: (
|
|
463
|
-
const
|
|
464
|
-
return t(
|
|
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
|
|
442
|
+
const a = s();
|
|
469
443
|
return {
|
|
470
|
-
fullPath:
|
|
471
|
-
query: Object.fromEntries(
|
|
444
|
+
fullPath: a.pathname + a.search,
|
|
445
|
+
query: Object.fromEntries(a.searchParams)
|
|
472
446
|
};
|
|
473
447
|
}
|
|
474
448
|
if (typeof window < "u") {
|
|
475
|
-
const
|
|
449
|
+
const a = new URL(window.location.href);
|
|
476
450
|
return {
|
|
477
|
-
fullPath:
|
|
478
|
-
query: Object.fromEntries(
|
|
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: (
|
|
488
|
-
typeof window < "u" && (window.location.href =
|
|
461
|
+
push: (a) => {
|
|
462
|
+
typeof window < "u" && (window.location.href = a.path);
|
|
489
463
|
},
|
|
490
|
-
replace: (
|
|
491
|
-
typeof window < "u" && window.location.replace(
|
|
464
|
+
replace: (a) => {
|
|
465
|
+
typeof window < "u" && window.location.replace(a.path);
|
|
492
466
|
}
|
|
493
467
|
};
|
|
494
468
|
}
|
|
495
|
-
function
|
|
496
|
-
const s =
|
|
469
|
+
function Z(n, e = []) {
|
|
470
|
+
const s = n.replace(/^\//, "").replace(/\/$/, "");
|
|
497
471
|
if (!s)
|
|
498
472
|
return "index";
|
|
499
|
-
const
|
|
500
|
-
return
|
|
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(
|
|
503
|
-
const
|
|
504
|
-
return
|
|
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(
|
|
507
|
-
const
|
|
508
|
-
return
|
|
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(
|
|
511
|
-
const
|
|
512
|
-
return f && s.includes(f) &&
|
|
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(
|
|
515
|
-
const s =
|
|
516
|
-
return
|
|
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
|
|
519
|
-
const { translationDir: e, rootDir: s = process.cwd(), disablePageLocales:
|
|
520
|
-
if (!
|
|
521
|
-
return console.warn(`[i18n] Translation directory not found: ${
|
|
522
|
-
const
|
|
523
|
-
if (!
|
|
524
|
-
const
|
|
525
|
-
for (const u of
|
|
526
|
-
const
|
|
527
|
-
if (
|
|
528
|
-
u === "pages" && !
|
|
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
|
|
533
|
-
|
|
534
|
-
} catch (
|
|
535
|
-
console.error(`[i18n] Failed to load translation file: ${
|
|
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(
|
|
514
|
+
return t(i), { general: c, routes: f };
|
|
541
515
|
}
|
|
542
|
-
function
|
|
543
|
-
const { general: s, routes:
|
|
544
|
-
for (const [
|
|
545
|
-
|
|
546
|
-
for (const [
|
|
547
|
-
for (const [f, t] of Object.entries(
|
|
548
|
-
|
|
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
|
-
|
|
525
|
+
S as AstroI18n,
|
|
552
526
|
le as FormatService,
|
|
553
|
-
|
|
527
|
+
Y as createAstroRouterAdapter,
|
|
554
528
|
E as createI18n,
|
|
555
529
|
J as createI18nMiddleware,
|
|
556
530
|
re as defaultPlural,
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
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
|
-
|
|
564
|
-
|
|
537
|
+
$ as getLocales,
|
|
538
|
+
Z as getRouteName,
|
|
565
539
|
U as i18nIntegration,
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
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
|
-
|
|
573
|
-
|
|
546
|
+
K as useI18n,
|
|
547
|
+
Q as useLocaleHead
|
|
574
548
|
};
|