intor 2.3.15 → 2.3.16
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/core/export/index.js +1 -1
- package/dist/core/src/routing/pathname/{get-unprefixed-pathname.js → canonicalize-pathname.js} +3 -3
- package/dist/core/src/routing/pathname/localize-pathname.js +15 -15
- package/dist/{next/src/routing/pathname/locale-prefix-pathname.js → core/src/routing/pathname/materialize-pathname.js} +6 -5
- package/dist/core/src/routing/pathname/standardize-pathname.js +9 -9
- package/dist/core/src/server/helpers/get-translator.js +0 -1
- package/dist/core/src/server/intor/intor.js +2 -2
- package/dist/core/src/server/translator/create-translator.js +0 -1
- package/dist/express/src/adapters/express/helpers/get-translator.js +4 -0
- package/dist/express/src/adapters/express/middleware/create-intor.js +3 -5
- package/dist/express/src/routing/inbound/resolve-pathname/resolve-pathname.js +1 -1
- package/dist/{next/src/routing/pathname/get-unprefixed-pathname.js → express/src/routing/pathname/canonicalize-pathname.js} +3 -3
- package/dist/express/src/routing/pathname/localize-pathname.js +15 -15
- package/dist/{core/src/routing/pathname/locale-prefix-pathname.js → express/src/routing/pathname/materialize-pathname.js} +6 -5
- package/dist/express/src/routing/pathname/standardize-pathname.js +9 -9
- package/dist/express/src/server/helpers/get-translator.js +0 -1
- package/dist/express/src/server/translator/create-translator.js +0 -1
- package/dist/next/src/adapters/next/navigation/use-pathname.js +4 -4
- package/dist/next/src/adapters/next/proxy/intor-proxy.js +1 -1
- package/dist/next/src/adapters/next/server/get-pathname.js +4 -4
- package/dist/next/src/adapters/next/server/get-translator.js +4 -0
- package/dist/next/src/adapters/next/server/intor.js +1 -1
- package/dist/next/src/routing/inbound/resolve-pathname/resolve-pathname.js +1 -1
- package/dist/next/src/routing/navigation/derive-target.js +5 -5
- package/dist/next/src/routing/navigation/utils/derive-host-destination.js +1 -1
- package/dist/next/src/routing/navigation/utils/derive-query-destination.js +1 -1
- package/dist/{express/src/routing/pathname/get-unprefixed-pathname.js → next/src/routing/pathname/canonicalize-pathname.js} +3 -3
- package/dist/next/src/routing/pathname/localize-pathname.js +15 -15
- package/dist/{react/src/routing/pathname/locale-prefix-pathname.js → next/src/routing/pathname/materialize-pathname.js} +6 -5
- package/dist/next/src/routing/pathname/standardize-pathname.js +9 -9
- package/dist/next/src/server/helpers/get-translator.js +0 -1
- package/dist/next/src/server/intor/intor.js +2 -2
- package/dist/next/src/server/translator/create-translator.js +0 -1
- package/dist/react/export/react/index.js +1 -1
- package/dist/react/src/client/react/navigation/use-execute-navigation.js +3 -3
- package/dist/react/src/client/react/provider/effects/use-locale-effects.js +5 -5
- package/dist/react/src/client/react/render/create-react-renderer.js +5 -0
- package/dist/react/src/client/react/translator/create-t-rich.js +2 -2
- package/dist/react/src/client/react/translator/{t.js → trans.js} +4 -4
- package/dist/react/src/client/react/translator/use-translator.js +0 -5
- package/dist/react/src/client/shared/helpers/get-client-locale.js +2 -2
- package/dist/react/src/client/shared/utils/locale/detect-browser-locale.js +1 -1
- package/dist/{vue/src/client/shared/utils/locale/get-locale-cookie-browser.js → react/src/client/shared/utils/locale/get-locale-from-cookie.js} +3 -3
- package/dist/react/src/client/shared/utils/locale/set-document-locale.js +2 -2
- package/dist/{svelte/src/client/shared/utils/locale/set-locale-cookie-browser.js → react/src/client/shared/utils/locale/set-locale-cookie.js} +4 -4
- package/dist/react/src/routing/navigation/derive-target.js +5 -5
- package/dist/react/src/routing/navigation/utils/derive-host-destination.js +1 -1
- package/dist/react/src/routing/navigation/utils/derive-query-destination.js +1 -1
- package/dist/react/src/routing/pathname/{get-unprefixed-pathname.js → canonicalize-pathname.js} +3 -3
- package/dist/react/src/routing/pathname/localize-pathname.js +15 -15
- package/dist/{express/src/routing/pathname/locale-prefix-pathname.js → react/src/routing/pathname/materialize-pathname.js} +6 -5
- package/dist/react/src/routing/pathname/standardize-pathname.js +9 -9
- package/dist/svelte/src/client/shared/helpers/get-client-locale.js +2 -2
- package/dist/svelte/src/client/shared/utils/locale/detect-browser-locale.js +1 -1
- package/dist/{react/src/client/shared/utils/locale/get-locale-cookie-browser.js → svelte/src/client/shared/utils/locale/get-locale-from-cookie.js} +3 -3
- package/dist/svelte/src/client/shared/utils/locale/set-document-locale.js +2 -2
- package/dist/{vue/src/client/shared/utils/locale/set-locale-cookie-browser.js → svelte/src/client/shared/utils/locale/set-locale-cookie.js} +4 -4
- package/dist/svelte/src/client/svelte/render/create-svelte-renderer.js +12 -0
- package/dist/svelte/src/client/svelte/runtime/create-intor-api.js +0 -4
- package/dist/svelte/src/client/svelte/runtime/create-intor.js +3 -14
- package/dist/svelte/src/client/svelte/runtime/effects/locale-effects.js +5 -5
- package/dist/types/export/index.d.ts +1 -1
- package/dist/types/export/internal/index.d.ts +2 -1
- package/dist/types/export/react/index.d.ts +1 -1
- package/dist/types/export/server/index.d.ts +1 -1
- package/dist/types/export/vue/index.d.ts +1 -1
- package/dist/types/src/adapters/express/global.d.ts +4 -5
- package/dist/types/src/adapters/express/helpers/get-translator.d.ts +5 -5
- package/dist/types/src/adapters/express/middleware/create-intor.d.ts +1 -1
- package/dist/types/src/adapters/next/navigation/use-pathname.d.ts +3 -3
- package/dist/types/src/adapters/next/proxy/intor-proxy.d.ts +1 -1
- package/dist/types/src/adapters/next/server/get-pathname.d.ts +3 -3
- package/dist/types/src/adapters/next/server/get-translator.d.ts +5 -5
- package/dist/types/src/adapters/next/server/intor.d.ts +3 -3
- package/dist/types/src/client/react/helpers/use-runtime-state.d.ts +5 -3
- package/dist/types/src/client/react/index.d.ts +1 -1
- package/dist/types/src/client/react/provider/types.d.ts +10 -9
- package/dist/types/src/client/react/render/create-react-renderer.d.ts +1 -0
- package/dist/types/src/client/react/render/render-rich-message-react.d.ts +2 -1
- package/dist/types/src/client/react/render/types.d.ts +15 -10
- package/dist/types/src/client/react/translator/index.d.ts +1 -1
- package/dist/types/src/client/react/translator/trans.d.ts +27 -0
- package/dist/types/src/client/react/translator/translator-instance.d.ts +4 -4
- package/dist/types/src/client/react/translator/use-translator.d.ts +4 -4
- package/dist/types/src/client/shared/utils/index.d.ts +1 -1
- package/dist/types/src/client/shared/utils/locale/detect-browser-locale.d.ts +1 -1
- package/dist/types/src/client/shared/utils/locale/get-locale-from-cookie.d.ts +6 -0
- package/dist/types/src/client/shared/utils/locale/index.d.ts +2 -2
- package/dist/types/src/client/shared/utils/locale/set-document-locale.d.ts +2 -2
- package/dist/types/src/client/shared/utils/locale/set-locale-cookie.d.ts +7 -0
- package/dist/types/src/client/svelte/helpers/create-runtime-state.d.ts +7 -6
- package/dist/types/src/client/svelte/render/render-rich-message-svelte.d.ts +2 -1
- package/dist/types/src/client/svelte/runtime/create-intor-api.d.ts +0 -2
- package/dist/types/src/client/svelte/runtime/create-intor.d.ts +1 -2
- package/dist/types/src/client/svelte/runtime/types.d.ts +19 -23
- package/dist/types/src/client/vue/helpers/use-runtime-state.d.ts +7 -6
- package/dist/types/src/client/vue/index.d.ts +1 -1
- package/dist/types/src/client/vue/provider/inject.d.ts +1 -2
- package/dist/types/src/client/vue/provider/resolver/resolve-runtime.d.ts +1 -1
- package/dist/types/src/client/vue/provider/types.d.ts +11 -11
- package/dist/types/src/client/vue/render/create-vue-renderer.d.ts +1 -0
- package/dist/types/src/client/vue/render/render-rich-message-vue.d.ts +2 -1
- package/dist/types/src/client/vue/render/types.d.ts +14 -6
- package/dist/types/src/client/vue/translator/index.d.ts +1 -1
- package/dist/types/src/client/vue/translator/{t.d.ts → trans.d.ts} +4 -5
- package/dist/types/src/client/vue/translator/translator-instance.d.ts +4 -4
- package/dist/types/src/client/vue/translator/use-translator.d.ts +5 -5
- package/dist/types/src/core/index.d.ts +1 -1
- package/dist/types/src/core/types/generated.d.ts +14 -5
- package/dist/types/src/core/types/index.d.ts +2 -3
- package/dist/types/src/core/types/translator-instance.d.ts +5 -21
- package/dist/types/src/routing/navigation/utils/derive-host-destination.d.ts +1 -1
- package/dist/types/src/routing/navigation/utils/derive-query-destination.d.ts +1 -1
- package/dist/types/src/routing/pathname/{get-unprefixed-pathname.d.ts → canonicalize-pathname.d.ts} +2 -2
- package/dist/types/src/routing/pathname/localize-pathname.d.ts +16 -13
- package/dist/types/src/routing/pathname/materialize-pathname.d.ts +17 -0
- package/dist/types/src/routing/pathname/standardize-pathname.d.ts +7 -6
- package/dist/types/src/server/helpers/get-translator.d.ts +5 -5
- package/dist/types/src/server/index.d.ts +1 -1
- package/dist/types/src/server/intor/index.d.ts +1 -1
- package/dist/types/src/server/intor/intor.d.ts +4 -4
- package/dist/types/src/server/intor/types.d.ts +5 -3
- package/dist/types/src/server/runtime/create-intor-runtime.d.ts +1 -2
- package/dist/types/src/server/runtime/types.d.ts +6 -12
- package/dist/types/src/server/translator/create-translator.d.ts +1 -2
- package/dist/types/src/server/translator/translator-instance.d.ts +3 -3
- package/dist/vue/export/vue/index.js +1 -1
- package/dist/vue/src/client/shared/helpers/get-client-locale.js +2 -2
- package/dist/vue/src/client/shared/utils/locale/detect-browser-locale.js +1 -1
- package/dist/{svelte/src/client/shared/utils/locale/get-locale-cookie-browser.js → vue/src/client/shared/utils/locale/get-locale-from-cookie.js} +3 -3
- package/dist/vue/src/client/shared/utils/locale/set-document-locale.js +2 -2
- package/dist/{react/src/client/shared/utils/locale/set-locale-cookie-browser.js → vue/src/client/shared/utils/locale/set-locale-cookie.js} +4 -4
- package/dist/vue/src/client/vue/provider/effects/use-locale-effects.js +5 -5
- package/dist/vue/src/client/vue/render/create-vue-renderer.js +5 -0
- package/dist/vue/src/client/vue/translator/{t.js → trans.js} +3 -3
- package/dist/vue/src/client/vue/translator/use-translator.js +0 -2
- package/package.json +2 -2
- package/dist/types/src/client/react/translator/t.d.ts +0 -27
- package/dist/types/src/client/shared/types/index.d.ts +0 -1
- package/dist/types/src/client/shared/types/runtime-state.d.ts +0 -13
- package/dist/types/src/client/shared/utils/locale/get-locale-cookie-browser.d.ts +0 -6
- package/dist/types/src/client/shared/utils/locale/set-locale-cookie-browser.d.ts +0 -7
- package/dist/types/src/core/types/bootstrap.d.ts +0 -13
- package/dist/types/src/routing/pathname/locale-prefix-pathname.d.ts +0 -16
|
@@ -10,4 +10,4 @@ export { mergeMessages } from '../src/core/messages/merge-messages.js';
|
|
|
10
10
|
export { defineIntorConfig } from '../src/config/define-intor-config.js';
|
|
11
11
|
import '../src/config/constants/cookie.js';
|
|
12
12
|
export { localizePathname } from '../src/routing/pathname/localize-pathname.js';
|
|
13
|
-
export { Translator } from 'intor-translator';
|
|
13
|
+
export { Translator, tokenize } from 'intor-translator';
|
package/dist/core/src/routing/pathname/{get-unprefixed-pathname.js → canonicalize-pathname.js}
RENAMED
|
@@ -10,11 +10,11 @@ import 'logry';
|
|
|
10
10
|
* // config.supportedLocales: ["en-US"]
|
|
11
11
|
* // config.routing.basePath: "/app"
|
|
12
12
|
* // config.routing.prefix: "all"
|
|
13
|
-
*
|
|
13
|
+
* canonicalizePathname("/app/en-US/about", config);
|
|
14
14
|
* // => "/about"
|
|
15
15
|
*```
|
|
16
16
|
*/
|
|
17
|
-
function
|
|
17
|
+
function canonicalizePathname(rawPathname, config) {
|
|
18
18
|
const { routing, supportedLocales } = config;
|
|
19
19
|
const { basePath } = routing;
|
|
20
20
|
// 1. Normalize pathname
|
|
@@ -38,4 +38,4 @@ function getUnprefixedPathname(config, rawPathname) {
|
|
|
38
38
|
: prefixedPathname;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export {
|
|
41
|
+
export { canonicalizePathname };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { canonicalizePathname } from './canonicalize-pathname.js';
|
|
2
|
+
import { materializePathname } from './materialize-pathname.js';
|
|
3
3
|
import { standardizePathname } from './standardize-pathname.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -11,25 +11,25 @@ import { standardizePathname } from './standardize-pathname.js';
|
|
|
11
11
|
* // config.supportedLocales: ["en-US"]
|
|
12
12
|
* // config.routing.basePath: "/app"
|
|
13
13
|
* // config.routing.prefix: "all"
|
|
14
|
-
*
|
|
14
|
+
* localizePathname(config, "/app/en-US/about", "en-US");
|
|
15
15
|
* // => {
|
|
16
|
+
* // pathname: '/app/en-US/about'
|
|
16
17
|
* // unprefixedPathname: '/about',
|
|
17
|
-
* //
|
|
18
|
-
* // localizedPathname: '/app/en-US/about'
|
|
18
|
+
* // templatedPathname: '/app/{locale}/about',
|
|
19
19
|
* // }
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
-
const localizePathname = (
|
|
23
|
-
// 1. Canonicalize:
|
|
24
|
-
const
|
|
25
|
-
// 2. Standardize:
|
|
26
|
-
const
|
|
27
|
-
// 3.
|
|
28
|
-
const
|
|
22
|
+
const localizePathname = (rawPathname, config, locale) => {
|
|
23
|
+
// 1. Canonicalize: normalize and remove routing-specific prefixes
|
|
24
|
+
const canonicalized = canonicalizePathname(rawPathname, config);
|
|
25
|
+
// 2. Standardize: convert to internal pathname shape with locale placeholder
|
|
26
|
+
const standardized = standardizePathname(canonicalized, config);
|
|
27
|
+
// 3. Materialize: apply routing rules to produce the final pathname
|
|
28
|
+
const materialized = materializePathname(standardized, config, locale);
|
|
29
29
|
return {
|
|
30
|
-
pathname,
|
|
31
|
-
unprefixedPathname,
|
|
32
|
-
|
|
30
|
+
pathname: materialized,
|
|
31
|
+
unprefixedPathname: canonicalized,
|
|
32
|
+
templatedPathname: standardized,
|
|
33
33
|
};
|
|
34
34
|
};
|
|
35
35
|
|
|
@@ -4,20 +4,21 @@ import { normalizePathname } from '../../core/utils/normalizers/normalize-pathna
|
|
|
4
4
|
import 'logry';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Materializes a standardized pathname by applying
|
|
8
|
+
* the configured locale prefix behavior.
|
|
8
9
|
*
|
|
9
10
|
* @example
|
|
10
11
|
* ```ts
|
|
11
12
|
* // config.routing.localePrefix: "all"
|
|
12
|
-
*
|
|
13
|
+
* materializePathname("/app/{locale}/about", config, "en-US");
|
|
13
14
|
* // => /app/en-US/about
|
|
14
15
|
*
|
|
15
16
|
* // config.routing.localePrefix: "none"
|
|
16
|
-
*
|
|
17
|
+
* materializePathname("/app/{locale}/about", config, "en-US");
|
|
17
18
|
* // => /app/about
|
|
18
19
|
* ```
|
|
19
20
|
*/
|
|
20
|
-
const
|
|
21
|
+
const materializePathname = (standardizedPathname, config, locale) => {
|
|
21
22
|
const { localePrefix } = config.routing;
|
|
22
23
|
if (localePrefix !== "none" && !locale) {
|
|
23
24
|
throw new Error('No locale when using localePrefix "all", "except-default"');
|
|
@@ -36,4 +37,4 @@ const localePrefixPathname = (config, standardizedPathname, locale) => {
|
|
|
36
37
|
return normalizePathname(standardizedPathname.replaceAll(`/${PREFIX_PLACEHOLDER}`, ""));
|
|
37
38
|
};
|
|
38
39
|
|
|
39
|
-
export {
|
|
40
|
+
export { materializePathname };
|
|
@@ -4,24 +4,24 @@ import { normalizePathname } from '../../core/utils/normalizers/normalize-pathna
|
|
|
4
4
|
import 'logry';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Standardizes a canonical pathname
|
|
8
|
-
* and injecting
|
|
7
|
+
* Standardizes a canonical pathname into an internal routing template
|
|
8
|
+
* by applying the base path and injecting a locale placeholder.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```ts
|
|
12
|
-
* // routing.basePath: "/app",
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* // config.routing.basePath: "/app",
|
|
13
|
+
* // config.routing.prefix: "all"
|
|
14
|
+
* standardizePathname("/about", config);
|
|
15
|
+
* // => "/app/{locale}/about"
|
|
15
16
|
* ```
|
|
16
17
|
*/
|
|
17
|
-
const standardizePathname = (
|
|
18
|
-
const {
|
|
19
|
-
const { basePath } = routing;
|
|
18
|
+
const standardizePathname = (canonicalizedPathname, config) => {
|
|
19
|
+
const { basePath } = config.routing;
|
|
20
20
|
// Normalize each segment before join to avoid redundant slashes
|
|
21
21
|
const parts = [
|
|
22
22
|
normalizePathname(basePath),
|
|
23
23
|
PREFIX_PLACEHOLDER,
|
|
24
|
-
normalizePathname(
|
|
24
|
+
normalizePathname(canonicalizedPathname),
|
|
25
25
|
];
|
|
26
26
|
// Avoid double slashes between segments
|
|
27
27
|
const standardizedPathname = parts.join("/").replaceAll(/\/{2,}/g, "/");
|
|
@@ -5,8 +5,8 @@ import { createIntorRuntime } from '../runtime/create-intor-runtime.js';
|
|
|
5
5
|
/**
|
|
6
6
|
* Initializes Intor for the current execution context.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
* full-stack
|
|
8
|
+
* Produces a server-side snapshot for SSR and
|
|
9
|
+
* full-stack rendering environments.
|
|
10
10
|
*/
|
|
11
11
|
async function intor(config, localeOrResolver, options) {
|
|
12
12
|
const baseLogger = getLogger(config.logger);
|
|
@@ -16,6 +16,10 @@ async function getTranslator(config, req, params) {
|
|
|
16
16
|
plugins,
|
|
17
17
|
readers,
|
|
18
18
|
allowCacheWrite,
|
|
19
|
+
// NOTE:
|
|
20
|
+
// The runtime implementation is intentionally erased.
|
|
21
|
+
// Type safety is guaranteed by public type contracts.
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
23
|
});
|
|
20
24
|
}
|
|
21
25
|
|
|
@@ -15,7 +15,7 @@ import { getTranslator } from '../../../server/helpers/get-translator.js';
|
|
|
15
15
|
*
|
|
16
16
|
* The resolved routing state is exposed via response headers.
|
|
17
17
|
*
|
|
18
|
-
* -
|
|
18
|
+
* - Permits cache writes during server execution.
|
|
19
19
|
* - Convenience routing shortcuts are also bound to the request for downstream consumption.
|
|
20
20
|
*
|
|
21
21
|
* @platform Express
|
|
@@ -43,20 +43,18 @@ function createIntor(config, options) {
|
|
|
43
43
|
// --------------------------------------------------
|
|
44
44
|
// Bind inbound routing context
|
|
45
45
|
// --------------------------------------------------
|
|
46
|
-
const { hasKey, t
|
|
46
|
+
const { hasKey, t } = (await getTranslator(config, {
|
|
47
47
|
locale,
|
|
48
48
|
handlers: options?.handlers,
|
|
49
49
|
plugins: options?.plugins,
|
|
50
50
|
readers: options?.readers,
|
|
51
51
|
allowCacheWrite: true,
|
|
52
52
|
}));
|
|
53
|
-
req.intor = { locale, localeSource };
|
|
53
|
+
req.intor = { locale, localeSource, pathname };
|
|
54
54
|
// DX shortcuts (optional)
|
|
55
55
|
req.locale = locale;
|
|
56
|
-
req.localeSource = localeSource;
|
|
57
56
|
req.hasKey = hasKey;
|
|
58
57
|
req.t = t;
|
|
59
|
-
req.tRaw = tRaw;
|
|
60
58
|
return next();
|
|
61
59
|
};
|
|
62
60
|
}
|
|
@@ -32,7 +32,7 @@ const resolvePathname = (config, rawPathname, context) => {
|
|
|
32
32
|
return assertNever(localePrefix);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
const { pathname } = localizePathname(
|
|
35
|
+
const { pathname } = localizePathname(rawPathname, config, context.locale);
|
|
36
36
|
return {
|
|
37
37
|
pathname,
|
|
38
38
|
shouldRedirect: directive.type === "redirect",
|
|
@@ -10,11 +10,11 @@ import 'logry';
|
|
|
10
10
|
* // config.supportedLocales: ["en-US"]
|
|
11
11
|
* // config.routing.basePath: "/app"
|
|
12
12
|
* // config.routing.prefix: "all"
|
|
13
|
-
*
|
|
13
|
+
* canonicalizePathname("/app/en-US/about", config);
|
|
14
14
|
* // => "/about"
|
|
15
15
|
*```
|
|
16
16
|
*/
|
|
17
|
-
function
|
|
17
|
+
function canonicalizePathname(rawPathname, config) {
|
|
18
18
|
const { routing, supportedLocales } = config;
|
|
19
19
|
const { basePath } = routing;
|
|
20
20
|
// 1. Normalize pathname
|
|
@@ -38,4 +38,4 @@ function getUnprefixedPathname(config, rawPathname) {
|
|
|
38
38
|
: prefixedPathname;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export {
|
|
41
|
+
export { canonicalizePathname };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { canonicalizePathname } from './canonicalize-pathname.js';
|
|
2
|
+
import { materializePathname } from './materialize-pathname.js';
|
|
3
3
|
import { standardizePathname } from './standardize-pathname.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -11,25 +11,25 @@ import { standardizePathname } from './standardize-pathname.js';
|
|
|
11
11
|
* // config.supportedLocales: ["en-US"]
|
|
12
12
|
* // config.routing.basePath: "/app"
|
|
13
13
|
* // config.routing.prefix: "all"
|
|
14
|
-
*
|
|
14
|
+
* localizePathname(config, "/app/en-US/about", "en-US");
|
|
15
15
|
* // => {
|
|
16
|
+
* // pathname: '/app/en-US/about'
|
|
16
17
|
* // unprefixedPathname: '/about',
|
|
17
|
-
* //
|
|
18
|
-
* // localizedPathname: '/app/en-US/about'
|
|
18
|
+
* // templatedPathname: '/app/{locale}/about',
|
|
19
19
|
* // }
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
-
const localizePathname = (
|
|
23
|
-
// 1. Canonicalize:
|
|
24
|
-
const
|
|
25
|
-
// 2. Standardize:
|
|
26
|
-
const
|
|
27
|
-
// 3.
|
|
28
|
-
const
|
|
22
|
+
const localizePathname = (rawPathname, config, locale) => {
|
|
23
|
+
// 1. Canonicalize: normalize and remove routing-specific prefixes
|
|
24
|
+
const canonicalized = canonicalizePathname(rawPathname, config);
|
|
25
|
+
// 2. Standardize: convert to internal pathname shape with locale placeholder
|
|
26
|
+
const standardized = standardizePathname(canonicalized, config);
|
|
27
|
+
// 3. Materialize: apply routing rules to produce the final pathname
|
|
28
|
+
const materialized = materializePathname(standardized, config, locale);
|
|
29
29
|
return {
|
|
30
|
-
pathname,
|
|
31
|
-
unprefixedPathname,
|
|
32
|
-
|
|
30
|
+
pathname: materialized,
|
|
31
|
+
unprefixedPathname: canonicalized,
|
|
32
|
+
templatedPathname: standardized,
|
|
33
33
|
};
|
|
34
34
|
};
|
|
35
35
|
|
|
@@ -4,20 +4,21 @@ import { normalizePathname } from '../../core/utils/normalizers/normalize-pathna
|
|
|
4
4
|
import 'logry';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Materializes a standardized pathname by applying
|
|
8
|
+
* the configured locale prefix behavior.
|
|
8
9
|
*
|
|
9
10
|
* @example
|
|
10
11
|
* ```ts
|
|
11
12
|
* // config.routing.localePrefix: "all"
|
|
12
|
-
*
|
|
13
|
+
* materializePathname("/app/{locale}/about", config, "en-US");
|
|
13
14
|
* // => /app/en-US/about
|
|
14
15
|
*
|
|
15
16
|
* // config.routing.localePrefix: "none"
|
|
16
|
-
*
|
|
17
|
+
* materializePathname("/app/{locale}/about", config, "en-US");
|
|
17
18
|
* // => /app/about
|
|
18
19
|
* ```
|
|
19
20
|
*/
|
|
20
|
-
const
|
|
21
|
+
const materializePathname = (standardizedPathname, config, locale) => {
|
|
21
22
|
const { localePrefix } = config.routing;
|
|
22
23
|
if (localePrefix !== "none" && !locale) {
|
|
23
24
|
throw new Error('No locale when using localePrefix "all", "except-default"');
|
|
@@ -36,4 +37,4 @@ const localePrefixPathname = (config, standardizedPathname, locale) => {
|
|
|
36
37
|
return normalizePathname(standardizedPathname.replaceAll(`/${PREFIX_PLACEHOLDER}`, ""));
|
|
37
38
|
};
|
|
38
39
|
|
|
39
|
-
export {
|
|
40
|
+
export { materializePathname };
|
|
@@ -4,24 +4,24 @@ import { normalizePathname } from '../../core/utils/normalizers/normalize-pathna
|
|
|
4
4
|
import 'logry';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Standardizes a canonical pathname
|
|
8
|
-
* and injecting
|
|
7
|
+
* Standardizes a canonical pathname into an internal routing template
|
|
8
|
+
* by applying the base path and injecting a locale placeholder.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```ts
|
|
12
|
-
* // routing.basePath: "/app",
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* // config.routing.basePath: "/app",
|
|
13
|
+
* // config.routing.prefix: "all"
|
|
14
|
+
* standardizePathname("/about", config);
|
|
15
|
+
* // => "/app/{locale}/about"
|
|
15
16
|
* ```
|
|
16
17
|
*/
|
|
17
|
-
const standardizePathname = (
|
|
18
|
-
const {
|
|
19
|
-
const { basePath } = routing;
|
|
18
|
+
const standardizePathname = (canonicalizedPathname, config) => {
|
|
19
|
+
const { basePath } = config.routing;
|
|
20
20
|
// Normalize each segment before join to avoid redundant slashes
|
|
21
21
|
const parts = [
|
|
22
22
|
normalizePathname(basePath),
|
|
23
23
|
PREFIX_PLACEHOLDER,
|
|
24
|
-
normalizePathname(
|
|
24
|
+
normalizePathname(canonicalizedPathname),
|
|
25
25
|
];
|
|
26
26
|
// Avoid double slashes between segments
|
|
27
27
|
const standardizedPathname = parts.join("/").replaceAll(/\/{2,}/g, "/");
|
|
@@ -9,17 +9,17 @@ import { localizePathname } from '../../../routing/pathname/localize-pathname.js
|
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```ts
|
|
12
|
-
* const { pathname,
|
|
13
|
-
* // pathname => "/en-US/about"
|
|
14
|
-
* // standardizedPathname => "/{locale}/about"
|
|
12
|
+
* const { pathname, unprefixedPathname, templatedPathname } = usePathname();
|
|
13
|
+
* // pathname => "/app/en-US/about"
|
|
15
14
|
* // unprefixedPathname => "/about"
|
|
15
|
+
* // templatedPathname => "/app/{locale}/about"
|
|
16
16
|
* ```
|
|
17
17
|
* @platform Next.js
|
|
18
18
|
*/
|
|
19
19
|
const usePathname = () => {
|
|
20
20
|
const { config, locale } = useIntor();
|
|
21
21
|
const rawPathname = usePathname$1();
|
|
22
|
-
return localizePathname(
|
|
22
|
+
return localizePathname(rawPathname, config, locale);
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
export { usePathname };
|
|
@@ -11,7 +11,7 @@ import { getLocaleFromAcceptLanguage } from '../../../routing/locale/get-locale-
|
|
|
11
11
|
*
|
|
12
12
|
* The resolved routing state is exposed via response headers.
|
|
13
13
|
*
|
|
14
|
-
* -
|
|
14
|
+
* - Acts as the canonical routing authority, guaranteeing a canonical routing result for every request.
|
|
15
15
|
*
|
|
16
16
|
* @platform Next.js
|
|
17
17
|
*/
|
|
@@ -9,10 +9,10 @@ import { localizePathname } from '../../../routing/pathname/localize-pathname.js
|
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```ts
|
|
12
|
-
* const { pathname,
|
|
13
|
-
* // pathname => "/en-US/about"
|
|
14
|
-
* // standardizedPathname => "/{locale}/about"
|
|
12
|
+
* const { pathname, unprefixedPathname, templatedPathname } = await getPathname();
|
|
13
|
+
* // pathname => "/app/en-US/about"
|
|
15
14
|
* // unprefixedPathname => "/about"
|
|
15
|
+
* // templatedPathname => "/app/{locale}/about"
|
|
16
16
|
* ```
|
|
17
17
|
* @note Requires inbound routing context; otherwise the result may be inferred.
|
|
18
18
|
* @platform Next.js
|
|
@@ -21,7 +21,7 @@ async function getPathname(config) {
|
|
|
21
21
|
const headersStore = await headers();
|
|
22
22
|
const locale = headersStore.get(INTOR_HEADERS.LOCALE) || config.defaultLocale;
|
|
23
23
|
const rawPathname = headersStore.get(INTOR_HEADERS.PATHNAME) || "/";
|
|
24
|
-
return localizePathname(
|
|
24
|
+
return localizePathname(rawPathname, config, locale);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export { getPathname };
|
|
@@ -17,6 +17,10 @@ async function getTranslator(config, params) {
|
|
|
17
17
|
plugins,
|
|
18
18
|
readers,
|
|
19
19
|
allowCacheWrite,
|
|
20
|
+
// NOTE:
|
|
21
|
+
// The runtime implementation is intentionally erased.
|
|
22
|
+
// Type safety is guaranteed by public type contracts.
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
24
|
});
|
|
21
25
|
}
|
|
22
26
|
|
|
@@ -11,7 +11,7 @@ import { getLocale } from './get-locale.js';
|
|
|
11
11
|
* Initializes Intor for the current execution context.
|
|
12
12
|
*
|
|
13
13
|
* - Automatically resolves the locale from the framework context.
|
|
14
|
-
* -
|
|
14
|
+
* - Permits cache writes during server execution.
|
|
15
15
|
* @platform Next.js
|
|
16
16
|
*/
|
|
17
17
|
async function intor(config, readers) {
|
|
@@ -32,7 +32,7 @@ const resolvePathname = (config, rawPathname, context) => {
|
|
|
32
32
|
return assertNever(localePrefix);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
const { pathname } = localizePathname(
|
|
35
|
+
const { pathname } = localizePathname(rawPathname, config, context.locale);
|
|
36
36
|
return {
|
|
37
37
|
pathname,
|
|
38
38
|
shouldRedirect: directive.type === "redirect",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { canonicalizePathname } from '../pathname/canonicalize-pathname.js';
|
|
2
2
|
import { localizePathname } from '../pathname/localize-pathname.js';
|
|
3
3
|
import { deriveHostDestination } from './utils/derive-host-destination.js';
|
|
4
4
|
import { deriveQueryDestination } from './utils/derive-query-destination.js';
|
|
@@ -23,7 +23,7 @@ function deriveTarget(config, currentLocale, currentPathname, intent) {
|
|
|
23
23
|
// ----------------------------------------------------------------
|
|
24
24
|
// Use the unprefixed logical path as the navigation base.
|
|
25
25
|
// Locale prefixes are applied later by inbound canonicalization.
|
|
26
|
-
const rawDestination = intent?.destination ??
|
|
26
|
+
const rawDestination = intent?.destination ?? canonicalizePathname(currentPathname, config);
|
|
27
27
|
const isExternal = isExternalDestination(rawDestination);
|
|
28
28
|
// ----------------------------------------------------------------
|
|
29
29
|
// Project destination by navigation carrier
|
|
@@ -32,15 +32,15 @@ function deriveTarget(config, currentLocale, currentPathname, intent) {
|
|
|
32
32
|
if (!isExternal) {
|
|
33
33
|
switch (routing.outbound.localeCarrier) {
|
|
34
34
|
case "path": {
|
|
35
|
-
destination = localizePathname(
|
|
35
|
+
destination = localizePathname(rawDestination, config, locale).pathname;
|
|
36
36
|
break;
|
|
37
37
|
}
|
|
38
38
|
case "host": {
|
|
39
|
-
destination = deriveHostDestination(
|
|
39
|
+
destination = deriveHostDestination(rawDestination, config, locale);
|
|
40
40
|
break;
|
|
41
41
|
}
|
|
42
42
|
case "query": {
|
|
43
|
-
destination = deriveQueryDestination(
|
|
43
|
+
destination = deriveQueryDestination(rawDestination, config, locale);
|
|
44
44
|
break;
|
|
45
45
|
}
|
|
46
46
|
default: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Derives a locale-specific destination using host-based navigation.
|
|
3
3
|
*/
|
|
4
|
-
const deriveHostDestination = (
|
|
4
|
+
const deriveHostDestination = (rawDestination, config, locale) => {
|
|
5
5
|
const { host } = config.routing.outbound;
|
|
6
6
|
const resolvedHost = host.map[locale] ?? host.default;
|
|
7
7
|
if (!resolvedHost)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Derives a locale-specific destination using query-based navigation.
|
|
3
3
|
*/
|
|
4
|
-
const deriveQueryDestination = (
|
|
4
|
+
const deriveQueryDestination = (rawDestination, config, locale) => {
|
|
5
5
|
const { queryKey } = config.routing.outbound;
|
|
6
6
|
const url = new URL(rawDestination, "http://internal");
|
|
7
7
|
url.searchParams.set(queryKey, locale);
|
|
@@ -10,11 +10,11 @@ import 'logry';
|
|
|
10
10
|
* // config.supportedLocales: ["en-US"]
|
|
11
11
|
* // config.routing.basePath: "/app"
|
|
12
12
|
* // config.routing.prefix: "all"
|
|
13
|
-
*
|
|
13
|
+
* canonicalizePathname("/app/en-US/about", config);
|
|
14
14
|
* // => "/about"
|
|
15
15
|
*```
|
|
16
16
|
*/
|
|
17
|
-
function
|
|
17
|
+
function canonicalizePathname(rawPathname, config) {
|
|
18
18
|
const { routing, supportedLocales } = config;
|
|
19
19
|
const { basePath } = routing;
|
|
20
20
|
// 1. Normalize pathname
|
|
@@ -38,4 +38,4 @@ function getUnprefixedPathname(config, rawPathname) {
|
|
|
38
38
|
: prefixedPathname;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export {
|
|
41
|
+
export { canonicalizePathname };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { canonicalizePathname } from './canonicalize-pathname.js';
|
|
2
|
+
import { materializePathname } from './materialize-pathname.js';
|
|
3
3
|
import { standardizePathname } from './standardize-pathname.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -11,25 +11,25 @@ import { standardizePathname } from './standardize-pathname.js';
|
|
|
11
11
|
* // config.supportedLocales: ["en-US"]
|
|
12
12
|
* // config.routing.basePath: "/app"
|
|
13
13
|
* // config.routing.prefix: "all"
|
|
14
|
-
*
|
|
14
|
+
* localizePathname(config, "/app/en-US/about", "en-US");
|
|
15
15
|
* // => {
|
|
16
|
+
* // pathname: '/app/en-US/about'
|
|
16
17
|
* // unprefixedPathname: '/about',
|
|
17
|
-
* //
|
|
18
|
-
* // localizedPathname: '/app/en-US/about'
|
|
18
|
+
* // templatedPathname: '/app/{locale}/about',
|
|
19
19
|
* // }
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
-
const localizePathname = (
|
|
23
|
-
// 1. Canonicalize:
|
|
24
|
-
const
|
|
25
|
-
// 2. Standardize:
|
|
26
|
-
const
|
|
27
|
-
// 3.
|
|
28
|
-
const
|
|
22
|
+
const localizePathname = (rawPathname, config, locale) => {
|
|
23
|
+
// 1. Canonicalize: normalize and remove routing-specific prefixes
|
|
24
|
+
const canonicalized = canonicalizePathname(rawPathname, config);
|
|
25
|
+
// 2. Standardize: convert to internal pathname shape with locale placeholder
|
|
26
|
+
const standardized = standardizePathname(canonicalized, config);
|
|
27
|
+
// 3. Materialize: apply routing rules to produce the final pathname
|
|
28
|
+
const materialized = materializePathname(standardized, config, locale);
|
|
29
29
|
return {
|
|
30
|
-
pathname,
|
|
31
|
-
unprefixedPathname,
|
|
32
|
-
|
|
30
|
+
pathname: materialized,
|
|
31
|
+
unprefixedPathname: canonicalized,
|
|
32
|
+
templatedPathname: standardized,
|
|
33
33
|
};
|
|
34
34
|
};
|
|
35
35
|
|
|
@@ -4,20 +4,21 @@ import { normalizePathname } from '../../core/utils/normalizers/normalize-pathna
|
|
|
4
4
|
import 'logry';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Materializes a standardized pathname by applying
|
|
8
|
+
* the configured locale prefix behavior.
|
|
8
9
|
*
|
|
9
10
|
* @example
|
|
10
11
|
* ```ts
|
|
11
12
|
* // config.routing.localePrefix: "all"
|
|
12
|
-
*
|
|
13
|
+
* materializePathname("/app/{locale}/about", config, "en-US");
|
|
13
14
|
* // => /app/en-US/about
|
|
14
15
|
*
|
|
15
16
|
* // config.routing.localePrefix: "none"
|
|
16
|
-
*
|
|
17
|
+
* materializePathname("/app/{locale}/about", config, "en-US");
|
|
17
18
|
* // => /app/about
|
|
18
19
|
* ```
|
|
19
20
|
*/
|
|
20
|
-
const
|
|
21
|
+
const materializePathname = (standardizedPathname, config, locale) => {
|
|
21
22
|
const { localePrefix } = config.routing;
|
|
22
23
|
if (localePrefix !== "none" && !locale) {
|
|
23
24
|
throw new Error('No locale when using localePrefix "all", "except-default"');
|
|
@@ -36,4 +37,4 @@ const localePrefixPathname = (config, standardizedPathname, locale) => {
|
|
|
36
37
|
return normalizePathname(standardizedPathname.replaceAll(`/${PREFIX_PLACEHOLDER}`, ""));
|
|
37
38
|
};
|
|
38
39
|
|
|
39
|
-
export {
|
|
40
|
+
export { materializePathname };
|