intor 2.3.30 → 2.3.31
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/express/src/adapters/express/middleware/create-intor-middleware.js +4 -11
- package/dist/next/src/adapters/next/proxy/intor-proxy.js +1 -1
- package/dist/svelte-kit/src/adapters/svelte-kit/server/create-intor-handle.js +25 -17
- package/dist/svelte-kit/src/adapters/svelte-kit/server/utils/is-svelte-kit-ssg.js +15 -0
- package/dist/types/src/adapters/svelte-kit/server/utils/is-svelte-kit-ssg.d.ts +8 -0
- package/package.json +3 -3
- package/dist/express/src/core/constants/headers.js +0 -6
- package/dist/svelte-kit/src/core/constants/headers.js +0 -6
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { INTOR_HEADERS } from '../../../core/constants/headers.js';
|
|
2
1
|
import '../../../core/error/intor-error.js';
|
|
3
2
|
import { normalizeQuery } from '../../../core/utils/normalizers/normalize-query.js';
|
|
4
3
|
import 'logry';
|
|
@@ -23,7 +22,7 @@ import { parseCookieHeader } from '../../../server/shared/utils/parse-cookie-hea
|
|
|
23
22
|
*/
|
|
24
23
|
function createIntorMiddleware(config, options) {
|
|
25
24
|
return async function intorMiddleware(req, _res, next) {
|
|
26
|
-
//
|
|
25
|
+
// Locale from Accept-Language header
|
|
27
26
|
const acceptLanguage = req.headers["accept-language"];
|
|
28
27
|
const localeFromAcceptLanguage = getLocaleFromAcceptLanguage(acceptLanguage, config.supportedLocales);
|
|
29
28
|
// ----------------------------------------------------------
|
|
@@ -35,15 +34,10 @@ function createIntorMiddleware(config, options) {
|
|
|
35
34
|
cookie: parseCookieHeader(req.headers.cookie)[config.cookie.name],
|
|
36
35
|
detected: localeFromAcceptLanguage || config.defaultLocale,
|
|
37
36
|
});
|
|
38
|
-
//
|
|
39
|
-
// Attach routing metadata to response headers
|
|
40
|
-
// --------------------------------------------------
|
|
41
|
-
req.headers[INTOR_HEADERS.LOCALE] = locale;
|
|
42
|
-
req.headers[INTOR_HEADERS.LOCALE_SOURCE] = localeSource;
|
|
43
|
-
req.headers[INTOR_HEADERS.PATHNAME] = pathname;
|
|
44
|
-
// --------------------------------------------------
|
|
37
|
+
// ----------------------------------------------------------
|
|
45
38
|
// Bind inbound routing context
|
|
46
|
-
//
|
|
39
|
+
// ----------------------------------------------------------
|
|
40
|
+
req.intor = { locale, localeSource, pathname };
|
|
47
41
|
const { hasKey, t } = (await getTranslator(config, {
|
|
48
42
|
locale,
|
|
49
43
|
handlers: options?.handlers,
|
|
@@ -51,7 +45,6 @@ function createIntorMiddleware(config, options) {
|
|
|
51
45
|
readers: options?.readers,
|
|
52
46
|
allowCacheWrite: true,
|
|
53
47
|
}));
|
|
54
|
-
req.intor = { locale, localeSource, pathname };
|
|
55
48
|
// DX shortcuts (optional)
|
|
56
49
|
req.locale = locale;
|
|
57
50
|
req.hasKey = hasKey;
|
|
@@ -17,7 +17,7 @@ import { getLocaleFromAcceptLanguage } from '../../../routing/locale/get-locale-
|
|
|
17
17
|
* @platform Next.js
|
|
18
18
|
*/
|
|
19
19
|
const intorProxy = async (config, request) => {
|
|
20
|
-
//
|
|
20
|
+
// Locale from Accept-Language header
|
|
21
21
|
const acceptLanguageHeader = request.headers.get("accept-language");
|
|
22
22
|
const localeFromAcceptLanguage = getLocaleFromAcceptLanguage(acceptLanguageHeader, config.supportedLocales);
|
|
23
23
|
// Check whether this navigation flow has already redirected
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { redirect } from '@sveltejs/kit';
|
|
2
|
-
import {
|
|
2
|
+
import { isSvelteKitSSG } from './utils/is-svelte-kit-ssg.js';
|
|
3
3
|
import '../../../core/error/intor-error.js';
|
|
4
4
|
import { normalizeQuery } from '../../../core/utils/normalizers/normalize-query.js';
|
|
5
5
|
import 'logry';
|
|
@@ -18,28 +18,37 @@ import { getLocaleFromAcceptLanguage } from '../../../routing/locale/get-locale-
|
|
|
18
18
|
*/
|
|
19
19
|
function createIntorHandle(config) {
|
|
20
20
|
return async ({ event, resolve }) => {
|
|
21
|
-
// ----------------------------------------------------------
|
|
22
21
|
// Locale from Accept-Language header
|
|
23
|
-
// ----------------------------------------------------------
|
|
24
22
|
const acceptLanguage = event.request.headers.get("accept-language");
|
|
25
23
|
const localeFromAcceptLanguage = getLocaleFromAcceptLanguage(acceptLanguage, config.supportedLocales);
|
|
26
24
|
// ----------------------------------------------------------
|
|
27
25
|
// Resolve inbound routing decision (pure computation)
|
|
28
26
|
// ----------------------------------------------------------
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
let inbound;
|
|
28
|
+
if (isSvelteKitSSG(event)) {
|
|
29
|
+
inbound = {
|
|
30
|
+
locale: event.params?.locale,
|
|
31
|
+
localeSource: "path",
|
|
32
|
+
pathname: event.url.pathname,
|
|
33
|
+
shouldRedirect: false,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
inbound = await resolveInbound(config, event.url.pathname, false, {
|
|
38
|
+
host: event.url.host,
|
|
39
|
+
query: normalizeQuery(Object.fromEntries(event.url.searchParams.entries())),
|
|
40
|
+
cookie: event.cookies.get(config.cookie.name),
|
|
41
|
+
detected: localeFromAcceptLanguage || config.defaultLocale,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const { locale, localeSource, pathname, shouldRedirect } = inbound;
|
|
35
45
|
// ----------------------------------------------------------
|
|
36
46
|
// Redirect if needed
|
|
37
47
|
// ----------------------------------------------------------
|
|
38
|
-
if (shouldRedirect)
|
|
39
|
-
|
|
40
|
-
}
|
|
48
|
+
if (shouldRedirect)
|
|
49
|
+
redirect(307, pathname);
|
|
41
50
|
// ----------------------------------------------------------
|
|
42
|
-
//
|
|
51
|
+
// Bind inbound routing context
|
|
43
52
|
// ----------------------------------------------------------
|
|
44
53
|
// @ts-expect-error - App.Locals must be extended by user
|
|
45
54
|
event.locals.intor = {
|
|
@@ -47,10 +56,9 @@ function createIntorHandle(config) {
|
|
|
47
56
|
localeSource,
|
|
48
57
|
pathname,
|
|
49
58
|
};
|
|
50
|
-
const response = await resolve(event
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
response.headers.set(INTOR_HEADERS.PATHNAME, pathname);
|
|
59
|
+
const response = await resolve(event, {
|
|
60
|
+
transformPageChunk: ({ html }) => html.replace("%lang%", locale),
|
|
61
|
+
});
|
|
54
62
|
return response;
|
|
55
63
|
};
|
|
56
64
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Heuristic to detect static (prerender) execution in SvelteKit.
|
|
3
|
+
*
|
|
4
|
+
* This is NOT a guaranteed signal.
|
|
5
|
+
* It intentionally prefers false positives over false negatives.
|
|
6
|
+
*/
|
|
7
|
+
function isSvelteKitSSG(event) {
|
|
8
|
+
// No user-agent is a strong signal of static rendering
|
|
9
|
+
if (event.request.headers.get("user-agent") === null) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { isSvelteKitSSG };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RequestEvent } from "@sveltejs/kit";
|
|
2
|
+
/**
|
|
3
|
+
* Heuristic to detect static (prerender) execution in SvelteKit.
|
|
4
|
+
*
|
|
5
|
+
* This is NOT a guaranteed signal.
|
|
6
|
+
* It intentionally prefers false positives over false negatives.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isSvelteKitSSG(event: RequestEvent<Record<string, string>, string | null>): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "intor",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.31",
|
|
4
4
|
"description": "The i18n library for modern JavaScript",
|
|
5
5
|
"author": "Yiming Liao",
|
|
6
6
|
"homepage": "https://github.com/yiming-liao/intor#readme",
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
"@rollup/plugin-alias": "6.0.0",
|
|
117
117
|
"@rollup/plugin-typescript": "12.3.0",
|
|
118
118
|
"@rollup/pluginutils": "5.3.0",
|
|
119
|
-
"@sveltejs/kit": "
|
|
119
|
+
"@sveltejs/kit": "2.50.1",
|
|
120
120
|
"@testing-library/dom": "10.4.1",
|
|
121
121
|
"@testing-library/jest-dom": "6.9.1",
|
|
122
122
|
"@testing-library/react": "16.3.1",
|
|
@@ -146,7 +146,7 @@
|
|
|
146
146
|
"remark": "15.0.1",
|
|
147
147
|
"remark-gfm": "4.0.1",
|
|
148
148
|
"rollup": "4.53.3",
|
|
149
|
-
"rollup-plugin-copy": "
|
|
149
|
+
"rollup-plugin-copy": "3.5.0",
|
|
150
150
|
"svelte": "5.46.1",
|
|
151
151
|
"tsc-alias": "1.8.16",
|
|
152
152
|
"tsd": "0.33.0",
|