@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.cjs +2 -2
- package/dist/index.d.cts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.mjs +264 -308
- package/dist/load-translations.d.ts +2 -3
- package/package.json +42 -41
- package/src/index.ts +3 -31
- package/src/load-translations.ts +34 -56
- package/src/middleware.ts +4 -35
- package/dist/routing.d.ts +0 -23
- package/src/routing.ts +0 -94
package/dist/index.mjs
CHANGED
|
@@ -1,38 +1,40 @@
|
|
|
1
|
-
import { BaseI18n as
|
|
2
|
-
import { FormatService as
|
|
3
|
-
import { existsSync as
|
|
4
|
-
import { resolve as
|
|
5
|
-
|
|
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
|
|
9
|
+
const l = e._storage || {
|
|
8
10
|
translations: /* @__PURE__ */ new Map()
|
|
9
11
|
};
|
|
10
12
|
if (super({
|
|
11
|
-
storage:
|
|
13
|
+
storage: l,
|
|
12
14
|
plural: e.plural,
|
|
13
15
|
missingWarn: e.missingWarn,
|
|
14
16
|
missingHandler: e.missingHandler
|
|
15
|
-
}), this.initialMessages = {}, this.storage =
|
|
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 [
|
|
18
|
-
this.helper.loadTranslations(
|
|
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
|
|
23
|
-
for (const [
|
|
24
|
-
|
|
25
|
-
return { translations:
|
|
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
|
|
29
|
-
return new
|
|
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:
|
|
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,
|
|
63
|
-
const
|
|
64
|
-
return this.storage.translations.get(
|
|
64
|
+
getRouteTranslations(e, l) {
|
|
65
|
+
const r = `${e}:${l}`;
|
|
66
|
+
return this.storage.translations.get(r) ?? null;
|
|
65
67
|
}
|
|
66
|
-
addTranslations(e,
|
|
67
|
-
super.loadTranslationsCore(e,
|
|
68
|
+
addTranslations(e, l, r = !0) {
|
|
69
|
+
super.loadTranslationsCore(e, l, r);
|
|
68
70
|
}
|
|
69
|
-
addRouteTranslations(e,
|
|
70
|
-
super.loadRouteTranslationsCore(e,
|
|
71
|
+
addRouteTranslations(e, l, r, i = !0) {
|
|
72
|
+
super.loadRouteTranslationsCore(e, l, r, i);
|
|
71
73
|
}
|
|
72
|
-
mergeTranslations(e,
|
|
73
|
-
this.helper.mergeTranslation(e,
|
|
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 [
|
|
79
|
-
this.helper.loadTranslations(
|
|
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
|
|
85
|
+
function $() {
|
|
84
86
|
return v;
|
|
85
87
|
}
|
|
86
|
-
function
|
|
87
|
-
const { locale: e, fallbackLocale:
|
|
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,
|
|
95
|
+
const { updateConfig: u } = c, t = "virtual:i18n-micro/config", a = `\0${t}`, s = {
|
|
94
96
|
defaultLocale: e,
|
|
95
|
-
fallbackLocale:
|
|
96
|
-
locales:
|
|
97
|
-
localeCodes: (
|
|
98
|
-
translationDir:
|
|
99
|
-
autoDetect:
|
|
100
|
-
redirectToDefault:
|
|
101
|
-
localeCookie:
|
|
102
|
-
missingWarn:
|
|
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(
|
|
110
|
-
if (
|
|
111
|
-
return
|
|
111
|
+
resolveId(n) {
|
|
112
|
+
if (n === t)
|
|
113
|
+
return a;
|
|
112
114
|
},
|
|
113
|
-
load(
|
|
114
|
-
if (
|
|
115
|
-
return `export const config = ${JSON.stringify(
|
|
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
|
|
150
|
-
return new
|
|
151
|
+
function Y(o) {
|
|
152
|
+
return new R(o);
|
|
151
153
|
}
|
|
152
|
-
function
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
|
177
|
-
const {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
|
188
|
+
function ee(o) {
|
|
187
189
|
const {
|
|
188
190
|
i18n: e,
|
|
189
191
|
// This is the global singleton with cache
|
|
190
|
-
defaultLocale:
|
|
191
|
-
locales:
|
|
192
|
+
defaultLocale: l,
|
|
193
|
+
locales: r,
|
|
192
194
|
localeObjects: i,
|
|
193
195
|
autoDetect: c = !0,
|
|
194
196
|
redirectToDefault: u = !1,
|
|
195
|
-
routingStrategy:
|
|
196
|
-
} =
|
|
197
|
-
return async (
|
|
198
|
-
if (
|
|
199
|
-
return
|
|
200
|
-
const f =
|
|
201
|
-
if (!
|
|
202
|
-
const
|
|
203
|
-
return
|
|
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
|
|
206
|
-
...
|
|
207
|
-
getCurrentPath: () =>
|
|
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 =
|
|
214
|
+
}, m = d.split("/").filter(Boolean)[0], P = m !== void 0 && r.includes(m);
|
|
213
215
|
let y;
|
|
214
|
-
|
|
215
|
-
const
|
|
216
|
-
return
|
|
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
|
|
220
|
-
const
|
|
221
|
-
|
|
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
|
-
|
|
225
|
+
t = u.getLocaleFromPath(o, r, i);
|
|
235
226
|
else {
|
|
236
|
-
const
|
|
237
|
-
|
|
227
|
+
const s = o.split("/").filter(Boolean)[0];
|
|
228
|
+
s && i.includes(s) && (t = s);
|
|
238
229
|
}
|
|
239
|
-
if (c !== null &&
|
|
240
|
-
const
|
|
241
|
-
|
|
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 (
|
|
234
|
+
if (t === r)
|
|
244
235
|
try {
|
|
245
|
-
const
|
|
246
|
-
|
|
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
|
|
240
|
+
return t;
|
|
257
241
|
}
|
|
258
|
-
function
|
|
259
|
-
const
|
|
260
|
-
const
|
|
261
|
-
if (!
|
|
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
|
|
264
|
-
return p && f.includes(p) &&
|
|
265
|
-
}, c = (
|
|
266
|
-
const p =
|
|
267
|
-
return p &&
|
|
268
|
-
}, u = (
|
|
269
|
-
const p =
|
|
270
|
-
return m &&
|
|
271
|
-
},
|
|
272
|
-
const m = (
|
|
273
|
-
return
|
|
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: () =>
|
|
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:
|
|
281
|
-
removeLocaleFromPath: (
|
|
282
|
-
const
|
|
283
|
-
return
|
|
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: (
|
|
286
|
-
const
|
|
287
|
-
return
|
|
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 (
|
|
291
|
-
const
|
|
274
|
+
if (l) {
|
|
275
|
+
const n = l();
|
|
292
276
|
return {
|
|
293
|
-
fullPath:
|
|
294
|
-
query: Object.fromEntries(
|
|
277
|
+
fullPath: n.pathname + n.search,
|
|
278
|
+
query: Object.fromEntries(n.searchParams)
|
|
295
279
|
};
|
|
296
280
|
}
|
|
297
281
|
if (typeof window < "u") {
|
|
298
|
-
const
|
|
282
|
+
const n = new URL(window.location.href);
|
|
299
283
|
return {
|
|
300
|
-
fullPath:
|
|
301
|
-
query: Object.fromEntries(
|
|
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: (
|
|
311
|
-
typeof window < "u" && (window.location.href =
|
|
294
|
+
push: (n) => {
|
|
295
|
+
typeof window < "u" && (window.location.href = n.path);
|
|
312
296
|
},
|
|
313
|
-
replace: (
|
|
314
|
-
typeof window < "u" && window.location.replace(
|
|
297
|
+
replace: (n) => {
|
|
298
|
+
typeof window < "u" && window.location.replace(n.path);
|
|
315
299
|
}
|
|
316
300
|
};
|
|
317
301
|
}
|
|
318
|
-
function
|
|
319
|
-
const
|
|
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
|
|
348
|
-
return
|
|
308
|
+
function T(o) {
|
|
309
|
+
return o.locals.locale || "en";
|
|
349
310
|
}
|
|
350
|
-
function
|
|
351
|
-
return
|
|
311
|
+
function j(o) {
|
|
312
|
+
return o.locals.defaultLocale || "en";
|
|
352
313
|
}
|
|
353
|
-
function B(
|
|
354
|
-
return
|
|
314
|
+
function B(o) {
|
|
315
|
+
return o.locals.locales || [];
|
|
355
316
|
}
|
|
356
|
-
function
|
|
357
|
-
return
|
|
317
|
+
function I(o) {
|
|
318
|
+
return o.locals.routingStrategy || null;
|
|
358
319
|
}
|
|
359
|
-
function
|
|
360
|
-
const e =
|
|
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:
|
|
364
|
-
defaultLocale:
|
|
324
|
+
locale: l,
|
|
325
|
+
defaultLocale: r,
|
|
365
326
|
locales: i,
|
|
366
327
|
// Translation methods
|
|
367
|
-
t: (
|
|
368
|
-
ts: (
|
|
369
|
-
tc: (
|
|
370
|
-
tn: (
|
|
371
|
-
td: (
|
|
372
|
-
tdr: (
|
|
373
|
-
has: (
|
|
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: (
|
|
377
|
-
const
|
|
337
|
+
getRouteName: (t) => {
|
|
338
|
+
const a = t || o.url.pathname;
|
|
378
339
|
if (u?.getRouteName)
|
|
379
|
-
return u.getRouteName(
|
|
380
|
-
const
|
|
381
|
-
if (!
|
|
382
|
-
const
|
|
383
|
-
return f && c.includes(f) &&
|
|
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: (
|
|
386
|
-
const
|
|
346
|
+
getLocaleFromPath: (t) => {
|
|
347
|
+
const a = t || o.url.pathname;
|
|
387
348
|
if (u?.getLocaleFromPath)
|
|
388
|
-
return u.getLocaleFromPath(
|
|
389
|
-
const
|
|
390
|
-
return
|
|
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: (
|
|
354
|
+
switchLocalePath: (t) => {
|
|
394
355
|
if (u?.switchLocalePath)
|
|
395
|
-
return u.switchLocalePath(
|
|
396
|
-
const
|
|
397
|
-
return
|
|
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: (
|
|
360
|
+
localizePath: (t, a) => {
|
|
400
361
|
if (u?.localizePath)
|
|
401
|
-
return u.localizePath(
|
|
402
|
-
const
|
|
403
|
-
return f && c.includes(f) &&
|
|
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: (
|
|
409
|
-
const
|
|
410
|
-
return f && c.includes(f) &&
|
|
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: (
|
|
414
|
-
e.addTranslations(
|
|
374
|
+
addTranslations: (t, a, s = !0) => {
|
|
375
|
+
e.addTranslations(t, a, s);
|
|
415
376
|
},
|
|
416
|
-
addRouteTranslations: (
|
|
417
|
-
e.addRouteTranslations(
|
|
377
|
+
addRouteTranslations: (t, a, s, n = !0) => {
|
|
378
|
+
e.addRouteTranslations(t, a, s, n);
|
|
418
379
|
},
|
|
419
|
-
mergeTranslations: (
|
|
420
|
-
e.mergeTranslations(
|
|
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
|
|
428
|
-
const { baseUrl:
|
|
429
|
-
if (!
|
|
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 =
|
|
392
|
+
const f = n.iso || c, d = n.dir || "auto", g = {
|
|
432
393
|
htmlAttrs: {
|
|
433
394
|
lang: f,
|
|
434
|
-
...
|
|
395
|
+
...r ? { dir: d } : {}
|
|
435
396
|
},
|
|
436
397
|
link: [],
|
|
437
398
|
meta: []
|
|
438
399
|
};
|
|
439
400
|
if (!i)
|
|
440
|
-
return
|
|
441
|
-
const p = `${
|
|
442
|
-
|
|
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 =
|
|
447
|
-
for (const
|
|
448
|
-
let b =
|
|
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(
|
|
411
|
+
b = m.switchLocalePath(o.url.pathname, h.code, P, u);
|
|
451
412
|
else {
|
|
452
|
-
const S =
|
|
453
|
-
w &&
|
|
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
|
|
456
|
-
|
|
416
|
+
const L = `${l}${b}`;
|
|
417
|
+
g.link.push({
|
|
457
418
|
rel: "alternate",
|
|
458
|
-
href:
|
|
459
|
-
hreflang:
|
|
460
|
-
}),
|
|
419
|
+
href: L,
|
|
420
|
+
hreflang: h.code
|
|
421
|
+
}), h.iso && h.iso !== h.code && g.link.push({
|
|
461
422
|
rel: "alternate",
|
|
462
|
-
href:
|
|
463
|
-
hreflang:
|
|
423
|
+
href: L,
|
|
424
|
+
hreflang: h.iso
|
|
464
425
|
});
|
|
465
426
|
}
|
|
466
|
-
if (
|
|
467
|
-
let
|
|
427
|
+
if (a.find((h) => h.code === u)?.seo !== !1) {
|
|
428
|
+
let h = o.url.pathname;
|
|
468
429
|
if (m?.switchLocalePath)
|
|
469
|
-
|
|
430
|
+
h = m.switchLocalePath(o.url.pathname, u, P, u);
|
|
470
431
|
else {
|
|
471
|
-
const b =
|
|
472
|
-
|
|
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
|
-
|
|
435
|
+
g.link.push({
|
|
475
436
|
rel: "alternate",
|
|
476
|
-
href: `${
|
|
437
|
+
href: `${l}${h}`,
|
|
477
438
|
hreflang: "x-default"
|
|
478
439
|
});
|
|
479
440
|
}
|
|
480
|
-
|
|
441
|
+
g.meta.push({
|
|
481
442
|
property: "og:locale",
|
|
482
443
|
content: f
|
|
483
|
-
}),
|
|
444
|
+
}), g.meta.push({
|
|
484
445
|
property: "og:url",
|
|
485
446
|
content: p
|
|
486
447
|
});
|
|
487
|
-
for (const
|
|
488
|
-
|
|
448
|
+
for (const h of s)
|
|
449
|
+
h.code !== c && g.meta.push({
|
|
489
450
|
property: "og:locale:alternate",
|
|
490
|
-
content:
|
|
451
|
+
content: h.og || h.iso || h.code
|
|
491
452
|
});
|
|
492
|
-
return
|
|
453
|
+
return g;
|
|
493
454
|
}
|
|
494
|
-
function
|
|
495
|
-
const
|
|
496
|
-
let i =
|
|
497
|
-
for (let u = 0; u <
|
|
498
|
-
const
|
|
499
|
-
i[
|
|
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 =
|
|
502
|
-
c !== void 0 && (i[c] =
|
|
462
|
+
const c = r[r.length - 1];
|
|
463
|
+
c !== void 0 && (i[c] = l);
|
|
503
464
|
}
|
|
504
|
-
function
|
|
505
|
-
const
|
|
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
|
|
508
|
-
for (const
|
|
509
|
-
const
|
|
510
|
-
|
|
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(
|
|
473
|
+
Object.keys(t).length > 0 && (u[c] = t);
|
|
513
474
|
} else {
|
|
514
|
-
const
|
|
515
|
-
|
|
475
|
+
const t = l.getRouteTranslations(r, c);
|
|
476
|
+
t && (u[c] = t);
|
|
516
477
|
}
|
|
517
478
|
return {
|
|
518
|
-
locale:
|
|
479
|
+
locale: r,
|
|
519
480
|
fallbackLocale: i,
|
|
520
481
|
currentRoute: c,
|
|
521
482
|
translations: u
|
|
522
483
|
};
|
|
523
484
|
}
|
|
524
485
|
export {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
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
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
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
|
};
|