@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
|
@@ -3,24 +3,22 @@ import { createParaglide } from "../create-paraglide.js";
|
|
|
3
3
|
import { newProject } from "@inlang/sdk";
|
|
4
4
|
test("uses the locale from getLocale() if no locale is provided", 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
|
-
},
|
|
12
|
+
strategy: ["url", "globalVariable", "baseLocale"],
|
|
13
|
+
urlPatterns: [
|
|
14
|
+
{
|
|
15
|
+
pattern: "http://:domain(.*)/:locale(de|en)?/:path(.*)?",
|
|
16
|
+
localized: [
|
|
17
|
+
["de", "http://:domain(.*)/de/:path(.*)?"],
|
|
18
|
+
["en", "http://:domain(.*)/:path(.*)?"],
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
],
|
|
24
22
|
});
|
|
25
23
|
runtime.overwriteGetLocale(() => "de");
|
|
26
24
|
expect(runtime.localizeHref("/hello")).toBe("/de/hello");
|
|
@@ -28,24 +26,22 @@ test("uses the locale from getLocale() if no locale is provided", async () => {
|
|
|
28
26
|
});
|
|
29
27
|
test("returns an absolute href if the provided href is absolute", async () => {
|
|
30
28
|
const runtime = await createParaglide({
|
|
31
|
-
|
|
29
|
+
blob: await newProject({
|
|
32
30
|
settings: {
|
|
33
31
|
baseLocale: "en",
|
|
34
32
|
locales: ["en", "de"],
|
|
35
33
|
},
|
|
36
34
|
}),
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
],
|
|
48
|
-
},
|
|
35
|
+
strategy: ["url", "globalVariable", "baseLocale"],
|
|
36
|
+
urlPatterns: [
|
|
37
|
+
{
|
|
38
|
+
pattern: "http://:domain(.*)/:locale(de|en)?/:path(.*)?",
|
|
39
|
+
localized: [
|
|
40
|
+
["de", "http://:domain(.*)/de/:path(.*)?"],
|
|
41
|
+
["en", "http://:domain(.*)/:path(.*)?"],
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
],
|
|
49
45
|
});
|
|
50
46
|
expect(runtime.localizeHref("http://example.com/hello", { locale: "de" })).toBe("http://example.com/de/hello");
|
|
51
47
|
expect(runtime.deLocalizeHref("http://example.com/de/hello")).toBe("http://example.com/hello");
|
|
@@ -53,24 +49,22 @@ test("returns an absolute href if the provided href is absolute", async () => {
|
|
|
53
49
|
// useful if domain based localization is used for example
|
|
54
50
|
test("returns an absolute href if the provided href is relative but the origin of the localized href differs", async () => {
|
|
55
51
|
const runtime = await createParaglide({
|
|
56
|
-
|
|
52
|
+
blob: await newProject({
|
|
57
53
|
settings: {
|
|
58
54
|
baseLocale: "en",
|
|
59
55
|
locales: ["en", "de"],
|
|
60
56
|
},
|
|
61
57
|
}),
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
],
|
|
73
|
-
},
|
|
58
|
+
strategy: ["url", "globalVariable", "baseLocale"],
|
|
59
|
+
urlPatterns: [
|
|
60
|
+
{
|
|
61
|
+
pattern: "http://example.com/:path(.*)?",
|
|
62
|
+
localized: [
|
|
63
|
+
["de", "http://de.example.com/:path(.*)?"],
|
|
64
|
+
["en", "http://example.com/:path(.*)?"],
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
],
|
|
74
68
|
});
|
|
75
69
|
// simulating routing from current en page to de page
|
|
76
70
|
runtime.overwriteGetLocale(() => "en");
|
|
@@ -86,24 +80,22 @@ test("returns an absolute href if the provided href is relative but the origin o
|
|
|
86
80
|
test("adding a base path", async () => {
|
|
87
81
|
const base = "shop";
|
|
88
82
|
const runtime = await createParaglide({
|
|
89
|
-
|
|
83
|
+
blob: await newProject({
|
|
90
84
|
settings: {
|
|
91
85
|
baseLocale: "en",
|
|
92
86
|
locales: ["en", "de"],
|
|
93
87
|
},
|
|
94
88
|
}),
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
{
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
],
|
|
106
|
-
},
|
|
89
|
+
strategy: ["url"],
|
|
90
|
+
urlPatterns: [
|
|
91
|
+
{
|
|
92
|
+
pattern: `/{${base}/}?:path(.*)?`,
|
|
93
|
+
localized: [
|
|
94
|
+
["de", `/{${base}/}?de/:path(.*)?`],
|
|
95
|
+
["en", `/{${base}/}?:path(.*)?`],
|
|
96
|
+
],
|
|
97
|
+
},
|
|
98
|
+
],
|
|
107
99
|
});
|
|
108
100
|
// simulating the current locale to be en
|
|
109
101
|
runtime.overwriteGetLocale(() => "en");
|
|
@@ -116,17 +108,15 @@ test("adding a base path", async () => {
|
|
|
116
108
|
});
|
|
117
109
|
test("default url patterns to improve out of the box experience", async () => {
|
|
118
110
|
const runtime = await createParaglide({
|
|
119
|
-
|
|
111
|
+
blob: await newProject({
|
|
120
112
|
settings: {
|
|
121
113
|
baseLocale: "en",
|
|
122
114
|
locales: ["en", "de", "fr"],
|
|
123
115
|
},
|
|
124
116
|
}),
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
urlPatterns: undefined,
|
|
129
|
-
},
|
|
117
|
+
isServer: "false",
|
|
118
|
+
strategy: ["url"],
|
|
119
|
+
urlPatterns: undefined,
|
|
130
120
|
});
|
|
131
121
|
// polyfilling window
|
|
132
122
|
globalThis.window = { location: new URL("http://example.com") };
|