@inlang/paraglide-js 2.0.11 → 2.0.13
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/cli/steps/initialize-inlang-project.d.ts.map +1 -1
- package/dist/cli/utils.d.ts.map +1 -1
- package/dist/compiler/compile-bundle.d.ts.map +1 -1
- package/dist/compiler/compile-message.d.ts.map +1 -1
- package/dist/compiler/compile-pattern.d.ts.map +1 -1
- package/dist/compiler/compile-project.d.ts.map +1 -1
- package/dist/compiler/create-paraglide.d.ts +20 -14
- package/dist/compiler/create-paraglide.d.ts.map +1 -1
- package/dist/compiler/create-paraglide.js +18 -14
- package/dist/compiler/create-paraglide.test.js +7 -11
- package/dist/compiler/index.d.ts +1 -1
- package/dist/compiler/index.d.ts.map +1 -1
- package/dist/compiler/index.js +1 -1
- package/dist/compiler/runtime/assert-is-locale.test.js +3 -3
- package/dist/compiler/runtime/extract-locale-from-cookie.test.js +7 -11
- package/dist/compiler/runtime/extract-locale-from-request.test.js +57 -77
- package/dist/compiler/runtime/extract-locale-from-url.d.ts.map +1 -1
- package/dist/compiler/runtime/extract-locale-from-url.js +35 -13
- package/dist/compiler/runtime/extract-locale-from-url.test.js +51 -61
- package/dist/compiler/runtime/generate-static-localized-urls.test.js +48 -58
- package/dist/compiler/runtime/get-locale.test.js +52 -68
- package/dist/compiler/runtime/get-url-origin.test.js +2 -4
- package/dist/compiler/runtime/localize-href.d.ts.map +1 -1
- package/dist/compiler/runtime/localize-href.js +7 -4
- package/dist/compiler/runtime/localize-href.test.js +48 -58
- package/dist/compiler/runtime/localize-url.test.js +258 -294
- package/dist/compiler/runtime/set-locale.test.js +56 -74
- package/dist/compiler/runtime/track-message-call.test.js +1 -1
- package/dist/compiler/server/middleware.d.ts +4 -2
- package/dist/compiler/server/middleware.d.ts.map +1 -1
- package/dist/compiler/server/middleware.js +5 -3
- package/dist/compiler/server/middleware.test.js +163 -109
- package/dist/services/codegen/quotes.d.ts.map +1 -1
- package/dist/services/env-variables/index.js +1 -1
- package/dist/services/telemetry/capture.d.ts.map +1 -1
- package/dist/utilities/detect-json-formatting.d.ts.map +1 -1
- package/package.json +7 -7
|
@@ -3,41 +3,39 @@ import { createParaglide } from "../create-paraglide.js";
|
|
|
3
3
|
import { newProject } from "@inlang/sdk";
|
|
4
4
|
test("pathname based localization", async () => {
|
|
5
5
|
const runtime = await createParaglide({
|
|
6
|
-
|
|
6
|
+
blob: await newProject({
|
|
7
7
|
settings: {
|
|
8
8
|
baseLocale: "en",
|
|
9
9
|
locales: ["en", "de"],
|
|
10
10
|
},
|
|
11
11
|
}),
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
],
|
|
40
|
-
},
|
|
12
|
+
strategy: ["url"],
|
|
13
|
+
urlPatterns: [
|
|
14
|
+
// literal match
|
|
15
|
+
{
|
|
16
|
+
pattern: "/blog/about",
|
|
17
|
+
localized: [
|
|
18
|
+
["en", "/blog/about"],
|
|
19
|
+
["de", "/de/artikel/ueber-uns"],
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
// parameter
|
|
23
|
+
{
|
|
24
|
+
pattern: "/blog/:id",
|
|
25
|
+
localized: [
|
|
26
|
+
["en", "/blog/:id"],
|
|
27
|
+
["de", "/de/artikel/:id"],
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
// wildcard
|
|
31
|
+
{
|
|
32
|
+
pattern: "/:path(.*)",
|
|
33
|
+
localized: [
|
|
34
|
+
["de", "/de/:path(.*)"],
|
|
35
|
+
["en", "/:path(.*)"],
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
],
|
|
41
39
|
});
|
|
42
40
|
// wildcard - en to de
|
|
43
41
|
expect(runtime.localizeUrl("https://example.com/home", { locale: "de" }).href).toBe("https://example.com/de/home");
|
|
@@ -56,33 +54,31 @@ test("pathname based localization", async () => {
|
|
|
56
54
|
});
|
|
57
55
|
test("cross domain urls", async () => {
|
|
58
56
|
const runtime = await createParaglide({
|
|
59
|
-
|
|
57
|
+
blob: await newProject({
|
|
60
58
|
settings: {
|
|
61
59
|
baseLocale: "en",
|
|
62
60
|
locales: ["en", "de"],
|
|
63
61
|
},
|
|
64
62
|
}),
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
],
|
|
85
|
-
},
|
|
63
|
+
strategy: ["url"],
|
|
64
|
+
urlPatterns: [
|
|
65
|
+
// Development/deployment mapping
|
|
66
|
+
{
|
|
67
|
+
pattern: "https://localhost::port/:path*",
|
|
68
|
+
localized: [
|
|
69
|
+
["de", "https://localhost::port/de/:path*"],
|
|
70
|
+
["en", "https://localhost::port/:path*"],
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
// Domain based localization
|
|
74
|
+
{
|
|
75
|
+
pattern: "https://example.com/:path*",
|
|
76
|
+
localized: [
|
|
77
|
+
["en", "https://example.com/:path*"],
|
|
78
|
+
["de", "https://de.example.com/:path*"],
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
],
|
|
86
82
|
});
|
|
87
83
|
// in development use localhost with different mapping
|
|
88
84
|
expect(runtime.localizeUrl("https://localhost:5173/about", { locale: "de" }).href).toBe("https://localhost:5173/de/about");
|
|
@@ -101,41 +97,39 @@ test("cross domain urls", async () => {
|
|
|
101
97
|
});
|
|
102
98
|
test("multi tenancy", async () => {
|
|
103
99
|
const runtime = await createParaglide({
|
|
104
|
-
|
|
100
|
+
blob: await newProject({
|
|
105
101
|
settings: {
|
|
106
102
|
baseLocale: "en",
|
|
107
103
|
locales: ["en", "de", "fr"],
|
|
108
104
|
},
|
|
109
105
|
}),
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
],
|
|
138
|
-
},
|
|
106
|
+
strategy: ["url"],
|
|
107
|
+
urlPatterns: [
|
|
108
|
+
// 1) customer1.fr => root path locale is fr, other locales via sub-path e.g. /en/
|
|
109
|
+
{
|
|
110
|
+
pattern: "https://customer1.fr/:path*",
|
|
111
|
+
localized: [
|
|
112
|
+
["en", "https://customer1.fr/en/:path*"],
|
|
113
|
+
["fr", "https://customer1.fr/:path*"],
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
// 2) customer2.com => root path locale is en, other locales via sub-path e.g. /fr/
|
|
117
|
+
{
|
|
118
|
+
pattern: "https://customer2.com/:path*",
|
|
119
|
+
localized: [
|
|
120
|
+
["fr", "https://customer2.com/fr/:path*"],
|
|
121
|
+
["en", "https://customer2.com/:path*"],
|
|
122
|
+
],
|
|
123
|
+
},
|
|
124
|
+
// 3) Any other domain => path-based for en/fr
|
|
125
|
+
{
|
|
126
|
+
pattern: "https://:domain(.*)/:path*",
|
|
127
|
+
localized: [
|
|
128
|
+
["en", "https://:domain(.*)/en/:path*"],
|
|
129
|
+
["fr", "https://:domain(.*)/fr/:path*"],
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
],
|
|
139
133
|
});
|
|
140
134
|
// customer 1 - localizing french to french
|
|
141
135
|
expect(runtime.localizeUrl("https://customer1.fr/about", { locale: "fr" }).href).toBe("https://customer1.fr/about");
|
|
@@ -152,24 +146,22 @@ test("multi tenancy", async () => {
|
|
|
152
146
|
});
|
|
153
147
|
test("providing a URL object as input", async () => {
|
|
154
148
|
const runtime = await createParaglide({
|
|
155
|
-
|
|
149
|
+
blob: await newProject({
|
|
156
150
|
settings: {
|
|
157
151
|
baseLocale: "en",
|
|
158
152
|
locales: ["en", "de"],
|
|
159
153
|
},
|
|
160
154
|
}),
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
],
|
|
172
|
-
},
|
|
155
|
+
strategy: ["url"],
|
|
156
|
+
urlPatterns: [
|
|
157
|
+
{
|
|
158
|
+
pattern: "https://:domain(.*)/:path*",
|
|
159
|
+
localized: [
|
|
160
|
+
["en", "https://:domain(.*)/:path*"],
|
|
161
|
+
["de", "https://de.:domain(.*)/:path*"],
|
|
162
|
+
],
|
|
163
|
+
},
|
|
164
|
+
],
|
|
173
165
|
});
|
|
174
166
|
const url = new URL("https://example.com/about");
|
|
175
167
|
expect(runtime.localizeUrl(url, { locale: "de" }).href).toBe("https://de.example.com/about");
|
|
@@ -177,24 +169,22 @@ test("providing a URL object as input", async () => {
|
|
|
177
169
|
});
|
|
178
170
|
test("localhost with portname", async () => {
|
|
179
171
|
const runtime = await createParaglide({
|
|
180
|
-
|
|
172
|
+
blob: await newProject({
|
|
181
173
|
settings: {
|
|
182
174
|
baseLocale: "en",
|
|
183
175
|
locales: ["en", "de"],
|
|
184
176
|
},
|
|
185
177
|
}),
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
],
|
|
197
|
-
},
|
|
178
|
+
strategy: ["url"],
|
|
179
|
+
urlPatterns: [
|
|
180
|
+
{
|
|
181
|
+
pattern: ":protocol://:domain(.*)::port?/:path(.*)?",
|
|
182
|
+
localized: [
|
|
183
|
+
["de", ":protocol://:domain(.*)::port?/de/:path(.*)?"],
|
|
184
|
+
["en", ":protocol://:domain(.*)::port?/:path(.*)?"],
|
|
185
|
+
],
|
|
186
|
+
},
|
|
187
|
+
],
|
|
198
188
|
});
|
|
199
189
|
// http
|
|
200
190
|
expect(runtime.deLocalizeUrl(new URL("http://localhost:5173/de/about")).href).toBe("http://localhost:5173/about");
|
|
@@ -209,24 +199,22 @@ test("localhost with portname", async () => {
|
|
|
209
199
|
});
|
|
210
200
|
test("it keeps the query parameters", async () => {
|
|
211
201
|
const runtime = await createParaglide({
|
|
212
|
-
|
|
202
|
+
blob: await newProject({
|
|
213
203
|
settings: {
|
|
214
204
|
baseLocale: "en",
|
|
215
205
|
locales: ["en", "de"],
|
|
216
206
|
},
|
|
217
207
|
}),
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
],
|
|
229
|
-
},
|
|
208
|
+
strategy: ["url"],
|
|
209
|
+
urlPatterns: [
|
|
210
|
+
{
|
|
211
|
+
pattern: "https://:domain(.*)/:path(.*)?",
|
|
212
|
+
localized: [
|
|
213
|
+
["de", "https://:domain(.*)/de/:path(.*)?"],
|
|
214
|
+
["en", "https://:domain(.*)/:path(.*)?"],
|
|
215
|
+
],
|
|
216
|
+
},
|
|
217
|
+
],
|
|
230
218
|
});
|
|
231
219
|
expect(runtime.localizeUrl("https://example.com/about?foo=bar&baz=qux", {
|
|
232
220
|
locale: "de",
|
|
@@ -235,24 +223,22 @@ test("it keeps the query parameters", async () => {
|
|
|
235
223
|
});
|
|
236
224
|
test("it keeps the url hash", async () => {
|
|
237
225
|
const runtime = await createParaglide({
|
|
238
|
-
|
|
226
|
+
blob: await newProject({
|
|
239
227
|
settings: {
|
|
240
228
|
baseLocale: "en",
|
|
241
229
|
locales: ["en", "de"],
|
|
242
230
|
},
|
|
243
231
|
}),
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
],
|
|
255
|
-
},
|
|
232
|
+
strategy: ["url"],
|
|
233
|
+
urlPatterns: [
|
|
234
|
+
{
|
|
235
|
+
pattern: "https://:domain(.*)/:path(.*)?",
|
|
236
|
+
localized: [
|
|
237
|
+
["de", "https://:domain(.*)/de/:path(.*)?"],
|
|
238
|
+
["en", "https://:domain(.*)/:path(.*)?"],
|
|
239
|
+
],
|
|
240
|
+
},
|
|
241
|
+
],
|
|
256
242
|
});
|
|
257
243
|
expect(runtime.localizeUrl("https://example.com/about#test", { locale: "de" }).href).toBe("https://example.com/de/about#test");
|
|
258
244
|
expect(runtime.deLocalizeUrl("https://example.com/de/about#test").href).toBe("https://example.com/about#test");
|
|
@@ -264,48 +250,44 @@ test("it keeps the url hash", async () => {
|
|
|
264
250
|
// This means any request, including https://example.com/about, will match.
|
|
265
251
|
test("it keeps the url path", async () => {
|
|
266
252
|
const runtime = await createParaglide({
|
|
267
|
-
|
|
253
|
+
blob: await newProject({
|
|
268
254
|
settings: {
|
|
269
255
|
baseLocale: "en",
|
|
270
256
|
locales: ["en", "de"],
|
|
271
257
|
},
|
|
272
258
|
}),
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
],
|
|
284
|
-
},
|
|
259
|
+
strategy: ["url"],
|
|
260
|
+
urlPatterns: [
|
|
261
|
+
{
|
|
262
|
+
pattern: "https://example.com",
|
|
263
|
+
localized: [
|
|
264
|
+
["de", "https://example.de"],
|
|
265
|
+
["en", "https://example.com"],
|
|
266
|
+
],
|
|
267
|
+
},
|
|
268
|
+
],
|
|
285
269
|
});
|
|
286
270
|
expect(runtime.localizeUrl("https://example.com/about", { locale: "de" }).href).toBe("https://example.de/about");
|
|
287
271
|
expect(runtime.deLocalizeUrl("https://example.de/about").href).toBe("https://example.com/about");
|
|
288
272
|
});
|
|
289
273
|
test("uses getLocale when no locale is provided", async () => {
|
|
290
274
|
const runtime = await createParaglide({
|
|
291
|
-
|
|
275
|
+
blob: await newProject({
|
|
292
276
|
settings: {
|
|
293
277
|
baseLocale: "en",
|
|
294
278
|
locales: ["en", "de"],
|
|
295
279
|
},
|
|
296
280
|
}),
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
],
|
|
308
|
-
},
|
|
281
|
+
strategy: ["url"],
|
|
282
|
+
urlPatterns: [
|
|
283
|
+
{
|
|
284
|
+
pattern: "https://:domain(.*)/:path(.*)?",
|
|
285
|
+
localized: [
|
|
286
|
+
["de", "https://:domain(.*)/de/:path(.*)?"],
|
|
287
|
+
["en", "https://:domain(.*)/en/:path(.*)?"],
|
|
288
|
+
],
|
|
289
|
+
},
|
|
290
|
+
],
|
|
309
291
|
});
|
|
310
292
|
// Override getLocale to return German
|
|
311
293
|
runtime.overwriteGetLocale(() => "de");
|
|
@@ -333,13 +315,13 @@ test.each([
|
|
|
333
315
|
},
|
|
334
316
|
])("default url pattern", async (compilerOptions) => {
|
|
335
317
|
const runtime = await createParaglide({
|
|
336
|
-
|
|
318
|
+
blob: await newProject({
|
|
337
319
|
settings: {
|
|
338
320
|
baseLocale: "en",
|
|
339
321
|
locales: ["en", "de"],
|
|
340
322
|
},
|
|
341
323
|
}),
|
|
342
|
-
compilerOptions,
|
|
324
|
+
...compilerOptions,
|
|
343
325
|
});
|
|
344
326
|
runtime.overwriteGetLocale(() => "en");
|
|
345
327
|
expect(runtime.localizeUrl("https://example.com/about").href).toBe("https://example.com/about");
|
|
@@ -354,24 +336,22 @@ test.each([
|
|
|
354
336
|
});
|
|
355
337
|
test("auto fills the url base path", async () => {
|
|
356
338
|
const runtime = await createParaglide({
|
|
357
|
-
|
|
339
|
+
blob: await newProject({
|
|
358
340
|
settings: {
|
|
359
341
|
baseLocale: "en",
|
|
360
342
|
locales: ["en", "de"],
|
|
361
343
|
},
|
|
362
344
|
}),
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
],
|
|
374
|
-
},
|
|
345
|
+
strategy: ["url"],
|
|
346
|
+
urlPatterns: [
|
|
347
|
+
{
|
|
348
|
+
pattern: "/:path(.*)?",
|
|
349
|
+
localized: [
|
|
350
|
+
["de", "/de/:path(.*)?"],
|
|
351
|
+
["en", "/:path(.*)?"],
|
|
352
|
+
],
|
|
353
|
+
},
|
|
354
|
+
],
|
|
375
355
|
});
|
|
376
356
|
expect(runtime.localizeUrl("https://example.com/about", { locale: "en" }).href).toBe("https://example.com/about");
|
|
377
357
|
expect(runtime.localizeUrl("https://example.com/about", { locale: "de" }).href).toBe("https://example.com/de/about");
|
|
@@ -380,24 +360,22 @@ test("auto fills the url base path", async () => {
|
|
|
380
360
|
// https://github.com/opral/inlang-paraglide-js/issues/454
|
|
381
361
|
test("works with no trailing slash at the end", async () => {
|
|
382
362
|
const runtime = await createParaglide({
|
|
383
|
-
|
|
363
|
+
blob: await newProject({
|
|
384
364
|
settings: {
|
|
385
365
|
baseLocale: "en",
|
|
386
366
|
locales: ["en", "de"],
|
|
387
367
|
},
|
|
388
368
|
}),
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
],
|
|
400
|
-
},
|
|
369
|
+
strategy: ["url"],
|
|
370
|
+
urlPatterns: [
|
|
371
|
+
{
|
|
372
|
+
pattern: "/:path(.*)?",
|
|
373
|
+
localized: [
|
|
374
|
+
["en", "/en/:path(.*)?"],
|
|
375
|
+
["de", "/de/:path(.*)?"],
|
|
376
|
+
],
|
|
377
|
+
},
|
|
378
|
+
],
|
|
401
379
|
});
|
|
402
380
|
expect(runtime.deLocalizeUrl("https://example.com/en/").href).toBe("https://example.com/");
|
|
403
381
|
expect(runtime.deLocalizeUrl("https://example.com/en").href).toBe("https://example.com/");
|
|
@@ -405,45 +383,41 @@ test("works with no trailing slash at the end", async () => {
|
|
|
405
383
|
// https://github.com/opral/inlang-paraglide-js/issues/452#issuecomment-2715761308
|
|
406
384
|
test("falls through if no match is found", async () => {
|
|
407
385
|
const runtime = await createParaglide({
|
|
408
|
-
|
|
386
|
+
blob: await newProject({
|
|
409
387
|
settings: {
|
|
410
388
|
baseLocale: "en",
|
|
411
389
|
locales: ["en", "de"],
|
|
412
390
|
},
|
|
413
391
|
}),
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
],
|
|
425
|
-
},
|
|
392
|
+
strategy: ["url"],
|
|
393
|
+
urlPatterns: [
|
|
394
|
+
{
|
|
395
|
+
pattern: "/about",
|
|
396
|
+
localized: [
|
|
397
|
+
["de", "/ueber"],
|
|
398
|
+
["en", "/about"],
|
|
399
|
+
],
|
|
400
|
+
},
|
|
401
|
+
],
|
|
426
402
|
});
|
|
427
403
|
expect(runtime.localizeUrl("https://example.com/", { locale: "en" }).href).toBe("https://example.com/");
|
|
428
404
|
expect(runtime.deLocalizeUrl("https://example.com/").href).toBe("https://example.com/");
|
|
429
405
|
});
|
|
430
406
|
test("defining no localized pattern leads to a fallthrough", async () => {
|
|
431
407
|
const runtime = await createParaglide({
|
|
432
|
-
|
|
408
|
+
blob: await newProject({
|
|
433
409
|
settings: {
|
|
434
410
|
baseLocale: "en",
|
|
435
411
|
locales: ["en", "de"],
|
|
436
412
|
},
|
|
437
413
|
}),
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
],
|
|
446
|
-
},
|
|
414
|
+
strategy: ["url"],
|
|
415
|
+
urlPatterns: [
|
|
416
|
+
{
|
|
417
|
+
pattern: "/specific-path",
|
|
418
|
+
localized: [["en", "/specific-path"]],
|
|
419
|
+
},
|
|
420
|
+
],
|
|
447
421
|
});
|
|
448
422
|
// doesn't localize because no localized pattern is defined
|
|
449
423
|
expect(runtime.localizeUrl("https://example.com/specific-path", { locale: "de" })
|
|
@@ -454,38 +428,36 @@ test("defining no localized pattern leads to a fallthrough", async () => {
|
|
|
454
428
|
// https://github.com/opral/inlang-paraglide-js/issues/456
|
|
455
429
|
test("routing to a 404 page", async () => {
|
|
456
430
|
const runtime = await createParaglide({
|
|
457
|
-
|
|
431
|
+
blob: await newProject({
|
|
458
432
|
settings: {
|
|
459
433
|
baseLocale: "en",
|
|
460
434
|
locales: ["en", "de"],
|
|
461
435
|
},
|
|
462
436
|
}),
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
],
|
|
488
|
-
},
|
|
437
|
+
strategy: ["url"],
|
|
438
|
+
urlPatterns: [
|
|
439
|
+
{
|
|
440
|
+
pattern: "/404",
|
|
441
|
+
localized: [
|
|
442
|
+
["en", "/404"],
|
|
443
|
+
["de", "/de/404"],
|
|
444
|
+
],
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
pattern: "specific-path",
|
|
448
|
+
localized: [
|
|
449
|
+
["en", "/specific-path"],
|
|
450
|
+
["de", "/de/404"],
|
|
451
|
+
],
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
pattern: "/:path(.*)?",
|
|
455
|
+
localized: [
|
|
456
|
+
["en", "/:path(.*)?"],
|
|
457
|
+
["de", "/de/:path(.*)?"],
|
|
458
|
+
],
|
|
459
|
+
},
|
|
460
|
+
],
|
|
489
461
|
});
|
|
490
462
|
expect(runtime.localizeUrl("https://example.com/specific-path", { locale: "en" })
|
|
491
463
|
.href).toBe("https://example.com/specific-path");
|
|
@@ -498,25 +470,23 @@ test("routing to a 404 page", async () => {
|
|
|
498
470
|
// Test showing the importance of pattern order in the localized array
|
|
499
471
|
test("pattern order in localized array - correct order (specific first)", async () => {
|
|
500
472
|
const runtime = await createParaglide({
|
|
501
|
-
|
|
473
|
+
blob: await newProject({
|
|
502
474
|
settings: {
|
|
503
475
|
baseLocale: "en",
|
|
504
476
|
locales: ["en", "de"],
|
|
505
477
|
},
|
|
506
478
|
}),
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
],
|
|
519
|
-
},
|
|
479
|
+
strategy: ["url"],
|
|
480
|
+
urlPatterns: [
|
|
481
|
+
{
|
|
482
|
+
pattern: "/:path(.*)?",
|
|
483
|
+
localized: [
|
|
484
|
+
// CORRECT ORDER: more specific pattern first
|
|
485
|
+
["de", "/de/:path(.*)?"], // More specific pattern with prefix
|
|
486
|
+
["en", "/:path(.*)?"], // Less specific pattern without prefix
|
|
487
|
+
],
|
|
488
|
+
},
|
|
489
|
+
],
|
|
520
490
|
});
|
|
521
491
|
// These should work correctly with the specific (de) pattern first
|
|
522
492
|
expect(runtime.localizeUrl("https://example.com/about", { locale: "en" }).href).toBe("https://example.com/about");
|
|
@@ -527,25 +497,23 @@ test("pattern order in localized array - correct order (specific first)", async
|
|
|
527
497
|
// Test showing the importance of pattern order in the localized array
|
|
528
498
|
test("pattern order in localized array - incorrect order (generic first)", async () => {
|
|
529
499
|
const runtime = await createParaglide({
|
|
530
|
-
|
|
500
|
+
blob: await newProject({
|
|
531
501
|
settings: {
|
|
532
502
|
baseLocale: "en",
|
|
533
503
|
locales: ["en", "de"],
|
|
534
504
|
},
|
|
535
505
|
}),
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
],
|
|
548
|
-
},
|
|
506
|
+
strategy: ["url"],
|
|
507
|
+
urlPatterns: [
|
|
508
|
+
{
|
|
509
|
+
pattern: "/:path(.*)?",
|
|
510
|
+
localized: [
|
|
511
|
+
// INCORRECT ORDER: less specific pattern first
|
|
512
|
+
["en", "/:path(.*)?"], // Less specific pattern without prefix
|
|
513
|
+
["de", "/de/:path(.*)?"], // More specific pattern with prefix that may never match
|
|
514
|
+
],
|
|
515
|
+
},
|
|
516
|
+
],
|
|
549
517
|
});
|
|
550
518
|
// English localization works as expected
|
|
551
519
|
expect(runtime.localizeUrl("https://example.com/about", { locale: "en" }).href).toBe("https://example.com/about");
|
|
@@ -559,25 +527,23 @@ test("pattern order in localized array - incorrect order (generic first)", async
|
|
|
559
527
|
// Test for port number issue with specific port numbers in the URL pattern
|
|
560
528
|
test("handles explicit port numbers in URL patterns correctly", async () => {
|
|
561
529
|
const runtime = await createParaglide({
|
|
562
|
-
|
|
530
|
+
blob: await newProject({
|
|
563
531
|
settings: {
|
|
564
532
|
baseLocale: "en",
|
|
565
533
|
locales: ["en", "de"],
|
|
566
534
|
},
|
|
567
535
|
}),
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
],
|
|
580
|
-
},
|
|
536
|
+
strategy: ["url"],
|
|
537
|
+
urlPatterns: [
|
|
538
|
+
{
|
|
539
|
+
// Using explicit port number - this causes issues with deLocalizeUrl
|
|
540
|
+
pattern: "http://localhost:5173/:path(.*)?",
|
|
541
|
+
localized: [
|
|
542
|
+
["de", "http://localhost:5173/de/:path(.*)?"],
|
|
543
|
+
["en", "http://localhost:5173/:path(.*)?"],
|
|
544
|
+
],
|
|
545
|
+
},
|
|
546
|
+
],
|
|
581
547
|
});
|
|
582
548
|
// Localization should work correctly
|
|
583
549
|
expect(runtime.localizeUrl("http://localhost:5173/about", { locale: "de" }).href).toBe("http://localhost:5173/de/about");
|
|
@@ -589,25 +555,23 @@ test("handles explicit port numbers in URL patterns correctly", async () => {
|
|
|
589
555
|
// Test for the correct approach using port as a pattern parameter
|
|
590
556
|
test("correctly handles port numbers as pattern parameters", async () => {
|
|
591
557
|
const runtime = await createParaglide({
|
|
592
|
-
|
|
558
|
+
blob: await newProject({
|
|
593
559
|
settings: {
|
|
594
560
|
baseLocale: "en",
|
|
595
561
|
locales: ["en", "de"],
|
|
596
562
|
},
|
|
597
563
|
}),
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
],
|
|
610
|
-
},
|
|
564
|
+
strategy: ["url"],
|
|
565
|
+
urlPatterns: [
|
|
566
|
+
{
|
|
567
|
+
// Using port as a proper pattern parameter with :: syntax
|
|
568
|
+
pattern: "http://localhost::port/:path(.*)?",
|
|
569
|
+
localized: [
|
|
570
|
+
["de", "http://localhost::port/de/:path(.*)?"],
|
|
571
|
+
["en", "http://localhost::port/:path(.*)?"],
|
|
572
|
+
],
|
|
573
|
+
},
|
|
574
|
+
],
|
|
611
575
|
});
|
|
612
576
|
// Localization should work correctly
|
|
613
577
|
expect(runtime.localizeUrl("http://localhost:5173/about", { locale: "de" }).href).toBe("http://localhost:5173/de/about");
|