@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.
Files changed (37) hide show
  1. package/dist/cli/steps/initialize-inlang-project.d.ts.map +1 -1
  2. package/dist/cli/utils.d.ts.map +1 -1
  3. package/dist/compiler/compile-bundle.d.ts.map +1 -1
  4. package/dist/compiler/compile-message.d.ts.map +1 -1
  5. package/dist/compiler/compile-pattern.d.ts.map +1 -1
  6. package/dist/compiler/compile-project.d.ts.map +1 -1
  7. package/dist/compiler/create-paraglide.d.ts +20 -14
  8. package/dist/compiler/create-paraglide.d.ts.map +1 -1
  9. package/dist/compiler/create-paraglide.js +18 -14
  10. package/dist/compiler/create-paraglide.test.js +7 -11
  11. package/dist/compiler/index.d.ts +1 -1
  12. package/dist/compiler/index.d.ts.map +1 -1
  13. package/dist/compiler/index.js +1 -1
  14. package/dist/compiler/runtime/assert-is-locale.test.js +3 -3
  15. package/dist/compiler/runtime/extract-locale-from-cookie.test.js +7 -11
  16. package/dist/compiler/runtime/extract-locale-from-request.test.js +57 -77
  17. package/dist/compiler/runtime/extract-locale-from-url.d.ts.map +1 -1
  18. package/dist/compiler/runtime/extract-locale-from-url.js +35 -13
  19. package/dist/compiler/runtime/extract-locale-from-url.test.js +51 -61
  20. package/dist/compiler/runtime/generate-static-localized-urls.test.js +48 -58
  21. package/dist/compiler/runtime/get-locale.test.js +52 -68
  22. package/dist/compiler/runtime/get-url-origin.test.js +2 -4
  23. package/dist/compiler/runtime/localize-href.d.ts.map +1 -1
  24. package/dist/compiler/runtime/localize-href.js +7 -4
  25. package/dist/compiler/runtime/localize-href.test.js +48 -58
  26. package/dist/compiler/runtime/localize-url.test.js +258 -294
  27. package/dist/compiler/runtime/set-locale.test.js +56 -74
  28. package/dist/compiler/runtime/track-message-call.test.js +1 -1
  29. package/dist/compiler/server/middleware.d.ts +4 -2
  30. package/dist/compiler/server/middleware.d.ts.map +1 -1
  31. package/dist/compiler/server/middleware.js +5 -3
  32. package/dist/compiler/server/middleware.test.js +163 -109
  33. package/dist/services/codegen/quotes.d.ts.map +1 -1
  34. package/dist/services/env-variables/index.js +1 -1
  35. package/dist/services/telemetry/capture.d.ts.map +1 -1
  36. package/dist/utilities/detect-json-formatting.d.ts.map +1 -1
  37. package/package.json +7 -7
@@ -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
- project: await newProject({
6
+ blob: await newProject({
7
7
  settings: {
8
8
  baseLocale: "en",
9
9
  locales: ["en", "de"],
10
10
  },
11
11
  }),
12
- compilerOptions: {
13
- strategy: ["url", "globalVariable", "baseLocale"],
14
- urlPatterns: [
15
- {
16
- pattern: "http://:domain(.*)/:locale(de|en)?/:path(.*)?",
17
- localized: [
18
- ["de", "http://:domain(.*)/de/:path(.*)?"],
19
- ["en", "http://:domain(.*)/:path(.*)?"],
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
- project: await newProject({
29
+ blob: await newProject({
32
30
  settings: {
33
31
  baseLocale: "en",
34
32
  locales: ["en", "de"],
35
33
  },
36
34
  }),
37
- compilerOptions: {
38
- strategy: ["url", "globalVariable", "baseLocale"],
39
- urlPatterns: [
40
- {
41
- pattern: "http://:domain(.*)/:locale(de|en)?/:path(.*)?",
42
- localized: [
43
- ["de", "http://:domain(.*)/de/:path(.*)?"],
44
- ["en", "http://:domain(.*)/:path(.*)?"],
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
- project: await newProject({
52
+ blob: await newProject({
57
53
  settings: {
58
54
  baseLocale: "en",
59
55
  locales: ["en", "de"],
60
56
  },
61
57
  }),
62
- compilerOptions: {
63
- strategy: ["url", "globalVariable", "baseLocale"],
64
- urlPatterns: [
65
- {
66
- pattern: "http://example.com/:path(.*)?",
67
- localized: [
68
- ["de", "http://de.example.com/:path(.*)?"],
69
- ["en", "http://example.com/:path(.*)?"],
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
- project: await newProject({
83
+ blob: await newProject({
90
84
  settings: {
91
85
  baseLocale: "en",
92
86
  locales: ["en", "de"],
93
87
  },
94
88
  }),
95
- compilerOptions: {
96
- strategy: ["url"],
97
- urlPatterns: [
98
- {
99
- pattern: `/{${base}/}?:path(.*)?`,
100
- localized: [
101
- ["de", `/{${base}/}?de/:path(.*)?`],
102
- ["en", `/{${base}/}?:path(.*)?`],
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
- project: await newProject({
111
+ blob: await newProject({
120
112
  settings: {
121
113
  baseLocale: "en",
122
114
  locales: ["en", "de", "fr"],
123
115
  },
124
116
  }),
125
- compilerOptions: {
126
- isServer: "false",
127
- strategy: ["url"],
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") };