@i18n-micro/route-strategy 1.1.5 → 1.1.7
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 +1 -1
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +332 -322
- package/dist/locale-route-access.d.ts +6 -0
- package/dist/utils/index.d.cts +3 -0
- package/package.json +20 -12
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { existsSync as E, mkdirSync as
|
|
3
|
-
import { isPrefixAndDefaultStrategy as
|
|
4
|
-
const $ = (l) => l.map((e) => ({ ...e })), q = (l) => !!(l.redirect && !l.file), j = (l, e, t,
|
|
1
|
+
import w from "node:path";
|
|
2
|
+
import { existsSync as E, mkdirSync as U, writeFileSync as B } from "node:fs";
|
|
3
|
+
import { isPrefixAndDefaultStrategy as K, isPrefixStrategy as O } from "@i18n-micro/core";
|
|
4
|
+
const $ = (l) => l.map((e) => ({ ...e })), q = (l) => !!(l.redirect && !l.file), j = (l, e, t, s = "localized-") => t ? `${s}${l}-${e}` : `${s}${l}`, b = (l, e) => l ?? (e ?? "").replace(/[^a-z0-9]/gi, "-").replace(/^-+|-+$/g, ""), H = (l, e, t) => t && l !== e.code, J = (l, e) => (typeof l == "string" ? l : l.code) === e.code, Q = [
|
|
5
5
|
/^\/sitemap.*\.xml$/,
|
|
6
6
|
/^\/sitemap\.xml$/,
|
|
7
7
|
/^\/robots\.txt$/,
|
|
@@ -12,7 +12,7 @@ const $ = (l) => l.map((e) => ({ ...e })), q = (l) => !!(l.redirect && !l.file),
|
|
|
12
12
|
/^\/workbox-.*\.js$/,
|
|
13
13
|
/\.(xml|txt|ico|json|js|css|png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)$/
|
|
14
14
|
];
|
|
15
|
-
function
|
|
15
|
+
function D(l, e) {
|
|
16
16
|
if (/(?:^|\/)__[^/]+/.test(l))
|
|
17
17
|
return !0;
|
|
18
18
|
for (const t of Q)
|
|
@@ -31,23 +31,23 @@ function K(l, e) {
|
|
|
31
31
|
return !1;
|
|
32
32
|
}
|
|
33
33
|
function X(l, e) {
|
|
34
|
-
const t = l.reduce((o,
|
|
35
|
-
const
|
|
36
|
-
return
|
|
37
|
-
}, []).filter((o) => !o.disabled),
|
|
38
|
-
return { locales: t, defaultLocale:
|
|
34
|
+
const t = l.reduce((o, a) => {
|
|
35
|
+
const r = o.find((i) => i.code === a.code);
|
|
36
|
+
return r ? Object.assign(r, a) : o.push(a), o;
|
|
37
|
+
}, []).filter((o) => !o.disabled), s = t.find((o) => o.code === e) ?? { code: e };
|
|
38
|
+
return { locales: t, defaultLocale: s };
|
|
39
39
|
}
|
|
40
|
-
function
|
|
40
|
+
function x(l) {
|
|
41
41
|
return l.split("/").map((e) => e.startsWith("[...") && e.endsWith("]") ? `:${e.substring(4, e.length - 1)}(.*)*` : e.startsWith("[") && e.endsWith("]") ? `:${e.substring(1, e.length - 1)}` : e).join("/");
|
|
42
42
|
}
|
|
43
43
|
const R = (l) => {
|
|
44
44
|
if (!l)
|
|
45
45
|
return "";
|
|
46
|
-
const e =
|
|
46
|
+
const e = w.posix.normalize(l).replace(/\/+$/, "");
|
|
47
47
|
return e === "." ? "" : e;
|
|
48
|
-
},
|
|
48
|
+
}, g = (l) => l.startsWith("/") ? l.slice(1) : l;
|
|
49
49
|
function G(...l) {
|
|
50
|
-
return
|
|
50
|
+
return w.posix.join(...l);
|
|
51
51
|
}
|
|
52
52
|
function Y(l) {
|
|
53
53
|
if (!(typeof l > "u"))
|
|
@@ -57,8 +57,8 @@ function M(l) {
|
|
|
57
57
|
return !l || !/[\u0080-\uFFFF]/.test(l) ? l : l.split("/").map((e) => !e || e.startsWith(":") || !/[\u0080-\uFFFF]/.test(e) ? e : encodeURI(e)).join("/");
|
|
58
58
|
}
|
|
59
59
|
function A(l, e, t) {
|
|
60
|
-
const
|
|
61
|
-
return R(
|
|
60
|
+
const s = Y(t?.toString()), o = s || (Array.isArray(l) ? l.join("|") : l), a = M(e);
|
|
61
|
+
return R(w.posix.join("/", `:locale(${o})`, a));
|
|
62
62
|
}
|
|
63
63
|
function Z(l) {
|
|
64
64
|
const e = M(l);
|
|
@@ -66,102 +66,111 @@ function Z(l) {
|
|
|
66
66
|
}
|
|
67
67
|
const ee = (l, e) => l ?? (e ?? "").replace(/[^a-z0-9]/gi, "-").replace(/^-+|-+$/g, "");
|
|
68
68
|
function F(l) {
|
|
69
|
-
return
|
|
69
|
+
return g(l) || "/";
|
|
70
70
|
}
|
|
71
|
-
function
|
|
71
|
+
function S(l, e, t, s = "") {
|
|
72
72
|
const o = {};
|
|
73
|
-
return l.forEach((
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
76
|
-
typeof
|
|
73
|
+
return l.forEach((a) => {
|
|
74
|
+
const r = ee(a.name, a.path), i = R(G(s, a.path ?? "")), n = F(i), f = x(i), c = e[n] || e[f] || e[r];
|
|
75
|
+
if (c)
|
|
76
|
+
typeof c == "object" && (o[n] = c);
|
|
77
77
|
else {
|
|
78
|
-
const h = t[
|
|
79
|
-
h && typeof h == "object" && !Array.isArray(h) && (o[
|
|
78
|
+
const h = t[r];
|
|
79
|
+
h && typeof h == "object" && !Array.isArray(h) && (o[n] = h);
|
|
80
80
|
}
|
|
81
|
-
if (
|
|
82
|
-
const h = R(G(
|
|
83
|
-
Object.assign(o,
|
|
81
|
+
if (a.children?.length) {
|
|
82
|
+
const h = R(G(s, a.path ?? ""));
|
|
83
|
+
Object.assign(o, S(a.children, e, t, h));
|
|
84
84
|
}
|
|
85
85
|
}), o;
|
|
86
86
|
}
|
|
87
|
+
function de(l, e, t, s) {
|
|
88
|
+
if (!l || Object.keys(l).length === 0)
|
|
89
|
+
return !0;
|
|
90
|
+
const o = x(t), a = g(o) || "/", r = a === "/" ? "/" : a, i = l[o] ?? l[t] ?? l[a] ?? l[r] ?? (a !== "/" ? l[`/${a}`] : void 0);
|
|
91
|
+
if (!Array.isArray(i) || i.length === 0)
|
|
92
|
+
return !0;
|
|
93
|
+
const n = e.map((c) => c.code), f = i.filter((c) => n.includes(c));
|
|
94
|
+
return f.length === 0 ? !0 : f.includes(s);
|
|
95
|
+
}
|
|
87
96
|
function te(l) {
|
|
88
97
|
const e = {};
|
|
89
98
|
if (!l) return e;
|
|
90
99
|
for (const t in l) {
|
|
91
|
-
const
|
|
100
|
+
const s = x(t), o = l[t];
|
|
92
101
|
if (typeof o == "object") {
|
|
93
|
-
const
|
|
94
|
-
for (const
|
|
95
|
-
const
|
|
96
|
-
|
|
102
|
+
const a = {};
|
|
103
|
+
for (const r in o) {
|
|
104
|
+
const i = o[r];
|
|
105
|
+
i && (a[r] = x(i));
|
|
97
106
|
}
|
|
98
|
-
e[
|
|
107
|
+
e[s] = a;
|
|
99
108
|
} else
|
|
100
|
-
e[
|
|
109
|
+
e[s] = o;
|
|
101
110
|
}
|
|
102
111
|
return e;
|
|
103
112
|
}
|
|
104
113
|
class ae {
|
|
105
114
|
constructor(e) {
|
|
106
|
-
this.locales = e.locales, this.defaultLocale = this.findLocaleByCode(e.locales, e.defaultLocaleCode) ?? { code: e.defaultLocaleCode }, this.strategy = e.strategy, this.globalLocaleRoutes = te(e.globalLocaleRoutes ?? {}), this.filesLocaleRoutes = e.filesLocaleRoutes ?? {}, this.routeLocales = e.routeLocales ?? {}, this.localizedPaths =
|
|
115
|
+
this.locales = e.locales, this.defaultLocale = this.findLocaleByCode(e.locales, e.defaultLocaleCode) ?? { code: e.defaultLocaleCode }, this.strategy = e.strategy, this.globalLocaleRoutes = te(e.globalLocaleRoutes ?? {}), this.filesLocaleRoutes = e.filesLocaleRoutes ?? {}, this.routeLocales = e.routeLocales ?? {}, this.localizedPaths = S(e.pages, this.globalLocaleRoutes, this.filesLocaleRoutes), this.activeLocaleCodes = this.locales.filter((t) => t.code !== this.defaultLocale.code || K(this.strategy) || O(this.strategy)).map((t) => t.code), this.excludePatterns = e.excludePatterns, this.customRegex = e.customRegex, this.noPrefixRedirect = e.noPrefixRedirect ?? !1, this.localizedRouteNamePrefix = e.localizedRouteNamePrefix ?? "localized-", this.fallbackRedirectComponentPath = e.fallbackRedirectComponentPath, this.rawGlobalLocaleRoutes = e.rawGlobalLocaleRoutes;
|
|
107
116
|
}
|
|
108
117
|
findLocaleByCode(e, t) {
|
|
109
|
-
return e.find((
|
|
118
|
+
return e.find((s) => s.code === t);
|
|
110
119
|
}
|
|
111
120
|
/**
|
|
112
121
|
* Returns the list of locale codes allowed for a page (respecting routeLocales).
|
|
113
122
|
*/
|
|
114
123
|
getAllowedLocales(e, t) {
|
|
115
|
-
const
|
|
116
|
-
return
|
|
124
|
+
const s = this.routeLocales[e] ?? this.routeLocales[t];
|
|
125
|
+
return s?.length ? s.filter((o) => this.locales.some((a) => a.code === o)) : this.locales.map((o) => o.code);
|
|
117
126
|
}
|
|
118
127
|
/**
|
|
119
128
|
* Returns a custom path for a given locale by original page path, if any.
|
|
120
129
|
*/
|
|
121
130
|
getCustomPath(e, t) {
|
|
122
|
-
const
|
|
123
|
-
return this.localizedPaths[
|
|
131
|
+
const s = F(e);
|
|
132
|
+
return this.localizedPaths[s]?.[t];
|
|
124
133
|
}
|
|
125
134
|
/**
|
|
126
135
|
* Returns a map of custom paths (locale → path) for a page by path key or name.
|
|
127
136
|
*/
|
|
128
137
|
getCustomPathsForPage(e, t) {
|
|
129
|
-
const
|
|
130
|
-
return this.localizedPaths[
|
|
138
|
+
const s = F(e);
|
|
139
|
+
return this.localizedPaths[s] ?? this.localizedPaths[t];
|
|
131
140
|
}
|
|
132
141
|
hasLocaleRestrictions(e, t) {
|
|
133
142
|
return !!(this.routeLocales[e] ?? this.routeLocales[t]);
|
|
134
143
|
}
|
|
135
144
|
filterLocaleCodesWithoutCustomPaths(e) {
|
|
136
145
|
const t = F(e);
|
|
137
|
-
return this.activeLocaleCodes.filter((
|
|
146
|
+
return this.activeLocaleCodes.filter((s) => !this.localizedPaths[t]?.[s]);
|
|
138
147
|
}
|
|
139
148
|
}
|
|
140
149
|
function z(l, e) {
|
|
141
150
|
const t = (e ?? "").trim();
|
|
142
|
-
return t.startsWith("/") ? R(t) : R(
|
|
151
|
+
return t.startsWith("/") ? R(t) : R(w.posix.join(l || "", t));
|
|
143
152
|
}
|
|
144
153
|
function p(l, e) {
|
|
145
|
-
const { path: t, name:
|
|
154
|
+
const { path: t, name: s, children: o, meta: a, alias: r } = e, i = {
|
|
146
155
|
...l,
|
|
147
156
|
path: t
|
|
148
157
|
};
|
|
149
|
-
return
|
|
158
|
+
return s !== void 0 && (i.name = s), o !== void 0 && (i.children = o), a !== void 0 && (i.meta = { ...l.meta, ...a }), r !== void 0 ? (i.alias = r, i.meta = { ...i.meta, alias: r }) : "alias" in e && (i.alias = void 0, i.meta = { ...i.meta, alias: void 0 }), i;
|
|
150
159
|
}
|
|
151
160
|
function se(l) {
|
|
152
|
-
const e = l.alias, t = l.meta?.alias,
|
|
153
|
-
return Array.isArray(
|
|
161
|
+
const e = l.alias, t = l.meta?.alias, s = e ?? t;
|
|
162
|
+
return Array.isArray(s) ? s : [];
|
|
154
163
|
}
|
|
155
|
-
function _(l, e, t,
|
|
164
|
+
function _(l, e, t, s = "localized-") {
|
|
156
165
|
const o = se(l);
|
|
157
166
|
if (!o.length) return [];
|
|
158
|
-
const
|
|
159
|
-
for (const
|
|
160
|
-
const
|
|
161
|
-
|
|
167
|
+
const a = [];
|
|
168
|
+
for (const r of o) {
|
|
169
|
+
const i = A(e, r, t);
|
|
170
|
+
a.push(
|
|
162
171
|
p(l, {
|
|
163
|
-
path:
|
|
164
|
-
name: `${
|
|
172
|
+
path: i,
|
|
173
|
+
name: `${s}${l.name ?? ""}`,
|
|
165
174
|
alias: void 0,
|
|
166
175
|
meta: { alias: void 0 },
|
|
167
176
|
// Important: if the source page has children, the alias route
|
|
@@ -171,18 +180,18 @@ function _(l, e, t, a = "localized-") {
|
|
|
171
180
|
})
|
|
172
181
|
);
|
|
173
182
|
}
|
|
174
|
-
return
|
|
183
|
+
return a;
|
|
175
184
|
}
|
|
176
|
-
class
|
|
185
|
+
class k {
|
|
177
186
|
processPage(e, t) {
|
|
178
187
|
if (e.path === void 0)
|
|
179
188
|
throw new Error("page.path is required");
|
|
180
189
|
if (q(e))
|
|
181
190
|
return [e];
|
|
182
|
-
if (e.path &&
|
|
191
|
+
if (e.path && D(e.path, t.excludePatterns))
|
|
183
192
|
return [e];
|
|
184
|
-
const
|
|
185
|
-
return t.globalLocaleRoutes[o] === !1 || t.globalLocaleRoutes[
|
|
193
|
+
const s = e.path ?? "", o = b(e.name, e.path), a = x(s);
|
|
194
|
+
return t.globalLocaleRoutes[o] === !1 || t.globalLocaleRoutes[a] === !1 ? [e] : this.generateVariants(e, t);
|
|
186
195
|
}
|
|
187
196
|
postProcess(e, t) {
|
|
188
197
|
return e;
|
|
@@ -193,24 +202,24 @@ class S {
|
|
|
193
202
|
* - parentLocalizedPath used for the final path,
|
|
194
203
|
* and returns an array of localized child routes.
|
|
195
204
|
*/
|
|
196
|
-
localizeChildren(e, t,
|
|
197
|
-
return e.flatMap((
|
|
205
|
+
localizeChildren(e, t, s, o, a, r) {
|
|
206
|
+
return e.flatMap((i) => this.localizeChild(i, t, s, o, a, r));
|
|
198
207
|
}
|
|
199
208
|
/**
|
|
200
209
|
* Variant for a single route with :locale(locale1|locale2) — without custom paths.
|
|
201
210
|
* Returns a single child route with a relative path and recursively localized children.
|
|
202
211
|
*/
|
|
203
|
-
localizeChildrenAllLocales(e, t,
|
|
204
|
-
return e.flatMap((
|
|
205
|
-
}
|
|
206
|
-
localizeChildAllLocales(e, t,
|
|
207
|
-
const
|
|
208
|
-
if (
|
|
209
|
-
return o.flatMap((
|
|
210
|
-
const P = d
|
|
211
|
-
return this.localizeChild(e, P,
|
|
212
|
+
localizeChildrenAllLocales(e, t, s, o, a) {
|
|
213
|
+
return e.flatMap((r) => this.localizeChildAllLocales(r, t, s, o, a));
|
|
214
|
+
}
|
|
215
|
+
localizeChildAllLocales(e, t, s, o, a) {
|
|
216
|
+
const r = z(s, e.path ?? ""), i = z(t, e.path ?? ""), n = F(i), f = a.localizedPaths[n];
|
|
217
|
+
if (f)
|
|
218
|
+
return o.flatMap((d) => {
|
|
219
|
+
const P = f[d] ?? z(t, e.path ?? "");
|
|
220
|
+
return this.localizeChild(e, P, s, d, a, !0);
|
|
212
221
|
});
|
|
213
|
-
const
|
|
222
|
+
const c = R(e.path ?? ""), h = g(c), u = this.localizeChildrenAllLocales($(e.children ?? []), i, r, o, a), m = `${a.localizedRouteNamePrefix}${e.name ?? ""}`;
|
|
214
223
|
return [
|
|
215
224
|
p(e, {
|
|
216
225
|
path: h,
|
|
@@ -219,11 +228,11 @@ class S {
|
|
|
219
228
|
})
|
|
220
229
|
];
|
|
221
230
|
}
|
|
222
|
-
localizeChild(e, t,
|
|
223
|
-
const
|
|
231
|
+
localizeChild(e, t, s, o, a, r) {
|
|
232
|
+
const i = z(s, e.path ?? ""), n = a.getCustomPath(i, o), f = g(R(n || (e.path ?? ""))), c = n ?? z(t, e.path ?? ""), h = this.localizeChildren($(e.children ?? []), c, i, o, a, r), u = b(e.name, e.path), m = `${a.localizedRouteNamePrefix}${u}-${o}`;
|
|
224
233
|
return [
|
|
225
234
|
p(e, {
|
|
226
|
-
path:
|
|
235
|
+
path: f,
|
|
227
236
|
name: m,
|
|
228
237
|
children: h
|
|
229
238
|
})
|
|
@@ -236,36 +245,36 @@ class S {
|
|
|
236
245
|
*
|
|
237
246
|
* The logic matches what used to be duplicated in each strategy's buildRoutePath.
|
|
238
247
|
*/
|
|
239
|
-
buildRoutePathForLocales(e, t,
|
|
248
|
+
buildRoutePathForLocales(e, t, s, o, a, r, i) {
|
|
240
249
|
if (o) {
|
|
241
|
-
const
|
|
242
|
-
return
|
|
250
|
+
const n = e.includes(i);
|
|
251
|
+
return r || !n ? A(e, s, a) : R(s);
|
|
243
252
|
}
|
|
244
|
-
return A(e, t,
|
|
253
|
+
return A(e, t, a);
|
|
245
254
|
}
|
|
246
255
|
}
|
|
247
|
-
class oe extends
|
|
256
|
+
class oe extends k {
|
|
248
257
|
generateVariants(e, t) {
|
|
249
|
-
const
|
|
250
|
-
if (
|
|
251
|
-
for (const
|
|
252
|
-
const
|
|
253
|
-
if (!
|
|
254
|
-
const h = R(
|
|
258
|
+
const s = e.path ?? "", o = b(e.name, e.path), a = t.getAllowedLocales(s, o), r = t.getCustomPathsForPage(s, o), i = $(e.children ?? []), n = [];
|
|
259
|
+
if (n.push(e), r)
|
|
260
|
+
for (const f of a) {
|
|
261
|
+
const c = r[f];
|
|
262
|
+
if (!c) continue;
|
|
263
|
+
const h = R(c), u = R(s);
|
|
255
264
|
if (h === u)
|
|
256
265
|
continue;
|
|
257
|
-
const m = Z(
|
|
258
|
-
|
|
266
|
+
const m = Z(c), d = j(o, f, !0), P = this.localizeChildrenForNoPrefix(i, h, s, s, f, t, 1);
|
|
267
|
+
n.push(
|
|
259
268
|
p(e, {
|
|
260
269
|
path: m,
|
|
261
|
-
name:
|
|
270
|
+
name: d,
|
|
262
271
|
children: P,
|
|
263
272
|
alias: [],
|
|
264
273
|
meta: { alias: [] }
|
|
265
274
|
})
|
|
266
|
-
), t.noPrefixRedirect &&
|
|
275
|
+
), t.noPrefixRedirect && f === t.defaultLocale.code && h !== u && (e.redirect = h);
|
|
267
276
|
}
|
|
268
|
-
return
|
|
277
|
+
return n.push(..._(e, a, t.customRegex, t.localizedRouteNamePrefix)), n;
|
|
269
278
|
}
|
|
270
279
|
/**
|
|
271
280
|
* Localizes the children tree for the no_prefix strategy.
|
|
@@ -273,35 +282,35 @@ class oe extends S {
|
|
|
273
282
|
* - on the first level, custom paths (globalLocaleRoutes/filesLocaleRoutes) are applied;
|
|
274
283
|
* - on deeper levels, path stays as a segment (item, detail, etc.).
|
|
275
284
|
*/
|
|
276
|
-
localizeChildrenForNoPrefix(e, t,
|
|
277
|
-
return e.map((
|
|
278
|
-
const
|
|
279
|
-
let
|
|
280
|
-
if (
|
|
281
|
-
const P =
|
|
285
|
+
localizeChildrenForNoPrefix(e, t, s, o, a, r, i) {
|
|
286
|
+
return e.map((n) => {
|
|
287
|
+
const f = z(s, n.path ?? "");
|
|
288
|
+
let c, h;
|
|
289
|
+
if (i === 1) {
|
|
290
|
+
const P = r.getCustomPath(f, a);
|
|
282
291
|
if (P) {
|
|
283
292
|
const L = R(P);
|
|
284
|
-
|
|
293
|
+
c = g(L), h = L;
|
|
285
294
|
} else {
|
|
286
|
-
const L = R(
|
|
287
|
-
|
|
295
|
+
const L = R(n.path ?? "");
|
|
296
|
+
c = g(L), h = z(t, n.path ?? "");
|
|
288
297
|
}
|
|
289
298
|
} else {
|
|
290
|
-
const P = R(
|
|
291
|
-
|
|
299
|
+
const P = R(n.path ?? "");
|
|
300
|
+
c = g(P), h = z(t, n.path ?? "");
|
|
292
301
|
}
|
|
293
302
|
const u = this.localizeChildrenForNoPrefix(
|
|
294
|
-
$(
|
|
303
|
+
$(n.children ?? []),
|
|
295
304
|
h,
|
|
296
|
-
|
|
305
|
+
f,
|
|
297
306
|
o,
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
), m = b(
|
|
302
|
-
return p(
|
|
303
|
-
path:
|
|
304
|
-
name:
|
|
307
|
+
a,
|
|
308
|
+
r,
|
|
309
|
+
i + 1
|
|
310
|
+
), m = b(n.name, n.path), d = j(m, a, !0);
|
|
311
|
+
return p(n, {
|
|
312
|
+
path: c,
|
|
313
|
+
name: d,
|
|
305
314
|
children: u
|
|
306
315
|
});
|
|
307
316
|
});
|
|
@@ -311,16 +320,16 @@ function le(l) {
|
|
|
311
320
|
const e = l.alias ?? l.meta?.alias;
|
|
312
321
|
return Array.isArray(e) ? e : [];
|
|
313
322
|
}
|
|
314
|
-
class ie extends
|
|
323
|
+
class ie extends k {
|
|
315
324
|
generateVariants(e, t) {
|
|
316
|
-
const
|
|
317
|
-
if (
|
|
318
|
-
for (const
|
|
319
|
-
const h =
|
|
320
|
-
|
|
325
|
+
const s = e.path ?? "", o = b(e.name, e.path), a = t.getAllowedLocales(s, o), r = t.getCustomPathsForPage(s, o), i = $(e.children ?? []), n = [];
|
|
326
|
+
if (r)
|
|
327
|
+
for (const c of a) {
|
|
328
|
+
const h = r[c], u = h ? R(h) : s, m = A(c, u, t.customRegex), d = j(o, c, !!h, t.localizedRouteNamePrefix), P = h ?? s, L = this.localizeChildren(i, P, s, c, t, !0);
|
|
329
|
+
n.push(
|
|
321
330
|
p(e, {
|
|
322
331
|
path: m,
|
|
323
|
-
name:
|
|
332
|
+
name: d,
|
|
324
333
|
children: L,
|
|
325
334
|
alias: [],
|
|
326
335
|
meta: { alias: [] }
|
|
@@ -328,10 +337,10 @@ class ie extends S {
|
|
|
328
337
|
);
|
|
329
338
|
}
|
|
330
339
|
else {
|
|
331
|
-
const
|
|
332
|
-
|
|
340
|
+
const c = A(a, s, t.customRegex), h = j(o, a[0], !1, t.localizedRouteNamePrefix), u = this.localizeChildrenAllLocales(i, s, s, a, t);
|
|
341
|
+
n.push(
|
|
333
342
|
p(e, {
|
|
334
|
-
path:
|
|
343
|
+
path: c,
|
|
335
344
|
name: h,
|
|
336
345
|
children: u,
|
|
337
346
|
alias: [],
|
|
@@ -339,11 +348,11 @@ class ie extends S {
|
|
|
339
348
|
})
|
|
340
349
|
);
|
|
341
350
|
}
|
|
342
|
-
const
|
|
343
|
-
if (
|
|
344
|
-
for (const
|
|
345
|
-
const h = A(
|
|
346
|
-
|
|
351
|
+
const f = le(e);
|
|
352
|
+
if (f.length)
|
|
353
|
+
for (const c of f) {
|
|
354
|
+
const h = A(a, c, t.customRegex);
|
|
355
|
+
n.push(
|
|
347
356
|
p(e, {
|
|
348
357
|
path: h,
|
|
349
358
|
name: `${t.localizedRouteNamePrefix}${e.name ?? ""}`,
|
|
@@ -352,172 +361,172 @@ class ie extends S {
|
|
|
352
361
|
})
|
|
353
362
|
);
|
|
354
363
|
}
|
|
355
|
-
return
|
|
364
|
+
return n;
|
|
356
365
|
}
|
|
357
366
|
postProcess(e, t) {
|
|
358
|
-
const
|
|
359
|
-
if (
|
|
360
|
-
const
|
|
361
|
-
return !!(
|
|
367
|
+
const s = e.filter((a) => {
|
|
368
|
+
if (a.name === "index" && a.path === "/") return !1;
|
|
369
|
+
const r = a.path ?? "";
|
|
370
|
+
return !!(r && D(r, t.excludePatterns) || t.globalLocaleRoutes[a.name ?? ""] === !1 || /^\/:locale/.test(r) || r === "/");
|
|
362
371
|
}), o = t.defaultLocale.code;
|
|
363
|
-
for (const [
|
|
364
|
-
if (
|
|
365
|
-
const
|
|
366
|
-
if (!
|
|
367
|
-
const
|
|
368
|
-
|
|
369
|
-
path:
|
|
370
|
-
name: `redirect-${
|
|
371
|
-
redirect:
|
|
372
|
+
for (const [a, r] of Object.entries(t.globalLocaleRoutes)) {
|
|
373
|
+
if (r === !1 || typeof r != "object") continue;
|
|
374
|
+
const i = r[o];
|
|
375
|
+
if (!i) continue;
|
|
376
|
+
const n = a.startsWith("/") ? a : `/${a}`, f = `/${o}${i.startsWith("/") ? i : `/${i}`}`;
|
|
377
|
+
n !== f && s.push({
|
|
378
|
+
path: n,
|
|
379
|
+
name: `redirect-${a.replace(/\//g, "-")}`,
|
|
380
|
+
redirect: f
|
|
372
381
|
});
|
|
373
382
|
}
|
|
374
|
-
return t.fallbackRedirectComponentPath &&
|
|
383
|
+
return t.fallbackRedirectComponentPath && s.push({
|
|
375
384
|
path: "/:pathMatch(.*)*",
|
|
376
385
|
name: "custom-fallback-route",
|
|
377
386
|
file: t.fallbackRedirectComponentPath,
|
|
378
387
|
meta: {
|
|
379
388
|
globalLocaleRoutes: t.rawGlobalLocaleRoutes ?? t.globalLocaleRoutes
|
|
380
389
|
}
|
|
381
|
-
}),
|
|
390
|
+
}), s;
|
|
382
391
|
}
|
|
383
392
|
}
|
|
384
|
-
class re extends
|
|
393
|
+
class re extends k {
|
|
385
394
|
generateVariants(e, t) {
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
const
|
|
389
|
-
if (
|
|
390
|
-
if (
|
|
391
|
-
for (const u of
|
|
392
|
-
const m =
|
|
395
|
+
const s = e.path ?? "", o = b(e.name, e.path), a = t.getAllowedLocales(s, o), r = t.getCustomPathsForPage(s, o), i = $(e.children ?? []), n = [], f = t.defaultLocale.code;
|
|
396
|
+
n.push(e);
|
|
397
|
+
const c = t.locales.filter((u) => a.includes(u.code));
|
|
398
|
+
if (c.length > 0)
|
|
399
|
+
if (r)
|
|
400
|
+
for (const u of c) {
|
|
401
|
+
const m = r[u.code];
|
|
393
402
|
if (m)
|
|
394
|
-
if (u.code ===
|
|
395
|
-
const
|
|
403
|
+
if (u.code === f) {
|
|
404
|
+
const d = this.createLocalizedRoute(
|
|
396
405
|
e,
|
|
397
406
|
[u.code],
|
|
398
|
-
|
|
407
|
+
i,
|
|
399
408
|
!0,
|
|
400
409
|
m,
|
|
401
410
|
t.customRegex,
|
|
402
411
|
!1,
|
|
403
412
|
u.code,
|
|
404
|
-
|
|
413
|
+
s,
|
|
405
414
|
t
|
|
406
415
|
);
|
|
407
|
-
|
|
416
|
+
d && n.push(d);
|
|
408
417
|
const P = this.createLocalizedRoute(
|
|
409
418
|
e,
|
|
410
419
|
[u.code],
|
|
411
|
-
|
|
420
|
+
i,
|
|
412
421
|
!0,
|
|
413
422
|
m,
|
|
414
423
|
t.customRegex,
|
|
415
424
|
!0,
|
|
416
425
|
u.code,
|
|
417
|
-
|
|
426
|
+
s,
|
|
418
427
|
t
|
|
419
428
|
);
|
|
420
|
-
P &&
|
|
429
|
+
P && n.push(P);
|
|
421
430
|
} else {
|
|
422
|
-
const
|
|
431
|
+
const d = this.createLocalizedRoute(
|
|
423
432
|
e,
|
|
424
433
|
[u.code],
|
|
425
|
-
|
|
434
|
+
i,
|
|
426
435
|
!0,
|
|
427
436
|
m,
|
|
428
437
|
t.customRegex,
|
|
429
438
|
!1,
|
|
430
439
|
u.code,
|
|
431
|
-
|
|
440
|
+
s,
|
|
432
441
|
t
|
|
433
442
|
);
|
|
434
|
-
|
|
443
|
+
d && n.push(d);
|
|
435
444
|
}
|
|
436
445
|
else {
|
|
437
|
-
const
|
|
446
|
+
const d = this.createLocalizedRoute(
|
|
438
447
|
e,
|
|
439
448
|
[u.code],
|
|
440
|
-
|
|
449
|
+
i,
|
|
441
450
|
!1,
|
|
442
451
|
"",
|
|
443
452
|
t.customRegex,
|
|
444
453
|
!1,
|
|
445
454
|
u.code,
|
|
446
|
-
|
|
455
|
+
s,
|
|
447
456
|
t
|
|
448
457
|
);
|
|
449
|
-
|
|
458
|
+
d && n.push(d);
|
|
450
459
|
}
|
|
451
460
|
}
|
|
452
461
|
else {
|
|
453
|
-
const u =
|
|
462
|
+
const u = c.map((d) => d.code), m = this.createLocalizedRoute(
|
|
454
463
|
e,
|
|
455
464
|
u,
|
|
456
|
-
|
|
465
|
+
i,
|
|
457
466
|
!1,
|
|
458
467
|
"",
|
|
459
468
|
t.customRegex,
|
|
460
469
|
!1,
|
|
461
470
|
!0,
|
|
462
|
-
|
|
471
|
+
s,
|
|
463
472
|
t
|
|
464
473
|
);
|
|
465
|
-
m &&
|
|
474
|
+
m && n.push(m);
|
|
466
475
|
}
|
|
467
|
-
const h = _(e,
|
|
468
|
-
return h.length &&
|
|
476
|
+
const h = _(e, a, t.customRegex, t.localizedRouteNamePrefix);
|
|
477
|
+
return h.length && n.push(...h), n;
|
|
469
478
|
}
|
|
470
479
|
postProcess(e, t) {
|
|
471
|
-
const
|
|
472
|
-
for (const
|
|
473
|
-
const
|
|
474
|
-
typeof
|
|
480
|
+
const s = [], o = [];
|
|
481
|
+
for (const a of e) {
|
|
482
|
+
const r = a.name ?? "";
|
|
483
|
+
typeof r == "string" && r.startsWith(t.localizedRouteNamePrefix) ? o.push(a) : s.push(a);
|
|
475
484
|
}
|
|
476
|
-
return [...
|
|
485
|
+
return [...s, ...o];
|
|
477
486
|
}
|
|
478
|
-
createLocalizedRoute(e, t,
|
|
487
|
+
createLocalizedRoute(e, t, s, o, a = "", r, i = !1, n = !1, f, c) {
|
|
479
488
|
const h = this.buildRoutePathForLocales(
|
|
480
489
|
t,
|
|
481
490
|
e.path ?? "",
|
|
482
|
-
encodeURI(
|
|
491
|
+
encodeURI(a),
|
|
483
492
|
o,
|
|
484
|
-
i,
|
|
485
493
|
r,
|
|
486
|
-
|
|
494
|
+
i,
|
|
495
|
+
c.defaultLocale.code
|
|
487
496
|
);
|
|
488
|
-
if (!h || !(o &&
|
|
497
|
+
if (!h || !(o && a) && h === e.path || t.length === 0) return null;
|
|
489
498
|
const m = t[0];
|
|
490
499
|
if (!m) return null;
|
|
491
|
-
const
|
|
492
|
-
b(e.name ?? "",
|
|
500
|
+
const d = f ?? e.path ?? "", P = j(
|
|
501
|
+
b(e.name ?? "", d),
|
|
493
502
|
m,
|
|
494
503
|
o,
|
|
495
|
-
|
|
496
|
-
), L =
|
|
504
|
+
c.localizedRouteNamePrefix
|
|
505
|
+
), L = i || m !== c.defaultLocale.code, y = t.length === 1 ? this.localizeChildren(s, h, d, m, c, L) : this.localizeChildrenAllLocales(s, h, d, t, c);
|
|
497
506
|
return p(e, {
|
|
498
507
|
path: h,
|
|
499
508
|
name: P,
|
|
500
|
-
children:
|
|
509
|
+
children: y,
|
|
501
510
|
alias: [],
|
|
502
511
|
meta: { alias: [] }
|
|
503
512
|
});
|
|
504
513
|
}
|
|
505
514
|
}
|
|
506
|
-
class
|
|
515
|
+
class ne extends k {
|
|
507
516
|
generateVariants(e, t) {
|
|
508
|
-
const
|
|
509
|
-
if (
|
|
510
|
-
const u =
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
[
|
|
517
|
+
const s = e.path ?? "", o = b(e.name, e.path), a = t.getAllowedLocales(s, o), r = t.getCustomPathsForPage(s, o), i = $(e.children ?? []), n = [], f = t.defaultLocale.code;
|
|
518
|
+
if (a.includes(f)) {
|
|
519
|
+
const u = r?.[f], m = u ? R(u) : s, d = u ? { [f]: u } : {}, P = this.createLocalizedChildren(
|
|
520
|
+
i,
|
|
521
|
+
s,
|
|
522
|
+
[f],
|
|
514
523
|
!1,
|
|
515
524
|
!1,
|
|
516
525
|
!1,
|
|
517
|
-
|
|
526
|
+
d,
|
|
518
527
|
t
|
|
519
528
|
);
|
|
520
|
-
|
|
529
|
+
n.push(
|
|
521
530
|
p(e, {
|
|
522
531
|
path: m,
|
|
523
532
|
name: e.name,
|
|
@@ -525,125 +534,125 @@ class ce extends S {
|
|
|
525
534
|
})
|
|
526
535
|
);
|
|
527
536
|
}
|
|
528
|
-
const
|
|
529
|
-
if (
|
|
530
|
-
if (
|
|
531
|
-
for (const u of
|
|
532
|
-
const m =
|
|
537
|
+
const c = t.locales.filter((u) => a.includes(u.code) && u.code !== f);
|
|
538
|
+
if (c.length)
|
|
539
|
+
if (r)
|
|
540
|
+
for (const u of c) {
|
|
541
|
+
const m = r[u.code];
|
|
533
542
|
if (m) {
|
|
534
|
-
const
|
|
543
|
+
const d = this.createLocalizedRoute(
|
|
535
544
|
e,
|
|
536
545
|
[u.code],
|
|
537
|
-
|
|
546
|
+
i,
|
|
538
547
|
!0,
|
|
539
548
|
m,
|
|
540
549
|
t.customRegex,
|
|
541
550
|
!1,
|
|
542
551
|
u.code,
|
|
543
|
-
|
|
552
|
+
s,
|
|
544
553
|
t
|
|
545
554
|
);
|
|
546
|
-
|
|
555
|
+
d && n.push(d);
|
|
547
556
|
} else {
|
|
548
|
-
const
|
|
557
|
+
const d = this.createLocalizedRoute(
|
|
549
558
|
e,
|
|
550
559
|
[u.code],
|
|
551
|
-
|
|
560
|
+
i,
|
|
552
561
|
!1,
|
|
553
562
|
"",
|
|
554
563
|
t.customRegex,
|
|
555
564
|
!1,
|
|
556
565
|
u.code,
|
|
557
|
-
|
|
566
|
+
s,
|
|
558
567
|
t
|
|
559
568
|
);
|
|
560
|
-
|
|
569
|
+
d && n.push(d);
|
|
561
570
|
}
|
|
562
571
|
}
|
|
563
572
|
else {
|
|
564
|
-
const u =
|
|
573
|
+
const u = c.map((d) => d.code), m = this.createLocalizedRoute(
|
|
565
574
|
e,
|
|
566
575
|
u,
|
|
567
|
-
|
|
576
|
+
i,
|
|
568
577
|
!1,
|
|
569
578
|
"",
|
|
570
579
|
t.customRegex,
|
|
571
580
|
!1,
|
|
572
581
|
!0,
|
|
573
|
-
|
|
582
|
+
s,
|
|
574
583
|
t
|
|
575
584
|
);
|
|
576
|
-
m &&
|
|
585
|
+
m && n.push(m);
|
|
577
586
|
}
|
|
578
|
-
const h = _(e,
|
|
579
|
-
return h.length &&
|
|
587
|
+
const h = _(e, a, t.customRegex, t.localizedRouteNamePrefix);
|
|
588
|
+
return h.length && n.push(...h), n;
|
|
580
589
|
}
|
|
581
590
|
postProcess(e, t) {
|
|
582
|
-
const
|
|
583
|
-
for (const
|
|
584
|
-
const
|
|
585
|
-
typeof
|
|
591
|
+
const s = [], o = [];
|
|
592
|
+
for (const r of e) {
|
|
593
|
+
const i = r.name ?? "";
|
|
594
|
+
typeof i == "string" && i.startsWith(t.localizedRouteNamePrefix) ? o.push(r) : s.push(r);
|
|
586
595
|
}
|
|
587
|
-
const
|
|
588
|
-
return t.fallbackRedirectComponentPath &&
|
|
596
|
+
const a = [...s, ...o];
|
|
597
|
+
return t.fallbackRedirectComponentPath && a.push({
|
|
589
598
|
path: "/:pathMatch(.*)*",
|
|
590
599
|
name: "custom-fallback-route",
|
|
591
600
|
file: t.fallbackRedirectComponentPath,
|
|
592
601
|
meta: {
|
|
593
602
|
globalLocaleRoutes: t.rawGlobalLocaleRoutes ?? t.globalLocaleRoutes
|
|
594
603
|
}
|
|
595
|
-
}),
|
|
604
|
+
}), a;
|
|
596
605
|
}
|
|
597
|
-
createLocalizedChildren(e, t,
|
|
606
|
+
createLocalizedChildren(e, t, s, o = !0, a = !1, r = !1, i = {}, n) {
|
|
598
607
|
return e.flatMap(
|
|
599
|
-
(
|
|
608
|
+
(f) => this.createLocalizedVariants(f, t, s, o, a, r, i, n)
|
|
600
609
|
);
|
|
601
610
|
}
|
|
602
|
-
createLocalizedVariants(e, t,
|
|
603
|
-
const
|
|
611
|
+
createLocalizedVariants(e, t, s, o, a, r = !1, i, n) {
|
|
612
|
+
const f = R(e.path ?? ""), c = z(t, e.path ?? ""), h = F(c), u = n.localizedPaths[h], m = !!u, d = [];
|
|
604
613
|
if (!m) {
|
|
605
|
-
const P =
|
|
614
|
+
const P = g(f), L = this.createLocalizedChildren(
|
|
606
615
|
$(e.children ?? []),
|
|
607
616
|
z(t, e.path ?? ""),
|
|
608
|
-
a,
|
|
609
|
-
o,
|
|
610
617
|
s,
|
|
611
|
-
|
|
618
|
+
o,
|
|
619
|
+
a,
|
|
612
620
|
r,
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
621
|
+
i,
|
|
622
|
+
n
|
|
623
|
+
), y = this.buildChildRouteName(e.name, r, n);
|
|
624
|
+
return d.push(
|
|
616
625
|
p(e, {
|
|
617
626
|
path: P,
|
|
618
|
-
name:
|
|
627
|
+
name: y,
|
|
619
628
|
children: L
|
|
620
629
|
})
|
|
621
|
-
),
|
|
630
|
+
), d;
|
|
622
631
|
}
|
|
623
|
-
for (const P of
|
|
624
|
-
const L =
|
|
625
|
-
let
|
|
626
|
-
|
|
627
|
-
const v = H(P,
|
|
632
|
+
for (const P of s) {
|
|
633
|
+
const L = i?.[P], y = !!L, C = u?.[P];
|
|
634
|
+
let N = R(C || (e.path ?? ""));
|
|
635
|
+
y && L && (C ? N = R(C) : N = z(L, e.path ?? ""));
|
|
636
|
+
const v = H(P, n.defaultLocale, a) ? A(P, N, n.customRegex) : N, T = g(v), W = C ? R(C) : y ? L : z(t, e.path ?? ""), V = this.createLocalizedChildren(
|
|
628
637
|
$(e.children ?? []),
|
|
629
638
|
W,
|
|
630
639
|
[P],
|
|
631
640
|
o,
|
|
632
|
-
|
|
641
|
+
a,
|
|
633
642
|
P,
|
|
634
643
|
{
|
|
635
|
-
...
|
|
644
|
+
...i,
|
|
636
645
|
[P]: W
|
|
637
646
|
},
|
|
638
|
-
|
|
647
|
+
n
|
|
639
648
|
), I = this.buildLocalizedRouteName(
|
|
640
649
|
b(e.name, e.path),
|
|
641
650
|
P,
|
|
642
651
|
o,
|
|
643
652
|
!!u,
|
|
644
|
-
|
|
653
|
+
n
|
|
645
654
|
);
|
|
646
|
-
|
|
655
|
+
d.push(
|
|
647
656
|
p(e, {
|
|
648
657
|
path: T,
|
|
649
658
|
name: I,
|
|
@@ -651,52 +660,52 @@ class ce extends S {
|
|
|
651
660
|
})
|
|
652
661
|
);
|
|
653
662
|
}
|
|
654
|
-
return
|
|
663
|
+
return d;
|
|
655
664
|
}
|
|
656
|
-
buildChildRouteName(e, t,
|
|
657
|
-
return t === !0 ? `${
|
|
665
|
+
buildChildRouteName(e, t, s) {
|
|
666
|
+
return t === !0 ? `${s.localizedRouteNamePrefix}${e}` : typeof t == "string" ? `${s.localizedRouteNamePrefix}${e}-${t}` : e;
|
|
658
667
|
}
|
|
659
|
-
createLocalizedRoute(e, t,
|
|
668
|
+
createLocalizedRoute(e, t, s, o, a = "", r, i = !1, n = !1, f, c) {
|
|
660
669
|
const h = this.buildRoutePathForLocales(
|
|
661
670
|
t,
|
|
662
671
|
e.path ?? "",
|
|
663
|
-
encodeURI(
|
|
672
|
+
encodeURI(a),
|
|
664
673
|
o,
|
|
665
|
-
i,
|
|
666
674
|
r,
|
|
667
|
-
|
|
675
|
+
i,
|
|
676
|
+
c.defaultLocale.code
|
|
668
677
|
);
|
|
669
678
|
if (!h || h === e.path || t.length === 0) return null;
|
|
670
679
|
const u = t[0];
|
|
671
680
|
if (!u) return null;
|
|
672
|
-
const m =
|
|
681
|
+
const m = f ?? e.path ?? "", d = j(
|
|
673
682
|
b(e.name ?? "", m),
|
|
674
683
|
u,
|
|
675
684
|
o,
|
|
676
|
-
|
|
685
|
+
c.localizedRouteNamePrefix
|
|
677
686
|
);
|
|
678
687
|
return p(e, {
|
|
679
688
|
path: h,
|
|
680
|
-
name:
|
|
689
|
+
name: d,
|
|
681
690
|
children: this.createLocalizedChildren(
|
|
682
|
-
|
|
691
|
+
s,
|
|
683
692
|
m,
|
|
684
693
|
t,
|
|
685
694
|
!0,
|
|
686
695
|
!1,
|
|
687
|
-
|
|
688
|
-
{ [u]:
|
|
689
|
-
|
|
696
|
+
n,
|
|
697
|
+
{ [u]: a },
|
|
698
|
+
c
|
|
690
699
|
),
|
|
691
700
|
alias: [],
|
|
692
701
|
meta: { alias: [] }
|
|
693
702
|
});
|
|
694
703
|
}
|
|
695
|
-
buildLocalizedRouteName(e, t,
|
|
696
|
-
return
|
|
704
|
+
buildLocalizedRouteName(e, t, s, o = !1, a) {
|
|
705
|
+
return s ? o ? `${a.localizedRouteNamePrefix}${e}-${t}` : t && !J(t, a.defaultLocale) ? `${a.localizedRouteNamePrefix}${e}-${t}` : `${a.localizedRouteNamePrefix}${e}` : e;
|
|
697
706
|
}
|
|
698
707
|
}
|
|
699
|
-
function
|
|
708
|
+
function ce(l) {
|
|
700
709
|
switch (l) {
|
|
701
710
|
case "no_prefix":
|
|
702
711
|
return new oe();
|
|
@@ -705,45 +714,45 @@ function ne(l) {
|
|
|
705
714
|
case "prefix_and_default":
|
|
706
715
|
return new re();
|
|
707
716
|
case "prefix_except_default":
|
|
708
|
-
return new
|
|
717
|
+
return new ne();
|
|
709
718
|
default:
|
|
710
719
|
throw new Error(`Unknown route strategy: ${l}`);
|
|
711
720
|
}
|
|
712
721
|
}
|
|
713
|
-
class
|
|
722
|
+
class me {
|
|
714
723
|
constructor(e) {
|
|
715
724
|
this.localizedPaths = {};
|
|
716
725
|
const {
|
|
717
726
|
locales: t,
|
|
718
|
-
defaultLocaleCode:
|
|
727
|
+
defaultLocaleCode: s,
|
|
719
728
|
strategy: o,
|
|
720
|
-
globalLocaleRoutes:
|
|
721
|
-
filesLocaleRoutes:
|
|
722
|
-
routeLocales:
|
|
723
|
-
noPrefixRedirect:
|
|
724
|
-
excludePatterns:
|
|
725
|
-
localizedRouteNamePrefix:
|
|
729
|
+
globalLocaleRoutes: a,
|
|
730
|
+
filesLocaleRoutes: r = {},
|
|
731
|
+
routeLocales: i = {},
|
|
732
|
+
noPrefixRedirect: n,
|
|
733
|
+
excludePatterns: f,
|
|
734
|
+
localizedRouteNamePrefix: c = "localized-",
|
|
726
735
|
customRegexMatcher: h,
|
|
727
736
|
fallbackRedirectComponentPath: u
|
|
728
|
-
} = e, m = X(t,
|
|
729
|
-
this.locales = m.locales, this.defaultLocale = m.defaultLocale, this.strategy = o, this.noPrefixRedirect =
|
|
730
|
-
const
|
|
731
|
-
for (const P in
|
|
732
|
-
const L =
|
|
733
|
-
if (typeof
|
|
737
|
+
} = e, m = X(t, s);
|
|
738
|
+
this.locales = m.locales, this.defaultLocale = m.defaultLocale, this.strategy = o, this.noPrefixRedirect = n, this.excludePatterns = f, this.localizedRouteNamePrefix = c, this.customRegex = h, this.fallbackRedirectComponentPath = u, this.activeLocaleCodes = this.computeActiveLocaleCodes();
|
|
739
|
+
const d = {};
|
|
740
|
+
for (const P in a) {
|
|
741
|
+
const L = x(P), y = a[P];
|
|
742
|
+
if (typeof y == "object") {
|
|
734
743
|
const C = {};
|
|
735
|
-
for (const
|
|
736
|
-
const v =
|
|
737
|
-
v && (C[
|
|
744
|
+
for (const N in y) {
|
|
745
|
+
const v = y[N];
|
|
746
|
+
v && (C[N] = x(v));
|
|
738
747
|
}
|
|
739
|
-
|
|
748
|
+
d[L] = C;
|
|
740
749
|
} else
|
|
741
|
-
|
|
750
|
+
d[L] = y;
|
|
742
751
|
}
|
|
743
|
-
this.globalLocaleRoutes =
|
|
752
|
+
this.globalLocaleRoutes = d, this.rawGlobalLocaleRoutes = a ?? {}, this.filesLocaleRoutes = r ?? {}, this.routeLocales = i ?? {};
|
|
744
753
|
}
|
|
745
754
|
computeActiveLocaleCodes() {
|
|
746
|
-
return this.locales.filter((e) => e.code !== this.defaultLocale.code ||
|
|
755
|
+
return this.locales.filter((e) => e.code !== this.defaultLocale.code || K(this.strategy) || O(this.strategy)).map((e) => e.code);
|
|
747
756
|
}
|
|
748
757
|
extendPages(e) {
|
|
749
758
|
const t = new ae({
|
|
@@ -762,31 +771,31 @@ class de {
|
|
|
762
771
|
rawGlobalLocaleRoutes: this.rawGlobalLocaleRoutes
|
|
763
772
|
});
|
|
764
773
|
this.localizedPaths = t.localizedPaths;
|
|
765
|
-
const
|
|
766
|
-
for (const
|
|
767
|
-
|
|
768
|
-
const
|
|
769
|
-
e.length = 0, e.push(...
|
|
774
|
+
const s = ce(this.strategy), o = [...e], a = [];
|
|
775
|
+
for (const i of o)
|
|
776
|
+
a.push(...s.processPage(i, t));
|
|
777
|
+
const r = s.postProcess(a, t);
|
|
778
|
+
e.length = 0, e.push(...r);
|
|
770
779
|
}
|
|
771
780
|
extractLocalizedPaths(e, t = "") {
|
|
772
|
-
return
|
|
781
|
+
return S(e, this.globalLocaleRoutes, this.filesLocaleRoutes, t);
|
|
773
782
|
}
|
|
774
783
|
/**
|
|
775
784
|
* Creates global and per-page translation JSON files for the current resolved locales.
|
|
776
785
|
*/
|
|
777
|
-
ensureTranslationFilesExist(e, t,
|
|
778
|
-
this.locales.forEach((
|
|
779
|
-
const
|
|
780
|
-
this.ensureFileExists(
|
|
781
|
-
const
|
|
782
|
-
this.ensureFileExists(
|
|
786
|
+
ensureTranslationFilesExist(e, t, s, o) {
|
|
787
|
+
this.locales.forEach((a) => {
|
|
788
|
+
const r = w.join(s, t, `${a.code}.json`);
|
|
789
|
+
this.ensureFileExists(r), o || e.forEach((i) => {
|
|
790
|
+
const n = w.join(s, t, "pages", `${i}/${a.code}.json`);
|
|
791
|
+
this.ensureFileExists(n);
|
|
783
792
|
});
|
|
784
793
|
});
|
|
785
794
|
}
|
|
786
795
|
ensureFileExists(e) {
|
|
787
796
|
try {
|
|
788
|
-
const t =
|
|
789
|
-
E(t) ||
|
|
797
|
+
const t = w.dirname(e);
|
|
798
|
+
E(t) || U(t, { recursive: !0 }), E(e) || B(e, JSON.stringify({}), "utf-8");
|
|
790
799
|
} catch {
|
|
791
800
|
}
|
|
792
801
|
}
|
|
@@ -796,15 +805,15 @@ class de {
|
|
|
796
805
|
* Used by nitro:config and prerender so route rules work with custom paths (e.g. /de/ueber-uns).
|
|
797
806
|
*/
|
|
798
807
|
resolveLocalizedPath(e, t) {
|
|
799
|
-
const
|
|
800
|
-
let
|
|
801
|
-
const
|
|
802
|
-
|
|
803
|
-
const
|
|
804
|
-
let
|
|
805
|
-
if (this.strategy === "no_prefix" ?
|
|
806
|
-
return R(
|
|
807
|
-
const h =
|
|
808
|
+
const s = x(e), o = g(s) || "/";
|
|
809
|
+
let a;
|
|
810
|
+
const r = this.globalLocaleRoutes[o], i = this.globalLocaleRoutes[s];
|
|
811
|
+
r && typeof r == "object" && !Array.isArray(r) ? a = r[t] : i && typeof i == "object" && !Array.isArray(i) && (a = i[t]);
|
|
812
|
+
const n = !!a, f = a ? R(a) : R(s) || "";
|
|
813
|
+
let c = !1;
|
|
814
|
+
if (this.strategy === "no_prefix" ? c = !1 : this.strategy === "prefix" || this.strategy === "prefix_and_default" ? c = !0 : this.strategy === "prefix_except_default" && (c = t !== this.defaultLocale.code), t === this.defaultLocale.code && !n && (this.strategy === "prefix_except_default" || this.strategy === "no_prefix") && (c = !1), !c)
|
|
815
|
+
return R(f) || "/";
|
|
816
|
+
const h = g(f);
|
|
808
817
|
return h ? R(`/${t}/${h}`) : `/${t}`;
|
|
809
818
|
}
|
|
810
819
|
/**
|
|
@@ -812,34 +821,35 @@ class de {
|
|
|
812
821
|
* When disablePageLocales is true, only index routes are generated (all pages share root translations).
|
|
813
822
|
* Otherwise, generates index + per-page routes for each locale.
|
|
814
823
|
*/
|
|
815
|
-
generateDataRoutes(e, t,
|
|
816
|
-
const o = [],
|
|
817
|
-
for (const
|
|
818
|
-
if (o.push(`/${t}/index/${
|
|
819
|
-
for (const
|
|
820
|
-
o.push(`/${t}/${
|
|
824
|
+
generateDataRoutes(e, t, s) {
|
|
825
|
+
const o = [], a = this.collectPageNames(e);
|
|
826
|
+
for (const r of this.locales)
|
|
827
|
+
if (o.push(`/${t}/index/${r.code}/data.json`), !s)
|
|
828
|
+
for (const i of a)
|
|
829
|
+
o.push(`/${t}/${i}/${r.code}/data.json`);
|
|
821
830
|
return o;
|
|
822
831
|
}
|
|
823
832
|
collectPageNames(e) {
|
|
824
|
-
const t = /* @__PURE__ */ new Set(),
|
|
825
|
-
for (const
|
|
826
|
-
typeof
|
|
833
|
+
const t = /* @__PURE__ */ new Set(), s = (o) => {
|
|
834
|
+
for (const a of o)
|
|
835
|
+
typeof a.name == "string" && a.name.length > 0 && t.add(a.name), a.children && a.children.length > 0 && s(a.children);
|
|
827
836
|
};
|
|
828
|
-
return
|
|
837
|
+
return s(e), [...t];
|
|
829
838
|
}
|
|
830
839
|
}
|
|
831
840
|
export {
|
|
832
|
-
|
|
841
|
+
me as RouteGenerator,
|
|
833
842
|
A as buildFullPath,
|
|
834
843
|
Z as buildFullPathNoPrefix,
|
|
835
844
|
j as buildRouteName,
|
|
836
845
|
$ as cloneArray,
|
|
837
|
-
|
|
838
|
-
|
|
846
|
+
S as extractLocalizedPaths,
|
|
847
|
+
D as isInternalPath,
|
|
848
|
+
de as isLocaleAllowedForUnlocalizedRoute,
|
|
839
849
|
J as isLocaleDefault,
|
|
840
850
|
q as isPageRedirectOnly,
|
|
841
851
|
R as normalizePath,
|
|
842
|
-
|
|
843
|
-
|
|
852
|
+
x as normalizeRouteKey,
|
|
853
|
+
g as removeLeadingSlash,
|
|
844
854
|
H as shouldAddLocalePrefix
|
|
845
855
|
};
|