@inlang/paraglide-js 2.0.11 → 2.0.12
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/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.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.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.test.js +85 -109
- package/dist/services/env-variables/index.js +1 -1
- package/package.json +4 -4
|
@@ -10,16 +10,14 @@ test("sets the cookie to a different locale", async () => {
|
|
|
10
10
|
globalThis.window.location = { hostname: "example.com" };
|
|
11
11
|
globalThis.window.location.reload = vi.fn();
|
|
12
12
|
const runtime = await createParaglide({
|
|
13
|
-
|
|
13
|
+
blob: await newProject({
|
|
14
14
|
settings: {
|
|
15
15
|
baseLocale: "en",
|
|
16
16
|
locales: ["en", "de"],
|
|
17
17
|
},
|
|
18
18
|
}),
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
cookieName: "PARAGLIDE_LOCALE",
|
|
22
|
-
},
|
|
19
|
+
strategy: ["cookie"],
|
|
20
|
+
cookieName: "PARAGLIDE_LOCALE",
|
|
23
21
|
});
|
|
24
22
|
globalThis.document.cookie = "PARAGLIDE_LOCALE=en";
|
|
25
23
|
runtime.setLocale("de");
|
|
@@ -37,17 +35,15 @@ test("sets the cookie with explicit domain to a different locale navigating subd
|
|
|
37
35
|
globalThis.window.location = { hostname: "web.example.com" };
|
|
38
36
|
globalThis.window.location.reload = vi.fn();
|
|
39
37
|
const runtime = await createParaglide({
|
|
40
|
-
|
|
38
|
+
blob: await newProject({
|
|
41
39
|
settings: {
|
|
42
40
|
baseLocale: "en",
|
|
43
41
|
locales: ["en", "de"],
|
|
44
42
|
},
|
|
45
43
|
}),
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
cookieDomain: "example.com",
|
|
50
|
-
},
|
|
44
|
+
strategy: ["cookie"],
|
|
45
|
+
cookieName: "PARAGLIDE_LOCALE",
|
|
46
|
+
cookieDomain: "example.com",
|
|
51
47
|
});
|
|
52
48
|
globalThis.document.cookie = "PARAGLIDE_LOCALE=en";
|
|
53
49
|
runtime.setLocale("de");
|
|
@@ -65,17 +61,15 @@ test("sets the cookie with explicit domain to a different locale navigating doma
|
|
|
65
61
|
globalThis.window.location = { hostname: "example.com" };
|
|
66
62
|
globalThis.window.location.reload = vi.fn();
|
|
67
63
|
const runtime = await createParaglide({
|
|
68
|
-
|
|
64
|
+
blob: await newProject({
|
|
69
65
|
settings: {
|
|
70
66
|
baseLocale: "en",
|
|
71
67
|
locales: ["en", "de"],
|
|
72
68
|
},
|
|
73
69
|
}),
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
cookieDomain: "example.com",
|
|
78
|
-
},
|
|
70
|
+
strategy: ["cookie"],
|
|
71
|
+
cookieName: "PARAGLIDE_LOCALE",
|
|
72
|
+
cookieDomain: "example.com",
|
|
79
73
|
});
|
|
80
74
|
globalThis.document.cookie = "PARAGLIDE_LOCALE=en";
|
|
81
75
|
runtime.setLocale("de");
|
|
@@ -92,21 +86,19 @@ test("url pattern strategy sets the window location", async () => {
|
|
|
92
86
|
globalThis.window.location.hostname = "example.com";
|
|
93
87
|
globalThis.window.location.reload = vi.fn();
|
|
94
88
|
const runtime = await createParaglide({
|
|
95
|
-
|
|
89
|
+
blob: await newProject({
|
|
96
90
|
settings: { baseLocale: "en", locales: ["en", "de"] },
|
|
97
91
|
}),
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
],
|
|
109
|
-
},
|
|
92
|
+
strategy: ["url"],
|
|
93
|
+
urlPatterns: [
|
|
94
|
+
{
|
|
95
|
+
pattern: "https://example.:tld/:path*",
|
|
96
|
+
localized: [
|
|
97
|
+
["en", "https://example.com/:path*"],
|
|
98
|
+
["de", "https://example.de/:path*"],
|
|
99
|
+
],
|
|
100
|
+
},
|
|
101
|
+
],
|
|
110
102
|
});
|
|
111
103
|
globalThis.window.location.href = "https://example.com/page";
|
|
112
104
|
runtime.setLocale("de");
|
|
@@ -117,16 +109,14 @@ test("url pattern strategy sets the window location", async () => {
|
|
|
117
109
|
// `!document.cookie` was used which returned false for an empty string
|
|
118
110
|
test("sets the cookie when it's an empty string", async () => {
|
|
119
111
|
const runtime = await createParaglide({
|
|
120
|
-
|
|
112
|
+
blob: await newProject({
|
|
121
113
|
settings: {
|
|
122
114
|
baseLocale: "en",
|
|
123
115
|
locales: ["en", "fr"],
|
|
124
116
|
},
|
|
125
117
|
}),
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
cookieName: "PARAGLIDE_LOCALE",
|
|
129
|
-
},
|
|
118
|
+
strategy: ["cookie"],
|
|
119
|
+
cookieName: "PARAGLIDE_LOCALE",
|
|
130
120
|
});
|
|
131
121
|
/** @ts-expect-error - client side api */
|
|
132
122
|
globalThis.document = { cookie: "" };
|
|
@@ -135,26 +125,24 @@ test("sets the cookie when it's an empty string", async () => {
|
|
|
135
125
|
});
|
|
136
126
|
test("when strategy precedes URL, it should set the locale and re-direct to the URL", async () => {
|
|
137
127
|
const runtime = await createParaglide({
|
|
138
|
-
|
|
128
|
+
blob: await newProject({
|
|
139
129
|
settings: {
|
|
140
130
|
baseLocale: "en",
|
|
141
131
|
locales: ["en", "fr"],
|
|
142
132
|
},
|
|
143
133
|
}),
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
],
|
|
157
|
-
},
|
|
134
|
+
strategy: ["cookie", "url", "baseLocale"],
|
|
135
|
+
cookieName: "PARAGLIDE_LOCALE",
|
|
136
|
+
isServer: "false",
|
|
137
|
+
urlPatterns: [
|
|
138
|
+
{
|
|
139
|
+
pattern: "https://example.com/en/:path(.*)?",
|
|
140
|
+
localized: [
|
|
141
|
+
["en", "https://example.com/en/:path(.*)?"],
|
|
142
|
+
["fr", "https://example.com/fr/:path(.*)?"],
|
|
143
|
+
],
|
|
144
|
+
},
|
|
145
|
+
],
|
|
158
146
|
});
|
|
159
147
|
/** @ts-expect-error - client side api */
|
|
160
148
|
globalThis.document = { cookie: "PARAGLIDE_LOCALE=fr" };
|
|
@@ -177,16 +165,14 @@ test("should not reload when setting locale to current locale", async () => {
|
|
|
177
165
|
globalThis.window.location = { hostname: "example.com" };
|
|
178
166
|
globalThis.window.location.reload = vi.fn();
|
|
179
167
|
const runtime = await createParaglide({
|
|
180
|
-
|
|
168
|
+
blob: await newProject({
|
|
181
169
|
settings: {
|
|
182
170
|
baseLocale: "en",
|
|
183
171
|
locales: ["en", "de"],
|
|
184
172
|
},
|
|
185
173
|
}),
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
cookieName: "PARAGLIDE_LOCALE",
|
|
189
|
-
},
|
|
174
|
+
strategy: ["cookie"],
|
|
175
|
+
cookieName: "PARAGLIDE_LOCALE",
|
|
190
176
|
});
|
|
191
177
|
globalThis.document.cookie = "PARAGLIDE_LOCALE=en; path=/";
|
|
192
178
|
// Setting to the current locale (en)
|
|
@@ -209,15 +195,13 @@ test("sets the locale to localStorage", async () => {
|
|
|
209
195
|
// @ts-expect-error - global variable definition
|
|
210
196
|
globalThis.window = {};
|
|
211
197
|
const runtime = await createParaglide({
|
|
212
|
-
|
|
198
|
+
blob: await newProject({
|
|
213
199
|
settings: {
|
|
214
200
|
baseLocale: "en",
|
|
215
201
|
locales: ["en", "de"],
|
|
216
202
|
},
|
|
217
203
|
}),
|
|
218
|
-
|
|
219
|
-
strategy: ["localStorage"],
|
|
220
|
-
},
|
|
204
|
+
strategy: ["localStorage"],
|
|
221
205
|
});
|
|
222
206
|
runtime.setLocale("de");
|
|
223
207
|
expect(globalThis.localStorage.setItem).toHaveBeenCalledWith("PARAGLIDE_LOCALE", "de");
|
|
@@ -241,26 +225,24 @@ test("should set locale in all configured storage mechanisms regardless of which
|
|
|
241
225
|
globalThis.window.location.reload = vi.fn();
|
|
242
226
|
// Create runtime with multiple strategies
|
|
243
227
|
const runtime = await createParaglide({
|
|
244
|
-
|
|
228
|
+
blob: await newProject({
|
|
245
229
|
settings: {
|
|
246
230
|
baseLocale: "en",
|
|
247
231
|
locales: ["en", "de", "fr"],
|
|
248
232
|
},
|
|
249
233
|
}),
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
],
|
|
263
|
-
},
|
|
234
|
+
strategy: ["url", "localStorage", "cookie", "baseLocale"],
|
|
235
|
+
cookieName: "PARAGLIDE_LOCALE",
|
|
236
|
+
urlPatterns: [
|
|
237
|
+
{
|
|
238
|
+
pattern: "https://example.com/:locale/:path*",
|
|
239
|
+
localized: [
|
|
240
|
+
["en", "https://example.com/en/:path*"],
|
|
241
|
+
["de", "https://example.com/de/:path*"],
|
|
242
|
+
["fr", "https://example.com/fr/:path*"],
|
|
243
|
+
],
|
|
244
|
+
},
|
|
245
|
+
],
|
|
264
246
|
});
|
|
265
247
|
// Call setLocale
|
|
266
248
|
runtime.setLocale("fr");
|
|
@@ -4,7 +4,7 @@ import { newProject } from "@inlang/sdk";
|
|
|
4
4
|
import { test, expect } from "vitest";
|
|
5
5
|
test("tracks message calls", async () => {
|
|
6
6
|
const runtime = await createParaglide({
|
|
7
|
-
|
|
7
|
+
blob: await newProject({
|
|
8
8
|
settings: {
|
|
9
9
|
baseLocale: "en",
|
|
10
10
|
locales: ["en", "de"],
|
|
@@ -3,15 +3,13 @@ import { createParaglide } from "../create-paraglide.js";
|
|
|
3
3
|
import { newProject } from "@inlang/sdk";
|
|
4
4
|
test("sets the locale and origin", async () => {
|
|
5
5
|
const runtime = await createParaglide({
|
|
6
|
-
|
|
6
|
+
blob: await newProject({
|
|
7
7
|
settings: {
|
|
8
8
|
baseLocale: "en",
|
|
9
9
|
locales: ["en", "de", "fr"],
|
|
10
10
|
},
|
|
11
11
|
}),
|
|
12
|
-
|
|
13
|
-
strategy: ["url", "globalVariable"],
|
|
14
|
-
},
|
|
12
|
+
strategy: ["url", "globalVariable"],
|
|
15
13
|
});
|
|
16
14
|
// setting the global variable to fr to assure that
|
|
17
15
|
runtime.setLocale("fr");
|
|
@@ -37,15 +35,13 @@ test("sets the locale and origin", async () => {
|
|
|
37
35
|
});
|
|
38
36
|
test("delocalizes the url if the url strategy is used and returns the locale", async () => {
|
|
39
37
|
const runtime = await createParaglide({
|
|
40
|
-
|
|
38
|
+
blob: await newProject({
|
|
41
39
|
settings: {
|
|
42
40
|
baseLocale: "en",
|
|
43
41
|
locales: ["en", "de"],
|
|
44
42
|
},
|
|
45
43
|
}),
|
|
46
|
-
|
|
47
|
-
strategy: ["url"],
|
|
48
|
-
},
|
|
44
|
+
strategy: ["url"],
|
|
49
45
|
});
|
|
50
46
|
const request = new Request(new URL("https://example.com/de/page"), {
|
|
51
47
|
headers: { "Sec-Fetch-Dest": "document" },
|
|
@@ -59,15 +55,13 @@ test("delocalizes the url if the url strategy is used and returns the locale", a
|
|
|
59
55
|
});
|
|
60
56
|
test("does not delocalize the url if the url strategy is not used", async () => {
|
|
61
57
|
const runtime = await createParaglide({
|
|
62
|
-
|
|
58
|
+
blob: await newProject({
|
|
63
59
|
settings: {
|
|
64
60
|
baseLocale: "en",
|
|
65
61
|
locales: ["en", "de"],
|
|
66
62
|
},
|
|
67
63
|
}),
|
|
68
|
-
|
|
69
|
-
strategy: ["globalVariable", "baseLocale"],
|
|
70
|
-
},
|
|
64
|
+
strategy: ["globalVariable", "baseLocale"],
|
|
71
65
|
});
|
|
72
66
|
const request = new Request(new URL("https://example.com/de/page"), {
|
|
73
67
|
headers: { "Sec-Fetch-Dest": "document" },
|
|
@@ -81,25 +75,23 @@ test("does not delocalize the url if the url strategy is not used", async () =>
|
|
|
81
75
|
});
|
|
82
76
|
test("redirects to localized URL when non-URL strategy determines locale", async () => {
|
|
83
77
|
const runtime = await createParaglide({
|
|
84
|
-
|
|
78
|
+
blob: await newProject({
|
|
85
79
|
settings: {
|
|
86
80
|
baseLocale: "en",
|
|
87
81
|
locales: ["en", "fr"],
|
|
88
82
|
},
|
|
89
83
|
}),
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
],
|
|
102
|
-
},
|
|
84
|
+
strategy: ["cookie", "url"],
|
|
85
|
+
cookieName: "PARAGLIDE_LOCALE",
|
|
86
|
+
urlPatterns: [
|
|
87
|
+
{
|
|
88
|
+
pattern: "https://example.com/:path(.*)?",
|
|
89
|
+
localized: [
|
|
90
|
+
["en", "https://example.com/en/:path(.*)?"],
|
|
91
|
+
["fr", "https://example.com/fr/:path(.*)?"],
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
],
|
|
103
95
|
});
|
|
104
96
|
// Request to URL in en with cookie specifying French
|
|
105
97
|
const request = new Request("https://example.com/en/some-path", {
|
|
@@ -119,25 +111,23 @@ test("redirects to localized URL when non-URL strategy determines locale", async
|
|
|
119
111
|
});
|
|
120
112
|
test("does not redirect if URL already matches determined locale", async () => {
|
|
121
113
|
const runtime = await createParaglide({
|
|
122
|
-
|
|
114
|
+
blob: await newProject({
|
|
123
115
|
settings: {
|
|
124
116
|
baseLocale: "en",
|
|
125
117
|
locales: ["en", "fr"],
|
|
126
118
|
},
|
|
127
119
|
}),
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
],
|
|
140
|
-
},
|
|
120
|
+
strategy: ["cookie", "url"],
|
|
121
|
+
cookieName: "PARAGLIDE_LOCALE",
|
|
122
|
+
urlPatterns: [
|
|
123
|
+
{
|
|
124
|
+
pattern: "https://example.com/:path(.*)?",
|
|
125
|
+
localized: [
|
|
126
|
+
["en", "https://example.com/en/:path(.*)?"],
|
|
127
|
+
["fr", "https://example.com/fr/:path(.*)?"],
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
],
|
|
141
131
|
});
|
|
142
132
|
// Request to already localized URL matching cookie locale
|
|
143
133
|
const request = new Request("https://example.com/fr/some-path", {
|
|
@@ -155,16 +145,14 @@ test("does not redirect if URL already matches determined locale", async () => {
|
|
|
155
145
|
});
|
|
156
146
|
test("works with disableAsyncLocalStorage option", async () => {
|
|
157
147
|
const runtime = await createParaglide({
|
|
158
|
-
|
|
148
|
+
blob: await newProject({
|
|
159
149
|
settings: {
|
|
160
150
|
baseLocale: "en",
|
|
161
151
|
locales: ["en", "de", "fr"],
|
|
162
152
|
},
|
|
163
153
|
}),
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
disableAsyncLocalStorage: true,
|
|
167
|
-
},
|
|
154
|
+
strategy: ["url", "globalVariable"],
|
|
155
|
+
disableAsyncLocalStorage: true,
|
|
168
156
|
});
|
|
169
157
|
// Set a global locale to verify it doesn't interfere with request processing
|
|
170
158
|
runtime.setLocale("fr");
|
|
@@ -189,15 +177,13 @@ test("works with disableAsyncLocalStorage option", async () => {
|
|
|
189
177
|
});
|
|
190
178
|
test("works with sequential parallel requests using disableAsyncLocalStorage", async () => {
|
|
191
179
|
const runtime = await createParaglide({
|
|
192
|
-
|
|
180
|
+
blob: await newProject({
|
|
193
181
|
settings: {
|
|
194
182
|
baseLocale: "en",
|
|
195
183
|
locales: ["en", "de", "fr"],
|
|
196
184
|
},
|
|
197
185
|
}),
|
|
198
|
-
|
|
199
|
-
strategy: ["url", "globalVariable"],
|
|
200
|
-
},
|
|
186
|
+
strategy: ["url", "globalVariable"],
|
|
201
187
|
});
|
|
202
188
|
// setting the global variable to fr to assure that
|
|
203
189
|
runtime.setLocale("fr");
|
|
@@ -224,25 +210,23 @@ test("works with sequential parallel requests using disableAsyncLocalStorage", a
|
|
|
224
210
|
// https://github.com/opral/inlang-paraglide-js/issues/442
|
|
225
211
|
test("falls back to next strategy when cookie contains invalid locale", async () => {
|
|
226
212
|
const runtime = await createParaglide({
|
|
227
|
-
|
|
213
|
+
blob: await newProject({
|
|
228
214
|
settings: {
|
|
229
215
|
baseLocale: "en",
|
|
230
216
|
locales: ["en", "fr"],
|
|
231
217
|
},
|
|
232
218
|
}),
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
],
|
|
245
|
-
},
|
|
219
|
+
strategy: ["cookie", "url", "baseLocale"],
|
|
220
|
+
cookieName: "PARAGLIDE_LOCALE",
|
|
221
|
+
urlPatterns: [
|
|
222
|
+
{
|
|
223
|
+
pattern: "https://example.com/:path(.*)?",
|
|
224
|
+
localized: [
|
|
225
|
+
["en", "https://example.com/en/:path(.*)?"],
|
|
226
|
+
["fr", "https://example.com/fr/:path(.*)?"],
|
|
227
|
+
],
|
|
228
|
+
},
|
|
229
|
+
],
|
|
246
230
|
});
|
|
247
231
|
// Request with an invalid locale in cookie
|
|
248
232
|
const request = new Request("https://example.com/fr/some-path", {
|
|
@@ -276,25 +260,23 @@ test("falls back to next strategy when cookie contains invalid locale", async ()
|
|
|
276
260
|
test("prevents redirect loops by normalizing URLs with trailing slashes in different scenarios", async () => {
|
|
277
261
|
// Create two different runtimes to test different strategy configurations
|
|
278
262
|
const runtime = await createParaglide({
|
|
279
|
-
|
|
263
|
+
blob: await newProject({
|
|
280
264
|
settings: {
|
|
281
265
|
baseLocale: "en",
|
|
282
266
|
locales: ["en", "fr"],
|
|
283
267
|
},
|
|
284
268
|
}),
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
],
|
|
297
|
-
},
|
|
269
|
+
strategy: ["cookie", "url"],
|
|
270
|
+
cookieName: "PARAGLIDE_LOCALE",
|
|
271
|
+
urlPatterns: [
|
|
272
|
+
{
|
|
273
|
+
pattern: "https://example.com/:path(.*)?",
|
|
274
|
+
localized: [
|
|
275
|
+
["en", "https://example.com/en/:path(.*)?"],
|
|
276
|
+
["fr", "https://example.com/fr/:path(.*)?"],
|
|
277
|
+
],
|
|
278
|
+
},
|
|
279
|
+
],
|
|
298
280
|
});
|
|
299
281
|
// SCENARIO 1: Basic trailing slash normalization with cookie strategy
|
|
300
282
|
// Case 1A: Request URL has trailing slash, but localized URL might not
|
|
@@ -342,25 +324,23 @@ test("prevents redirect loops by normalizing URLs with trailing slashes in diffe
|
|
|
342
324
|
// strategy: ["cookie", "url"]
|
|
343
325
|
test.skip("doesn't redirect if disableUrlRedirect is true", async () => {
|
|
344
326
|
const runtime = await createParaglide({
|
|
345
|
-
|
|
327
|
+
blob: await newProject({
|
|
346
328
|
settings: {
|
|
347
329
|
baseLocale: "en",
|
|
348
330
|
locales: ["en", "fr"],
|
|
349
331
|
},
|
|
350
332
|
}),
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
],
|
|
363
|
-
},
|
|
333
|
+
cookieName: "PARAGLIDE_LOCALE",
|
|
334
|
+
strategy: ["cookie", "url"],
|
|
335
|
+
urlPatterns: [
|
|
336
|
+
{
|
|
337
|
+
pattern: "https://example.com/:path(.*)?",
|
|
338
|
+
localized: [
|
|
339
|
+
["en", "https://example.com/en/:path(.*)?"],
|
|
340
|
+
["fr", "https://example.com/fr/:path(.*)?"],
|
|
341
|
+
],
|
|
342
|
+
},
|
|
343
|
+
],
|
|
364
344
|
});
|
|
365
345
|
// Create a request that would normally be redirected
|
|
366
346
|
const request = new Request("https://example.com/en/some-path", {
|
|
@@ -382,25 +362,23 @@ test.skip("doesn't redirect if disableUrlRedirect is true", async () => {
|
|
|
382
362
|
});
|
|
383
363
|
test("only redirects if the request.headers.get('Sec-Fetch-Dest') === 'document'", async () => {
|
|
384
364
|
const runtime = await createParaglide({
|
|
385
|
-
|
|
365
|
+
blob: await newProject({
|
|
386
366
|
settings: {
|
|
387
367
|
baseLocale: "en",
|
|
388
368
|
locales: ["en", "fr"],
|
|
389
369
|
},
|
|
390
370
|
}),
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
],
|
|
403
|
-
},
|
|
371
|
+
strategy: ["cookie", "url"],
|
|
372
|
+
cookieName: "PARAGLIDE_LOCALE",
|
|
373
|
+
urlPatterns: [
|
|
374
|
+
{
|
|
375
|
+
pattern: "https://example.com/:path(.*)?",
|
|
376
|
+
localized: [
|
|
377
|
+
["en", "https://example.com/en/:path(.*)?"],
|
|
378
|
+
["fr", "https://example.com/fr/:path(.*)?"],
|
|
379
|
+
],
|
|
380
|
+
},
|
|
381
|
+
],
|
|
404
382
|
});
|
|
405
383
|
// Test with Sec-Fetch-Dest = document (should redirect)
|
|
406
384
|
const documentRequest = new Request("https://example.com/en/some-path", {
|
|
@@ -436,15 +414,13 @@ test("only redirects if the request.headers.get('Sec-Fetch-Dest') === 'document'
|
|
|
436
414
|
// https://github.com/opral/inlang-paraglide-js/issues/477
|
|
437
415
|
test("does not catch errors thrown by downstream resolve call", async () => {
|
|
438
416
|
const runtime = await createParaglide({
|
|
439
|
-
|
|
417
|
+
blob: await newProject({
|
|
440
418
|
settings: {
|
|
441
419
|
baseLocale: "en",
|
|
442
420
|
locales: ["en"],
|
|
443
421
|
},
|
|
444
422
|
}),
|
|
445
|
-
|
|
446
|
-
strategy: ["url"],
|
|
447
|
-
},
|
|
423
|
+
strategy: ["url"],
|
|
448
424
|
});
|
|
449
425
|
await expect(() => runtime.paraglideMiddleware(new Request(new URL("https://example.com/page"), {
|
|
450
426
|
headers: { "Sec-Fetch-Dest": "document" },
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inlang/paraglide-js",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.12",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"json5": "2.2.3",
|
|
32
32
|
"unplugin": "^2.1.2",
|
|
33
33
|
"urlpattern-polyfill": "^10.0.0",
|
|
34
|
-
"@inlang/sdk": "2.4.
|
|
34
|
+
"@inlang/sdk": "2.4.8",
|
|
35
35
|
"@inlang/recommend-sherlock": "0.2.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
"typescript": "^5.7.3",
|
|
51
51
|
"typescript-eslint": "^8.20.0",
|
|
52
52
|
"vitest": "2.1.8",
|
|
53
|
+
"@inlang/paraglide-js": "2.0.12",
|
|
53
54
|
"@inlang/plugin-message-format": "4.0.0",
|
|
54
|
-
"@opral/tsconfig": "1.1.0"
|
|
55
|
-
"@inlang/paraglide-js": "2.0.11"
|
|
55
|
+
"@opral/tsconfig": "1.1.0"
|
|
56
56
|
},
|
|
57
57
|
"keywords": [
|
|
58
58
|
"inlang",
|