intor 2.3.33 → 2.3.34
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/src/core/utils/resolve-loader-options.js +7 -3
- package/dist/core/src/server/messages/load-messages.js +5 -5
- package/dist/express/export/express/index.js +2 -2
- package/dist/express/src/adapters/express/{middleware/create-intor-middleware.js → create-intor-handler.js} +13 -12
- package/dist/express/src/adapters/express/{helpers/get-translator.js → get-translator.js} +2 -6
- package/dist/express/src/core/utils/resolve-loader-options.js +3 -1
- package/dist/express/src/routing/inbound/resolve-inbound.js +3 -4
- package/dist/express/src/routing/inbound/resolve-locale/resolve-locale.js +6 -5
- package/dist/express/src/routing/locale/get-locale-from-query.js +1 -9
- package/dist/express/src/server/messages/load-messages.js +5 -5
- package/dist/next/export/next/index.js +4 -3
- package/dist/next/src/adapters/next/{proxy/intor-proxy.js → create-intor-handler.js} +13 -12
- package/dist/next/src/adapters/next/{navigation/link.js → link.js} +6 -6
- package/dist/next/src/adapters/next/{navigation/redirect.js → redirect.js} +4 -4
- package/dist/next/src/adapters/next/server/get-translator.js +0 -4
- package/dist/next/src/adapters/next/{navigation/use-router.js → use-router.js} +10 -10
- package/dist/next/src/client/shared/navigation/execute-navigation.js +6 -6
- package/dist/next/src/core/utils/resolve-loader-options.js +7 -3
- package/dist/next/src/policies/shoud-full-reload.js +1 -1
- package/dist/next/src/routing/inbound/resolve-inbound.js +4 -5
- package/dist/next/src/routing/inbound/resolve-locale/resolve-locale.js +6 -5
- package/dist/next/src/routing/locale/get-locale-from-query.js +1 -9
- package/dist/next/src/routing/{navigation → outbound}/decide-strategy.js +2 -5
- package/dist/{svelte-kit/src/routing/navigation/derive-target.js → next/src/routing/outbound/determine-target.js} +3 -6
- package/dist/next/src/routing/outbound/resolve-outbound.js +23 -0
- package/dist/next/src/server/messages/load-messages.js +5 -5
- package/dist/react/src/client/react/helpers/use-intor.js +3 -8
- package/dist/react/src/client/react/provider/intor-provider.js +2 -2
- package/dist/react/src/client/shared/messages/create-refetch-messages.js +1 -1
- package/dist/react/src/core/utils/resolve-loader-options.js +4 -2
- package/dist/svelte/src/client/shared/messages/create-refetch-messages.js +1 -1
- package/dist/svelte/src/core/utils/resolve-loader-options.js +4 -2
- package/dist/svelte-kit/export/svelte-kit/index.js +1 -1
- package/dist/svelte-kit/export/svelte-kit/server/index.js +1 -1
- package/dist/svelte-kit/src/adapters/svelte-kit/server/{create-intor-handle.js → create-intor-handler.js} +10 -9
- package/dist/svelte-kit/src/adapters/svelte-kit/{navigation/use-navigation.js → use-navigation.js} +6 -6
- package/dist/svelte-kit/src/client/shared/navigation/execute-navigation.js +6 -6
- package/dist/svelte-kit/src/core/utils/resolve-loader-options.js +7 -3
- package/dist/svelte-kit/src/policies/shoud-full-reload.js +1 -1
- package/dist/svelte-kit/src/routing/inbound/resolve-inbound.js +3 -4
- package/dist/svelte-kit/src/routing/inbound/resolve-locale/resolve-locale.js +6 -5
- package/dist/svelte-kit/src/routing/locale/get-locale-from-query.js +1 -9
- package/dist/svelte-kit/src/routing/{navigation → outbound}/decide-strategy.js +2 -5
- package/dist/{next/src/routing/navigation/derive-target.js → svelte-kit/src/routing/outbound/determine-target.js} +3 -6
- package/dist/svelte-kit/src/routing/outbound/resolve-outbound.js +23 -0
- package/dist/svelte-kit/src/server/messages/load-messages.js +5 -5
- package/dist/types/export/express/index.d.ts +1 -1
- package/dist/types/export/next/index.d.ts +1 -1
- package/dist/types/export/svelte-kit/index.d.ts +1 -1
- package/dist/types/export/svelte-kit/server/index.d.ts +1 -1
- package/dist/types/src/adapters/express/{middleware/create-intor-middleware.d.ts → create-intor-handler.d.ts} +3 -3
- package/dist/types/src/adapters/express/{helpers/get-translator.d.ts → get-translator.d.ts} +3 -3
- package/dist/types/src/adapters/express/global.d.ts +5 -4
- package/dist/types/src/adapters/express/index.d.ts +2 -2
- package/dist/types/src/adapters/next/{proxy/intor-proxy.d.ts → create-intor-handler.d.ts} +2 -2
- package/dist/types/src/adapters/next/{navigation/index.d.ts → index.d.ts} +1 -0
- package/dist/types/src/adapters/next/{navigation/link.d.ts → link.d.ts} +1 -1
- package/dist/types/src/adapters/next/{navigation/redirect.d.ts → redirect.d.ts} +2 -2
- package/dist/types/src/adapters/next/{navigation/use-router.d.ts → use-router.d.ts} +1 -1
- package/dist/types/src/adapters/svelte-kit/server/{create-intor-handle.d.ts → create-intor-handler.d.ts} +1 -1
- package/dist/types/src/adapters/svelte-kit/server/index.d.ts +1 -1
- package/dist/types/src/adapters/svelte-kit/server/utils/is-svelte-kit-ssg.d.ts +1 -1
- package/dist/types/src/adapters/svelte-kit/{navigation/use-navigation.d.ts → use-navigation.d.ts} +1 -1
- package/dist/types/src/client/react/helpers/use-intor.d.ts +2 -2
- package/dist/types/src/client/react/provider/intor-provider.d.ts +1 -1
- package/dist/types/src/client/shared/messages/create-refetch-messages.d.ts +2 -2
- package/dist/types/src/client/shared/navigation/execute-navigation.d.ts +9 -8
- package/dist/types/src/client/shared/utils/locale/set-document-locale.d.ts +2 -1
- package/dist/types/src/client/shared/utils/locale/set-locale-cookie.d.ts +2 -1
- package/dist/types/src/client/vue/helpers/use-intor.d.ts +1 -1
- package/dist/types/src/config/types/intor-config.d.ts +2 -2
- package/dist/types/src/config/types/loader.d.ts +3 -3
- package/dist/types/src/config/validators/validate-default-locale.d.ts +2 -1
- package/dist/types/src/core/index.d.ts +1 -1
- package/dist/types/src/core/messages/load-remote-messages/collect-remote-resources.d.ts +2 -1
- package/dist/types/src/core/messages/load-remote-messages/types.d.ts +3 -2
- package/dist/types/src/core/utils/index.d.ts +1 -1
- package/dist/types/src/core/utils/normalizers/index.d.ts +1 -1
- package/dist/types/src/core/utils/normalizers/normalize-locale.d.ts +2 -1
- package/dist/types/src/core/utils/normalizers/normalize-query.d.ts +2 -1
- package/dist/types/src/policies/should-sync-locale.d.ts +2 -1
- package/dist/types/src/routing/inbound/index.d.ts +1 -1
- package/dist/types/src/routing/inbound/resolve-inbound.d.ts +12 -7
- package/dist/types/src/routing/inbound/resolve-locale/resolve-locale.d.ts +3 -3
- package/dist/types/src/routing/inbound/resolve-locale/types.d.ts +7 -6
- package/dist/types/src/routing/inbound/resolve-pathname/types.d.ts +2 -1
- package/dist/types/src/routing/inbound/types.d.ts +4 -3
- package/dist/types/src/routing/index.d.ts +2 -2
- package/dist/types/src/routing/locale/get-locale-from-query.d.ts +2 -5
- package/dist/types/src/routing/outbound/decide-strategy.d.ts +7 -0
- package/dist/types/src/routing/outbound/determine-target.d.ts +14 -0
- package/dist/types/src/routing/outbound/index.d.ts +1 -0
- package/dist/types/src/routing/outbound/resolve-outbound.d.ts +14 -0
- package/dist/types/src/server/helpers/get-translator.d.ts +2 -2
- package/dist/types/src/server/messages/load-local-messages/read-locale-messages/types.d.ts +2 -1
- package/dist/types/src/server/messages/load-local-messages/types.d.ts +2 -1
- package/dist/types/src/server/translator/create-translator.d.ts +2 -2
- package/dist/vue/src/client/shared/messages/create-refetch-messages.js +1 -1
- package/dist/vue/src/client/vue/helpers/use-intor.js +2 -10
- package/dist/vue/src/client/vue/provider/intor-provider.js +0 -1
- package/dist/vue/src/core/utils/resolve-loader-options.js +4 -2
- package/package.json +1 -5
- package/dist/next/export/next/proxy/index.js +0 -1
- package/dist/next/src/routing/navigation/resolve-navigation.js +0 -26
- package/dist/svelte-kit/src/routing/navigation/resolve-navigation.js +0 -26
- package/dist/types/export/next/proxy/index.d.ts +0 -1
- package/dist/types/src/adapters/express/helpers/index.d.ts +0 -1
- package/dist/types/src/adapters/express/middleware/index.d.ts +0 -1
- package/dist/types/src/adapters/next/proxy/index.d.ts +0 -1
- package/dist/types/src/routing/navigation/decide-strategy.d.ts +0 -17
- package/dist/types/src/routing/navigation/derive-target.d.ts +0 -17
- package/dist/types/src/routing/navigation/index.d.ts +0 -1
- package/dist/types/src/routing/navigation/resolve-navigation.d.ts +0 -25
- /package/dist/next/src/routing/{navigation → outbound}/utils/derive-host-destination.js +0 -0
- /package/dist/next/src/routing/{navigation → outbound}/utils/derive-query-destination.js +0 -0
- /package/dist/next/src/routing/{navigation → outbound}/utils/is-external-destination.js +0 -0
- /package/dist/svelte-kit/src/routing/{navigation → outbound}/utils/derive-host-destination.js +0 -0
- /package/dist/svelte-kit/src/routing/{navigation → outbound}/utils/derive-query-destination.js +0 -0
- /package/dist/svelte-kit/src/routing/{navigation → outbound}/utils/is-external-destination.js +0 -0
- /package/dist/types/src/adapters/svelte-kit/{navigation/index.d.ts → index.d.ts} +0 -0
- /package/dist/types/src/routing/{navigation → outbound}/utils/derive-host-destination.d.ts +0 -0
- /package/dist/types/src/routing/{navigation → outbound}/utils/derive-query-destination.d.ts +0 -0
- /package/dist/types/src/routing/{navigation → outbound}/utils/is-external-destination.d.ts +0 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { decideStrategy } from './decide-strategy.js';
|
|
2
|
+
import { determineTarget } from './determine-target.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Resolve an outbound routing attempt into an executable result.
|
|
6
|
+
*/
|
|
7
|
+
function resolveOutbound(config, currentLocale, currentPathname, intent) {
|
|
8
|
+
// --------------------------------------------------
|
|
9
|
+
// Determine outbound target
|
|
10
|
+
// --------------------------------------------------
|
|
11
|
+
const target = determineTarget(config, currentLocale, currentPathname, intent);
|
|
12
|
+
// --------------------------------------------------
|
|
13
|
+
// Decide outbound strategy
|
|
14
|
+
// --------------------------------------------------
|
|
15
|
+
const strategy = decideStrategy(config, target);
|
|
16
|
+
return {
|
|
17
|
+
locale: target.locale,
|
|
18
|
+
destination: target.destination,
|
|
19
|
+
kind: strategy,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { resolveOutbound };
|
|
@@ -29,12 +29,12 @@ const loadMessages = async ({ config, locale, readers, allowCacheWrite = false,
|
|
|
29
29
|
logger.warn("No loader options have been configured in the current config.");
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
|
-
const {
|
|
32
|
+
const { mode, namespaces, concurrency } = loader;
|
|
33
33
|
const fallbackLocales = config.fallbackLocales[locale] || [];
|
|
34
34
|
logger.info(`Loading messages for locale "${locale}".`);
|
|
35
35
|
logger.trace("Starting to load messages with runtime context.", {
|
|
36
|
-
|
|
37
|
-
...(
|
|
36
|
+
loaderMode: mode,
|
|
37
|
+
...(mode === "local" ? { rootDir: loader.rootDir } : {}),
|
|
38
38
|
locale,
|
|
39
39
|
fallbackLocales: fallbackLocales.join(", "),
|
|
40
40
|
namespaces: namespaces && namespaces.length > 0 ? [...namespaces] : "*",
|
|
@@ -43,7 +43,7 @@ const loadMessages = async ({ config, locale, readers, allowCacheWrite = false,
|
|
|
43
43
|
// Dispatch to loader implementation
|
|
44
44
|
// ---------------------------------------------------------------------------
|
|
45
45
|
let loadedMessages;
|
|
46
|
-
if (
|
|
46
|
+
if (mode === "local") {
|
|
47
47
|
loadedMessages = await loadLocalMessages({
|
|
48
48
|
id: config.id,
|
|
49
49
|
locale,
|
|
@@ -56,7 +56,7 @@ const loadMessages = async ({ config, locale, readers, allowCacheWrite = false,
|
|
|
56
56
|
loggerOptions: config.logger,
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
|
-
else if (
|
|
59
|
+
else if (mode === "remote") {
|
|
60
60
|
loadedMessages = await loadRemoteMessages({
|
|
61
61
|
locale,
|
|
62
62
|
fallbackLocales,
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import '../../../core/error/intor-error.js';
|
|
3
|
-
import 'logry';
|
|
4
|
-
import 'p-limit';
|
|
5
|
-
import { mergeMessages } from '../../../core/messages/merge-messages.js';
|
|
6
|
-
import 'intor-translator';
|
|
7
2
|
import { getClientLocale } from '../../shared/helpers/get-client-locale.js';
|
|
8
3
|
|
|
9
4
|
function useIntor(config, loader) {
|
|
@@ -23,13 +18,13 @@ function useIntor(config, loader) {
|
|
|
23
18
|
const onLocaleChange = React.useCallback(async (newLocale) => {
|
|
24
19
|
activeLocaleRef.current = newLocale;
|
|
25
20
|
setIsLoading(true);
|
|
26
|
-
const loaded = await loader(newLocale);
|
|
21
|
+
const loaded = await loader(config, newLocale);
|
|
27
22
|
// Ignore outdated results when locale changes again.
|
|
28
23
|
if (activeLocaleRef.current !== newLocale)
|
|
29
24
|
return;
|
|
30
|
-
setMessages(
|
|
25
|
+
setMessages(loaded);
|
|
31
26
|
setIsLoading(false);
|
|
32
|
-
}, [
|
|
27
|
+
}, [config, loader]);
|
|
33
28
|
// ---------------------------------------------------------------------------
|
|
34
29
|
// Initial load
|
|
35
30
|
// ---------------------------------------------------------------------------
|
|
@@ -6,7 +6,7 @@ import { useLocaleEffects } from './effects/use-locale-effects.js';
|
|
|
6
6
|
import { useMessagesEffects } from './effects/use-messages-effects.js';
|
|
7
7
|
|
|
8
8
|
const IntorContext = React.createContext(undefined);
|
|
9
|
-
|
|
9
|
+
function IntorProvider({ value: { config, locale: initialLocale, messages, handlers, plugins, onLocaleChange, isLoading: externalIsLoading, }, children, }) {
|
|
10
10
|
// -----------------------------------------------------------------------------
|
|
11
11
|
// Internal state
|
|
12
12
|
// -----------------------------------------------------------------------------
|
|
@@ -58,6 +58,6 @@ const IntorProvider = ({ value: { config, locale: initialLocale, messages, handl
|
|
|
58
58
|
useLocaleEffects(config, locale);
|
|
59
59
|
useMessagesEffects(config, locale, setRuntimeMessages, setInternalIsLoading);
|
|
60
60
|
return (jsx(IntorContext.Provider, { value: { config, locale, setLocale, translator }, children: children }));
|
|
61
|
-
}
|
|
61
|
+
}
|
|
62
62
|
|
|
63
63
|
export { IntorContext, IntorProvider };
|
|
@@ -18,7 +18,7 @@ const createRefetchMessages = ({ config, onLoadingStart, onLoadingEnd, onMessage
|
|
|
18
18
|
return async function refetchMessages(newLocale) {
|
|
19
19
|
// No-op when remote loading is not enabled
|
|
20
20
|
const loader = resolveLoaderOptions(config);
|
|
21
|
-
if (!loader || loader.
|
|
21
|
+
if (!loader || loader.mode !== "remote")
|
|
22
22
|
return;
|
|
23
23
|
// Abort previous request
|
|
24
24
|
controller?.abort();
|
|
@@ -18,12 +18,14 @@
|
|
|
18
18
|
* for the given runtime.
|
|
19
19
|
*/
|
|
20
20
|
const resolveLoaderOptions = (config, runtime) => {
|
|
21
|
-
//
|
|
21
|
+
// ------------------------------------------------
|
|
22
|
+
// runtime: client
|
|
23
|
+
// ------------------------------------------------
|
|
22
24
|
{
|
|
23
25
|
const client = config.client?.loader;
|
|
24
26
|
if (client) {
|
|
25
27
|
// Client loader is always remote by design
|
|
26
|
-
return {
|
|
28
|
+
return { mode: "remote", ...client };
|
|
27
29
|
}
|
|
28
30
|
return config.server?.loader ?? config.loader;
|
|
29
31
|
}
|
|
@@ -18,7 +18,7 @@ const createRefetchMessages = ({ config, onLoadingStart, onLoadingEnd, onMessage
|
|
|
18
18
|
return async function refetchMessages(newLocale) {
|
|
19
19
|
// No-op when remote loading is not enabled
|
|
20
20
|
const loader = resolveLoaderOptions(config);
|
|
21
|
-
if (!loader || loader.
|
|
21
|
+
if (!loader || loader.mode !== "remote")
|
|
22
22
|
return;
|
|
23
23
|
// Abort previous request
|
|
24
24
|
controller?.abort();
|
|
@@ -18,12 +18,14 @@
|
|
|
18
18
|
* for the given runtime.
|
|
19
19
|
*/
|
|
20
20
|
const resolveLoaderOptions = (config, runtime) => {
|
|
21
|
-
//
|
|
21
|
+
// ------------------------------------------------
|
|
22
|
+
// runtime: client
|
|
23
|
+
// ------------------------------------------------
|
|
22
24
|
{
|
|
23
25
|
const client = config.client?.loader;
|
|
24
26
|
if (client) {
|
|
25
27
|
// Client loader is always remote by design
|
|
26
|
-
return {
|
|
28
|
+
return { mode: "remote", ...client };
|
|
27
29
|
}
|
|
28
30
|
return config.server?.loader ?? config.loader;
|
|
29
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { useNavigation } from '../../src/adapters/svelte-kit/
|
|
1
|
+
export { useNavigation } from '../../src/adapters/svelte-kit/use-navigation.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createIntorHandler } from '../../../src/adapters/svelte-kit/server/create-intor-handler.js';
|
|
2
2
|
export { intor } from '../../../src/adapters/svelte-kit/server/intor.js';
|
|
@@ -17,32 +17,33 @@ import { getLocaleFromAcceptLanguage } from '../../../routing/locale/get-locale-
|
|
|
17
17
|
*
|
|
18
18
|
* @platform SvelteKit
|
|
19
19
|
*/
|
|
20
|
-
function
|
|
20
|
+
function createIntorHandler(config) {
|
|
21
21
|
return async ({ event, resolve }) => {
|
|
22
|
+
const { host, searchParams, pathname: rawPathname } = event.url;
|
|
22
23
|
// Locale from Accept-Language header
|
|
23
24
|
const acceptLanguage = event.request.headers.get("accept-language");
|
|
24
25
|
const localeFromAcceptLanguage = getLocaleFromAcceptLanguage(acceptLanguage, config.supportedLocales);
|
|
25
26
|
// ----------------------------------------------------------
|
|
26
27
|
// Resolve inbound routing decision (pure computation)
|
|
27
28
|
// ----------------------------------------------------------
|
|
28
|
-
let
|
|
29
|
+
let inboundResult;
|
|
29
30
|
if (isSvelteKitSSG(event)) {
|
|
30
|
-
|
|
31
|
+
inboundResult = {
|
|
31
32
|
locale: event.params?.locale,
|
|
32
33
|
localeSource: "path",
|
|
33
|
-
pathname:
|
|
34
|
+
pathname: rawPathname,
|
|
34
35
|
shouldRedirect: false,
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
38
|
else {
|
|
38
|
-
|
|
39
|
-
host
|
|
40
|
-
query: normalizeQuery(Object.fromEntries(
|
|
39
|
+
inboundResult = await resolveInbound(config, rawPathname, {
|
|
40
|
+
host,
|
|
41
|
+
query: normalizeQuery(Object.fromEntries(searchParams.entries())),
|
|
41
42
|
cookie: event.cookies.get(config.cookie.name),
|
|
42
43
|
detected: localeFromAcceptLanguage || config.defaultLocale,
|
|
43
44
|
});
|
|
44
45
|
}
|
|
45
|
-
const { locale, localeSource, pathname, shouldRedirect } =
|
|
46
|
+
const { locale, localeSource, pathname, shouldRedirect } = inboundResult;
|
|
46
47
|
// ----------------------------------------------------------
|
|
47
48
|
// Redirect if needed
|
|
48
49
|
// ----------------------------------------------------------
|
|
@@ -64,4 +65,4 @@ function createIntorHandle(config) {
|
|
|
64
65
|
};
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
export {
|
|
68
|
+
export { createIntorHandler };
|
package/dist/svelte-kit/src/adapters/svelte-kit/{navigation/use-navigation.js → use-navigation.js}
RENAMED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { get } from 'svelte/store';
|
|
2
|
-
import { executeNavigation } from '
|
|
2
|
+
import { executeNavigation } from '../../client/shared/navigation/execute-navigation.js';
|
|
3
3
|
import { useIntorContext } from 'intor/svelte';
|
|
4
|
-
import '
|
|
4
|
+
import '../../core/error/intor-error.js';
|
|
5
5
|
import 'logry';
|
|
6
6
|
import 'p-limit';
|
|
7
7
|
import 'intor-translator';
|
|
8
|
-
import {
|
|
8
|
+
import { resolveOutbound } from '../../routing/outbound/resolve-outbound.js';
|
|
9
9
|
import { goto } from '$app/navigation';
|
|
10
10
|
import { page } from '$app/state';
|
|
11
11
|
|
|
@@ -21,13 +21,13 @@ function useNavigation() {
|
|
|
21
21
|
const { config, locale: currentLocale, setLocale } = useIntorContext();
|
|
22
22
|
async function goto$1(url, opts) {
|
|
23
23
|
const { locale, ...rest } = opts || {};
|
|
24
|
-
const
|
|
25
|
-
executeNavigation(
|
|
24
|
+
const outboundResult = resolveOutbound(config, get(currentLocale), page.url.pathname, { destination: url, locale });
|
|
25
|
+
executeNavigation(outboundResult, {
|
|
26
26
|
config,
|
|
27
27
|
currentLocale: get(currentLocale),
|
|
28
28
|
setLocale,
|
|
29
29
|
});
|
|
30
|
-
return goto(
|
|
30
|
+
return goto(outboundResult.destination, rest);
|
|
31
31
|
}
|
|
32
32
|
return {
|
|
33
33
|
goto: goto$1,
|
|
@@ -6,17 +6,17 @@ import { shouldSyncLocale } from '../../../policies/should-sync-locale.js';
|
|
|
6
6
|
import { setLocaleCookie } from '../utils/locale/set-locale-cookie.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* Executes a resolved
|
|
9
|
+
* Executes a resolved outbound routing result.
|
|
10
10
|
*
|
|
11
|
-
* Applies all imperative side effects required to
|
|
12
|
-
* including locale synchronization, cookie persistence, and full reloads.
|
|
11
|
+
* Applies all imperative side effects required to realize the outbound decision,
|
|
12
|
+
* including locale synchronization, cookie persistence, and full page reloads.
|
|
13
13
|
*
|
|
14
|
-
* This function must be called after `
|
|
14
|
+
* This function must be called after `resolveOutbound`.
|
|
15
15
|
*/
|
|
16
|
-
function executeNavigation(
|
|
16
|
+
function executeNavigation(outboundResult, context, e) {
|
|
17
17
|
const { config, currentLocale, setLocale } = context;
|
|
18
18
|
const { cookie } = config;
|
|
19
|
-
const { destination, kind, locale } =
|
|
19
|
+
const { destination, kind, locale } = outboundResult;
|
|
20
20
|
// ------------------------------------------------------
|
|
21
21
|
// External navigation: let browser handle it
|
|
22
22
|
// ------------------------------------------------------
|
|
@@ -18,16 +18,20 @@
|
|
|
18
18
|
* for the given runtime.
|
|
19
19
|
*/
|
|
20
20
|
const resolveLoaderOptions = (config, runtime) => {
|
|
21
|
-
//
|
|
21
|
+
// ------------------------------------------------
|
|
22
|
+
// runtime: client
|
|
23
|
+
// ------------------------------------------------
|
|
22
24
|
if (runtime === "client") {
|
|
23
25
|
const client = config.client?.loader;
|
|
24
26
|
if (client) {
|
|
25
27
|
// Client loader is always remote by design
|
|
26
|
-
return {
|
|
28
|
+
return { mode: "remote", ...client };
|
|
27
29
|
}
|
|
28
30
|
return config.server?.loader ?? config.loader;
|
|
29
31
|
}
|
|
30
|
-
//
|
|
32
|
+
// ------------------------------------------------
|
|
33
|
+
// runtime: server
|
|
34
|
+
// ------------------------------------------------
|
|
31
35
|
return config.server?.loader ?? config.loader;
|
|
32
36
|
};
|
|
33
37
|
|
|
@@ -9,7 +9,7 @@ import 'intor-translator';
|
|
|
9
9
|
*/
|
|
10
10
|
function shouldFullReload(config) {
|
|
11
11
|
const loader = resolveLoaderOptions(config, "client");
|
|
12
|
-
return (loader?.
|
|
12
|
+
return (loader?.mode === "local" || config.routing.outbound.forceFullReload === true);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export { shouldFullReload };
|
|
@@ -13,7 +13,8 @@ import { resolvePathname } from './resolve-pathname/resolve-pathname.js';
|
|
|
13
13
|
*
|
|
14
14
|
* No side effects. No navigation.
|
|
15
15
|
*/
|
|
16
|
-
async function resolveInbound(config, rawPathname,
|
|
16
|
+
async function resolveInbound(config, rawPathname, localeInputs, options) {
|
|
17
|
+
const { queryKey } = config.routing.inbound;
|
|
17
18
|
const { host, query, cookie, detected } = localeInputs;
|
|
18
19
|
// ------------------------------------------------------
|
|
19
20
|
// Resolve locale from inbound inputs
|
|
@@ -22,9 +23,7 @@ async function resolveInbound(config, rawPathname, hasRedirected, localeInputs)
|
|
|
22
23
|
const { locale, localeSource } = resolveLocale(config, {
|
|
23
24
|
path: { locale: pathLocale },
|
|
24
25
|
host: { locale: getLocaleFromHost(host) },
|
|
25
|
-
query: {
|
|
26
|
-
locale: getLocaleFromQuery(query, config.routing.inbound.queryKey),
|
|
27
|
-
},
|
|
26
|
+
query: { locale: getLocaleFromQuery(query, queryKey) },
|
|
28
27
|
cookie: { locale: cookie },
|
|
29
28
|
detected: { locale: detected },
|
|
30
29
|
});
|
|
@@ -7,9 +7,9 @@ import 'intor-translator';
|
|
|
7
7
|
/**
|
|
8
8
|
* Resolve the active locale from inbound routing configuration.
|
|
9
9
|
*
|
|
10
|
-
* Iterates through configured locale sources and returns the first
|
|
11
|
-
*
|
|
12
|
-
* or the default locale if none match.
|
|
10
|
+
* Iterates through configured locale sources and returns the first normalized, supported locale.
|
|
11
|
+
*
|
|
12
|
+
* Falls back to the detected locale or the default locale if none match.
|
|
13
13
|
*/
|
|
14
14
|
function resolveLocale(config, context) {
|
|
15
15
|
const { localeSources } = config.routing.inbound;
|
|
@@ -24,9 +24,10 @@ function resolveLocale(config, context) {
|
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
// Fallback: detected is always available
|
|
27
|
+
const fallback = normalizeLocale(context.detected.locale, config.supportedLocales) ||
|
|
28
|
+
config.defaultLocale;
|
|
27
29
|
return {
|
|
28
|
-
locale:
|
|
29
|
-
config.defaultLocale,
|
|
30
|
+
locale: fallback,
|
|
30
31
|
localeSource: "detected",
|
|
31
32
|
};
|
|
32
33
|
}
|
|
@@ -11,19 +11,11 @@
|
|
|
11
11
|
*
|
|
12
12
|
* getLocaleFromQuery({}, "locale")
|
|
13
13
|
* // => undefined
|
|
14
|
-
*
|
|
15
|
-
* getLocaleFromQuery({ locale: ["zh-TW"] }, "locale")
|
|
16
|
-
* // => "zh-TW"
|
|
17
|
-
* ```
|
|
18
14
|
*/
|
|
19
15
|
function getLocaleFromQuery(query, queryKey) {
|
|
20
16
|
if (!query)
|
|
21
17
|
return;
|
|
22
|
-
|
|
23
|
-
if (!raw)
|
|
24
|
-
return;
|
|
25
|
-
const value = Array.isArray(raw) ? raw[0] : raw;
|
|
26
|
-
return value;
|
|
18
|
+
return query[queryKey];
|
|
27
19
|
}
|
|
28
20
|
|
|
29
21
|
export { getLocaleFromQuery };
|
|
@@ -2,16 +2,13 @@ import { shouldFullReload } from '../../policies/shoud-full-reload.js';
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Decide how a resolved navigation target should be executed.
|
|
5
|
-
*
|
|
6
|
-
* This function determines whether navigation should be handled
|
|
7
|
-
* by the browser, performed client-side, or forced to reload.
|
|
8
5
|
*/
|
|
9
6
|
function decideStrategy(config, target) {
|
|
10
7
|
// External destinations are always handled by the browser
|
|
11
8
|
if (target.isExternal) {
|
|
12
|
-
return
|
|
9
|
+
return "external";
|
|
13
10
|
}
|
|
14
|
-
return shouldFullReload(config) ?
|
|
11
|
+
return shouldFullReload(config) ? "reload" : "client";
|
|
15
12
|
}
|
|
16
13
|
|
|
17
14
|
export { decideStrategy };
|
|
@@ -5,12 +5,9 @@ import { deriveQueryDestination } from './utils/derive-query-destination.js';
|
|
|
5
5
|
import { isExternalDestination } from './utils/is-external-destination.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* This function computes the final destination URL and execution flags
|
|
11
|
-
* based on the current routing configuration and locale context.
|
|
8
|
+
* Determines the outbound routing target.
|
|
12
9
|
*/
|
|
13
|
-
function
|
|
10
|
+
function determineTarget(config, currentLocale, currentPathname, intent) {
|
|
14
11
|
const { supportedLocales, routing } = config;
|
|
15
12
|
// ----------------------------------------------------------------
|
|
16
13
|
// Resolve effective locale
|
|
@@ -55,4 +52,4 @@ function deriveTarget(config, currentLocale, currentPathname, intent) {
|
|
|
55
52
|
};
|
|
56
53
|
}
|
|
57
54
|
|
|
58
|
-
export {
|
|
55
|
+
export { determineTarget };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { decideStrategy } from './decide-strategy.js';
|
|
2
|
+
import { determineTarget } from './determine-target.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Resolve an outbound routing attempt into an executable result.
|
|
6
|
+
*/
|
|
7
|
+
function resolveOutbound(config, currentLocale, currentPathname, intent) {
|
|
8
|
+
// --------------------------------------------------
|
|
9
|
+
// Determine outbound target
|
|
10
|
+
// --------------------------------------------------
|
|
11
|
+
const target = determineTarget(config, currentLocale, currentPathname, intent);
|
|
12
|
+
// --------------------------------------------------
|
|
13
|
+
// Decide outbound strategy
|
|
14
|
+
// --------------------------------------------------
|
|
15
|
+
const strategy = decideStrategy(config, target);
|
|
16
|
+
return {
|
|
17
|
+
locale: target.locale,
|
|
18
|
+
destination: target.destination,
|
|
19
|
+
kind: strategy,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { resolveOutbound };
|
|
@@ -29,12 +29,12 @@ const loadMessages = async ({ config, locale, readers, allowCacheWrite = false,
|
|
|
29
29
|
logger.warn("No loader options have been configured in the current config.");
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
|
-
const {
|
|
32
|
+
const { mode, namespaces, concurrency } = loader;
|
|
33
33
|
const fallbackLocales = config.fallbackLocales[locale] || [];
|
|
34
34
|
logger.info(`Loading messages for locale "${locale}".`);
|
|
35
35
|
logger.trace("Starting to load messages with runtime context.", {
|
|
36
|
-
|
|
37
|
-
...(
|
|
36
|
+
loaderMode: mode,
|
|
37
|
+
...(mode === "local" ? { rootDir: loader.rootDir } : {}),
|
|
38
38
|
locale,
|
|
39
39
|
fallbackLocales: fallbackLocales.join(", "),
|
|
40
40
|
namespaces: namespaces && namespaces.length > 0 ? [...namespaces] : "*",
|
|
@@ -43,7 +43,7 @@ const loadMessages = async ({ config, locale, readers, allowCacheWrite = false,
|
|
|
43
43
|
// Dispatch to loader implementation
|
|
44
44
|
// ---------------------------------------------------------------------------
|
|
45
45
|
let loadedMessages;
|
|
46
|
-
if (
|
|
46
|
+
if (mode === "local") {
|
|
47
47
|
loadedMessages = await loadLocalMessages({
|
|
48
48
|
id: config.id,
|
|
49
49
|
locale,
|
|
@@ -56,7 +56,7 @@ const loadMessages = async ({ config, locale, readers, allowCacheWrite = false,
|
|
|
56
56
|
loggerOptions: config.logger,
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
|
-
else if (
|
|
59
|
+
else if (mode === "remote") {
|
|
60
60
|
loadedMessages = await loadRemoteMessages({
|
|
61
61
|
locale,
|
|
62
62
|
fallbackLocales,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createIntorHandler, getTranslator } from "../../src/adapters/express";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Link, useRouter, redirect } from "../../src/adapters/next
|
|
1
|
+
export { Link, useRouter, redirect, createIntorHandler } from "../../src/adapters/next";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { useNavigation } from "../../src/adapters/svelte-kit
|
|
1
|
+
export { useNavigation } from "../../src/adapters/svelte-kit";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createIntorHandler, intor } from "../../../src/adapters/svelte-kit/server";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { IntorResolvedConfig } from "
|
|
1
|
+
import type { IntorResolvedConfig } from "../../config";
|
|
2
2
|
import type { Request, Response, NextFunction } from "express";
|
|
3
|
-
import { type GetTranslatorParams } from "
|
|
3
|
+
import { type GetTranslatorParams } from "../../server";
|
|
4
4
|
/**
|
|
5
5
|
* Resolves locale-aware routing for the current execution context.
|
|
6
6
|
*
|
|
@@ -11,4 +11,4 @@ import { type GetTranslatorParams } from "../../../server";
|
|
|
11
11
|
*
|
|
12
12
|
* @platform Express
|
|
13
13
|
*/
|
|
14
|
-
export declare function
|
|
14
|
+
export declare function createIntorHandler(config: IntorResolvedConfig, options?: Omit<GetTranslatorParams, "locale">): (req: Request, _res: Response, next: NextFunction) => Promise<void>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { IntorResolvedConfig } from "
|
|
2
|
-
import type { GenConfigKeys, GenMessages, GenReplacements } from "
|
|
3
|
-
import type { GetTranslatorParams, TranslatorInstanceServer } from "
|
|
1
|
+
import type { IntorResolvedConfig } from "../../config";
|
|
2
|
+
import type { GenConfigKeys, GenMessages, GenReplacements } from "../../core";
|
|
3
|
+
import type { GetTranslatorParams, TranslatorInstanceServer } from "../../server";
|
|
4
4
|
import type { Request } from "express";
|
|
5
5
|
import type { LocalizedPreKey } from "intor-translator";
|
|
6
6
|
type GetTranslatorExpressParams = Omit<GetTranslatorParams, "locale">;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { TranslatorInstance } from "../../core";
|
|
2
1
|
import type { InboundContext } from "../../routing";
|
|
3
|
-
import type {
|
|
2
|
+
import type { TranslatorInstanceServer } from "../../server";
|
|
3
|
+
import type { Locale, LocaleMessages } from "intor-translator";
|
|
4
4
|
/**
|
|
5
5
|
* Global type augmentations for Express request
|
|
6
6
|
*/
|
|
@@ -9,8 +9,9 @@ declare global {
|
|
|
9
9
|
interface Request {
|
|
10
10
|
intor: InboundContext;
|
|
11
11
|
locale: Locale;
|
|
12
|
-
hasKey:
|
|
13
|
-
t:
|
|
12
|
+
hasKey: TranslatorInstanceServer<LocaleMessages>["hasKey"];
|
|
13
|
+
t: TranslatorInstanceServer<LocaleMessages>["t"];
|
|
14
|
+
tRich: TranslatorInstanceServer<LocaleMessages>["tRich"];
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { getTranslator } from "./
|
|
1
|
+
export { createIntorHandler } from "./create-intor-handler";
|
|
2
|
+
export { getTranslator } from "./get-translator";
|
|
3
3
|
export * from "./global";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IntorResolvedConfig } from "
|
|
1
|
+
import type { IntorResolvedConfig } from "../../config";
|
|
2
2
|
import type { NextRequest } from "next/server";
|
|
3
3
|
/**
|
|
4
4
|
* Resolves locale-aware routing for the current execution context.
|
|
@@ -9,4 +9,4 @@ import type { NextRequest } from "next/server";
|
|
|
9
9
|
*
|
|
10
10
|
* @platform Next.js
|
|
11
11
|
*/
|
|
12
|
-
export declare const
|
|
12
|
+
export declare const createIntorHandler: (config: IntorResolvedConfig, request: NextRequest) => Promise<Response>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GenConfigKeys, GenLocale } from "
|
|
1
|
+
import type { GenConfigKeys, GenLocale } from "../../core";
|
|
2
2
|
import type { Url } from "next/dist/shared/lib/router/router";
|
|
3
3
|
import type { LinkProps as NextLinkProps } from "next/link";
|
|
4
4
|
import * as React from "react";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { IntorResolvedConfig } from "
|
|
2
|
-
import type { GenConfigKeys, GenLocale } from "
|
|
1
|
+
import type { IntorResolvedConfig } from "../../config";
|
|
2
|
+
import type { GenConfigKeys, GenLocale } from "../../core";
|
|
3
3
|
import type { RedirectType } from "next/navigation";
|
|
4
4
|
/**
|
|
5
5
|
* Redirect to a locale-aware destination for the current execution context.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GenConfigKeys, GenLocale } from "
|
|
1
|
+
import type { GenConfigKeys, GenLocale } from "../../core";
|
|
2
2
|
import type { NavigateOptions, PrefetchOptions } from "next/dist/shared/lib/app-router-context.shared-runtime";
|
|
3
3
|
/**
|
|
4
4
|
* Locale-aware router hook for the current execution context.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createIntorHandler } from "./create-intor-handler";
|
|
2
2
|
export { intor } from "./intor";
|
|
@@ -5,4 +5,4 @@ import type { RequestEvent } from "@sveltejs/kit";
|
|
|
5
5
|
* This is NOT a guaranteed signal.
|
|
6
6
|
* It intentionally prefers false positives over false negatives.
|
|
7
7
|
*/
|
|
8
|
-
export declare function isSvelteKitSSG(event: RequestEvent
|
|
8
|
+
export declare function isSvelteKitSSG(event: RequestEvent): boolean;
|