@inlang/paraglide-js 2.0.13 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compiler/compile-bundle.d.ts +2 -1
- package/dist/compiler/compile-bundle.d.ts.map +1 -1
- package/dist/compiler/compile-bundle.js +4 -3
- package/dist/compiler/compile-bundle.test.js +64 -0
- package/dist/compiler/compile-project.d.ts.map +1 -1
- package/dist/compiler/compile-project.js +1 -0
- package/dist/compiler/compiler-options.d.ts +2 -0
- package/dist/compiler/compiler-options.d.ts.map +1 -1
- package/dist/compiler/runtime/create-runtime.d.ts.map +1 -1
- package/dist/compiler/runtime/create-runtime.js +6 -0
- package/dist/compiler/runtime/extract-locale-from-cookie.d.ts +1 -1
- package/dist/compiler/runtime/extract-locale-from-cookie.js +1 -1
- package/dist/compiler/runtime/extract-locale-from-header.d.ts +2 -0
- package/dist/compiler/runtime/extract-locale-from-header.d.ts.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-header.js +43 -0
- package/dist/compiler/runtime/extract-locale-from-header.test.d.ts +2 -0
- package/dist/compiler/runtime/extract-locale-from-header.test.d.ts.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-header.test.js +51 -0
- package/dist/compiler/runtime/extract-locale-from-navigator.d.ts +2 -0
- package/dist/compiler/runtime/extract-locale-from-navigator.d.ts.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-navigator.js +31 -0
- package/dist/compiler/runtime/extract-locale-from-navigator.test.d.ts +2 -0
- package/dist/compiler/runtime/extract-locale-from-navigator.test.d.ts.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-navigator.test.js +29 -0
- package/dist/compiler/runtime/extract-locale-from-request.d.ts.map +1 -1
- package/dist/compiler/runtime/extract-locale-from-request.js +8 -36
- package/dist/compiler/runtime/extract-locale-from-request.test.js +83 -2
- package/dist/compiler/runtime/get-locale.d.ts.map +1 -1
- package/dist/compiler/runtime/get-locale.js +8 -26
- package/dist/compiler/runtime/get-locale.test.js +153 -0
- package/dist/compiler/runtime/set-locale.d.ts.map +1 -1
- package/dist/compiler/runtime/set-locale.js +6 -1
- package/dist/compiler/runtime/set-locale.test.js +140 -0
- package/dist/compiler/runtime/strategy.d.ts +60 -0
- package/dist/compiler/runtime/strategy.d.ts.map +1 -0
- package/dist/compiler/runtime/strategy.js +62 -0
- package/dist/compiler/runtime/strategy.test.d.ts +2 -0
- package/dist/compiler/runtime/strategy.test.d.ts.map +1 -0
- package/dist/compiler/runtime/strategy.test.js +94 -0
- package/dist/compiler/runtime/type.d.ts +4 -0
- package/dist/compiler/runtime/type.d.ts.map +1 -1
- package/dist/compiler/runtime/variables.d.ts +2 -2
- package/dist/compiler/runtime/variables.d.ts.map +1 -1
- package/dist/compiler/runtime/variables.js +1 -1
- package/dist/compiler/server/middleware.d.ts.map +1 -1
- package/dist/compiler/server/middleware.js +13 -1
- package/dist/compiler/server/middleware.test.js +73 -0
- package/dist/services/env-variables/index.js +1 -1
- package/package.json +3 -3
|
@@ -150,6 +150,79 @@ test("call onRedirect callback when redirecting to new url", async () => {
|
|
|
150
150
|
expect(response.status).toBe(307); // Redirect status code
|
|
151
151
|
expect(response.headers.get("Location")).toBe("https://example.com/fr/some-path");
|
|
152
152
|
});
|
|
153
|
+
test("sets Vary: Accept-Language header when preferredLanguage strategy is used and redirect occurs", async () => {
|
|
154
|
+
const runtime = await createParaglide({
|
|
155
|
+
blob: await newProject({
|
|
156
|
+
settings: {
|
|
157
|
+
baseLocale: "en",
|
|
158
|
+
locales: ["en", "fr"],
|
|
159
|
+
},
|
|
160
|
+
}),
|
|
161
|
+
strategy: ["preferredLanguage", "url"],
|
|
162
|
+
urlPatterns: [
|
|
163
|
+
{
|
|
164
|
+
pattern: "https://example.com/:path(.*)?",
|
|
165
|
+
localized: [
|
|
166
|
+
["en", "https://example.com/en/:path(.*)?"],
|
|
167
|
+
["fr", "https://example.com/fr/:path(.*)?"],
|
|
168
|
+
],
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
});
|
|
172
|
+
// Request with Accept-Language header preferring French
|
|
173
|
+
const request = new Request("https://example.com/en/some-path", {
|
|
174
|
+
headers: {
|
|
175
|
+
"Accept-Language": "fr,en;q=0.8",
|
|
176
|
+
"Sec-Fetch-Dest": "document",
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
const response = await runtime.paraglideMiddleware(request, () => {
|
|
180
|
+
// This shouldn't be called since we should redirect
|
|
181
|
+
throw new Error("Should not reach here");
|
|
182
|
+
});
|
|
183
|
+
expect(response instanceof Response).toBe(true);
|
|
184
|
+
expect(response.status).toBe(307); // Redirect status code
|
|
185
|
+
expect(response.headers.get("Location")).toBe("https://example.com/fr/some-path");
|
|
186
|
+
// Should have Vary header when preferredLanguage strategy is used
|
|
187
|
+
expect(response.headers.get("Vary")).toBe("Accept-Language");
|
|
188
|
+
});
|
|
189
|
+
test("does not set Vary header when preferredLanguage strategy is not used", async () => {
|
|
190
|
+
const runtime = await createParaglide({
|
|
191
|
+
blob: await newProject({
|
|
192
|
+
settings: {
|
|
193
|
+
baseLocale: "en",
|
|
194
|
+
locales: ["en", "fr"],
|
|
195
|
+
},
|
|
196
|
+
}),
|
|
197
|
+
strategy: ["cookie", "url"],
|
|
198
|
+
cookieName: "PARAGLIDE_LOCALE",
|
|
199
|
+
urlPatterns: [
|
|
200
|
+
{
|
|
201
|
+
pattern: "https://example.com/:path(.*)?",
|
|
202
|
+
localized: [
|
|
203
|
+
["en", "https://example.com/en/:path(.*)?"],
|
|
204
|
+
["fr", "https://example.com/fr/:path(.*)?"],
|
|
205
|
+
],
|
|
206
|
+
},
|
|
207
|
+
],
|
|
208
|
+
});
|
|
209
|
+
// Request with cookie specifying French
|
|
210
|
+
const request = new Request("https://example.com/en/some-path", {
|
|
211
|
+
headers: {
|
|
212
|
+
cookie: `PARAGLIDE_LOCALE=fr`,
|
|
213
|
+
"Sec-Fetch-Dest": "document",
|
|
214
|
+
},
|
|
215
|
+
});
|
|
216
|
+
const response = await runtime.paraglideMiddleware(request, () => {
|
|
217
|
+
// This shouldn't be called since we should redirect
|
|
218
|
+
throw new Error("Should not reach here");
|
|
219
|
+
});
|
|
220
|
+
expect(response instanceof Response).toBe(true);
|
|
221
|
+
expect(response.status).toBe(307); // Redirect status code
|
|
222
|
+
expect(response.headers.get("Location")).toBe("https://example.com/fr/some-path");
|
|
223
|
+
// Should NOT have Vary header when preferredLanguage strategy is not used
|
|
224
|
+
expect(response.headers.get("Vary")).toBe(null);
|
|
225
|
+
});
|
|
153
226
|
test("does not call onRedirect callback when there is no redirecting", async () => {
|
|
154
227
|
const runtime = await createParaglide({
|
|
155
228
|
blob: await newProject({
|
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.1.0",
|
|
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.9",
|
|
35
35
|
"@inlang/recommend-sherlock": "0.2.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"typescript": "^5.7.3",
|
|
51
51
|
"typescript-eslint": "^8.20.0",
|
|
52
52
|
"vitest": "2.1.8",
|
|
53
|
+
"@inlang/paraglide-js": "2.1.0",
|
|
53
54
|
"@inlang/plugin-message-format": "4.0.0",
|
|
54
|
-
"@inlang/paraglide-js": "2.0.13",
|
|
55
55
|
"@opral/tsconfig": "1.1.0"
|
|
56
56
|
},
|
|
57
57
|
"keywords": [
|