@bleedingdev/modern-js-plugin-i18n 3.5.0-ultramodern.6 → 3.5.0-ultramodern.75
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/cjs/cli/index.js +2 -1
- package/dist/cjs/cli/locales.js +15 -15
- package/dist/cjs/runtime/Link.js +8 -89
- package/dist/cjs/runtime/context.js +78 -91
- package/dist/cjs/runtime/contextHelpers.js +143 -0
- package/dist/cjs/runtime/core.js +32 -132
- package/dist/cjs/runtime/hooks.js +54 -21
- package/dist/cjs/runtime/i18n/backend/defaults.node.js +7 -7
- package/dist/cjs/runtime/i18n/detection/cache.js +150 -0
- package/dist/cjs/runtime/i18n/detection/detector.js +100 -0
- package/dist/cjs/runtime/i18n/detection/index.js +8 -263
- package/dist/cjs/runtime/i18n/detection/initOptions.js +69 -0
- package/dist/cjs/runtime/i18n/detection/language.js +62 -0
- package/dist/cjs/runtime/i18n/detection/path.js +49 -0
- package/dist/cjs/runtime/i18n/detection/priority.js +66 -0
- package/dist/cjs/runtime/i18n/detection/ssr.js +70 -0
- package/dist/cjs/runtime/i18n/detection/types.js +18 -0
- package/dist/cjs/runtime/i18n/instance.js +34 -10
- package/dist/cjs/runtime/linkHelpers.js +148 -0
- package/dist/cjs/runtime/pluginSetup.js +102 -0
- package/dist/cjs/runtime/providerComposition.js +115 -0
- package/dist/cjs/runtime/reactI18next.js +43 -0
- package/dist/cjs/runtime/routerAdapter.js +16 -8
- package/dist/cjs/runtime/utils.js +1 -9
- package/dist/cjs/server/apiPrefix.js +72 -0
- package/dist/cjs/server/detectorOptions.js +97 -0
- package/dist/cjs/server/index.js +17 -144
- package/dist/cjs/server/redirectPolicy.js +96 -0
- package/dist/cjs/shared/detection.js +2 -104
- package/dist/cjs/shared/localisedUrls/config.js +49 -0
- package/dist/cjs/shared/localisedUrls/index.js +91 -0
- package/dist/cjs/shared/localisedUrls/normalise.js +87 -0
- package/dist/cjs/shared/localisedUrls/pathname.js +68 -0
- package/dist/cjs/shared/localisedUrls/patterns.js +130 -0
- package/dist/cjs/shared/localisedUrls/redirect.js +103 -0
- package/dist/cjs/shared/localisedUrls/resolve.js +88 -0
- package/dist/cjs/shared/localisedUrls/routes.js +130 -0
- package/dist/cjs/shared/localisedUrls/types.js +18 -0
- package/dist/cjs/shared/localisedUrls.js +28 -294
- package/dist/cjs/shared/utils.js +2 -8
- package/dist/esm/cli/index.mjs +2 -1
- package/dist/esm/cli/locales.mjs +13 -13
- package/dist/esm/runtime/Link.mjs +1 -82
- package/dist/esm/runtime/context.mjs +76 -92
- package/dist/esm/runtime/contextHelpers.mjs +87 -0
- package/dist/esm/runtime/core.mjs +30 -133
- package/dist/esm/runtime/hooks.mjs +56 -23
- package/dist/esm/runtime/i18n/backend/defaults.node.mjs +5 -5
- package/dist/esm/runtime/i18n/detection/cache.mjs +103 -0
- package/dist/esm/runtime/i18n/detection/detector.mjs +62 -0
- package/dist/esm/runtime/i18n/detection/index.mjs +4 -260
- package/dist/esm/runtime/i18n/detection/initOptions.mjs +28 -0
- package/dist/esm/runtime/i18n/detection/language.mjs +21 -0
- package/dist/esm/runtime/i18n/detection/path.mjs +11 -0
- package/dist/esm/runtime/i18n/detection/priority.mjs +28 -0
- package/dist/esm/runtime/i18n/detection/ssr.mjs +26 -0
- package/dist/esm/runtime/i18n/detection/types.mjs +0 -0
- package/dist/esm/runtime/i18n/instance.mjs +35 -8
- package/dist/esm/runtime/linkHelpers.mjs +98 -0
- package/dist/esm/runtime/pluginSetup.mjs +64 -0
- package/dist/esm/runtime/providerComposition.mjs +77 -0
- package/dist/esm/runtime/reactI18next.mjs +5 -0
- package/dist/esm/runtime/routerAdapter.mjs +16 -8
- package/dist/esm/runtime/utils.mjs +2 -10
- package/dist/esm/server/apiPrefix.mjs +31 -0
- package/dist/esm/server/detectorOptions.mjs +59 -0
- package/dist/esm/server/index.mjs +8 -135
- package/dist/esm/server/redirectPolicy.mjs +46 -0
- package/dist/esm/shared/detection.mjs +1 -71
- package/dist/esm/shared/localisedUrls/config.mjs +11 -0
- package/dist/esm/shared/localisedUrls/index.mjs +7 -0
- package/dist/esm/shared/localisedUrls/normalise.mjs +37 -0
- package/dist/esm/shared/localisedUrls/pathname.mjs +24 -0
- package/dist/esm/shared/localisedUrls/patterns.mjs +86 -0
- package/dist/esm/shared/localisedUrls/redirect.mjs +56 -0
- package/dist/esm/shared/localisedUrls/resolve.mjs +47 -0
- package/dist/esm/shared/localisedUrls/routes.mjs +89 -0
- package/dist/esm/shared/localisedUrls/types.mjs +0 -0
- package/dist/esm/shared/localisedUrls.mjs +1 -283
- package/dist/esm/shared/utils.mjs +1 -1
- package/dist/esm-node/cli/index.mjs +2 -1
- package/dist/esm-node/cli/locales.mjs +13 -13
- package/dist/esm-node/runtime/Link.mjs +1 -82
- package/dist/esm-node/runtime/context.mjs +76 -92
- package/dist/esm-node/runtime/contextHelpers.mjs +88 -0
- package/dist/esm-node/runtime/core.mjs +30 -133
- package/dist/esm-node/runtime/hooks.mjs +56 -23
- package/dist/esm-node/runtime/i18n/backend/defaults.node.mjs +5 -5
- package/dist/esm-node/runtime/i18n/detection/cache.mjs +104 -0
- package/dist/esm-node/runtime/i18n/detection/detector.mjs +63 -0
- package/dist/esm-node/runtime/i18n/detection/index.mjs +4 -260
- package/dist/esm-node/runtime/i18n/detection/initOptions.mjs +29 -0
- package/dist/esm-node/runtime/i18n/detection/language.mjs +22 -0
- package/dist/esm-node/runtime/i18n/detection/path.mjs +12 -0
- package/dist/esm-node/runtime/i18n/detection/priority.mjs +29 -0
- package/dist/esm-node/runtime/i18n/detection/ssr.mjs +27 -0
- package/dist/esm-node/runtime/i18n/detection/types.mjs +1 -0
- package/dist/esm-node/runtime/i18n/instance.mjs +35 -8
- package/dist/esm-node/runtime/linkHelpers.mjs +99 -0
- package/dist/esm-node/runtime/pluginSetup.mjs +65 -0
- package/dist/esm-node/runtime/providerComposition.mjs +78 -0
- package/dist/esm-node/runtime/reactI18next.mjs +6 -0
- package/dist/esm-node/runtime/routerAdapter.mjs +16 -8
- package/dist/esm-node/runtime/utils.mjs +2 -10
- package/dist/esm-node/server/apiPrefix.mjs +32 -0
- package/dist/esm-node/server/detectorOptions.mjs +60 -0
- package/dist/esm-node/server/index.mjs +8 -135
- package/dist/esm-node/server/redirectPolicy.mjs +47 -0
- package/dist/esm-node/shared/detection.mjs +1 -71
- package/dist/esm-node/shared/localisedUrls/config.mjs +12 -0
- package/dist/esm-node/shared/localisedUrls/index.mjs +8 -0
- package/dist/esm-node/shared/localisedUrls/normalise.mjs +38 -0
- package/dist/esm-node/shared/localisedUrls/pathname.mjs +25 -0
- package/dist/esm-node/shared/localisedUrls/patterns.mjs +87 -0
- package/dist/esm-node/shared/localisedUrls/redirect.mjs +57 -0
- package/dist/esm-node/shared/localisedUrls/resolve.mjs +48 -0
- package/dist/esm-node/shared/localisedUrls/routes.mjs +90 -0
- package/dist/esm-node/shared/localisedUrls/types.mjs +1 -0
- package/dist/esm-node/shared/localisedUrls.mjs +1 -283
- package/dist/esm-node/shared/utils.mjs +1 -1
- package/dist/types/cli/locales.d.ts +1 -1
- package/dist/types/runtime/Link.d.ts +3 -7
- package/dist/types/runtime/context.d.ts +21 -5
- package/dist/types/runtime/contextHelpers.d.ts +29 -0
- package/dist/types/runtime/core.d.ts +4 -8
- package/dist/types/runtime/hooks.d.ts +3 -7
- package/dist/types/runtime/i18n/backend/middleware.common.d.ts +2 -1
- package/dist/types/runtime/i18n/detection/cache.d.ts +14 -0
- package/dist/types/runtime/i18n/detection/detector.d.ts +8 -0
- package/dist/types/runtime/i18n/detection/index.d.ts +5 -50
- package/dist/types/runtime/i18n/detection/initOptions.d.ts +10 -0
- package/dist/types/runtime/i18n/detection/language.d.ts +11 -0
- package/dist/types/runtime/i18n/detection/middleware.d.ts +4 -4
- package/dist/types/runtime/i18n/detection/middleware.node.d.ts +4 -4
- package/dist/types/runtime/i18n/detection/path.d.ts +5 -0
- package/dist/types/runtime/i18n/detection/priority.d.ts +10 -0
- package/dist/types/runtime/i18n/detection/ssr.d.ts +9 -0
- package/dist/types/runtime/i18n/detection/types.d.ts +32 -0
- package/dist/types/runtime/i18n/instance.d.ts +31 -27
- package/dist/types/runtime/i18n/react-i18next.d.ts +1 -6
- package/dist/types/runtime/i18n/utils.d.ts +14 -5
- package/dist/types/runtime/linkHelpers.d.ts +17 -0
- package/dist/types/runtime/pluginSetup.d.ts +32 -0
- package/dist/types/runtime/providerComposition.d.ts +16 -0
- package/dist/types/runtime/reactI18next.d.ts +7 -0
- package/dist/types/runtime/routerAdapter.d.ts +7 -6
- package/dist/types/runtime/utils.d.ts +7 -2
- package/dist/types/server/apiPrefix.d.ts +7 -0
- package/dist/types/server/detectorOptions.d.ts +21 -0
- package/dist/types/server/index.d.ts +1 -6
- package/dist/types/server/redirectPolicy.d.ts +22 -0
- package/dist/types/shared/detection.d.ts +1 -11
- package/dist/types/shared/localisedUrls/config.d.ts +9 -0
- package/dist/types/shared/localisedUrls/index.d.ts +9 -0
- package/dist/types/shared/localisedUrls/normalise.d.ts +10 -0
- package/dist/types/shared/localisedUrls/pathname.d.ts +4 -0
- package/dist/types/shared/localisedUrls/patterns.d.ts +5 -0
- package/dist/types/shared/localisedUrls/redirect.d.ts +11 -0
- package/dist/types/shared/localisedUrls/resolve.d.ts +7 -0
- package/dist/types/shared/localisedUrls/routes.d.ts +3 -0
- package/dist/types/shared/localisedUrls/types.d.ts +14 -0
- package/dist/types/shared/localisedUrls.d.ts +2 -36
- package/dist/types/shared/utils.d.ts +0 -2
- package/package.json +17 -20
- package/rstest.config.mts +8 -1
- package/src/cli/index.ts +5 -4
- package/src/cli/locales.ts +3 -3
- package/src/runtime/Link.tsx +11 -138
- package/src/runtime/context.tsx +170 -207
- package/src/runtime/contextHelpers.ts +242 -0
- package/src/runtime/core.tsx +48 -275
- package/src/runtime/hooks.ts +86 -24
- package/src/runtime/i18n/backend/defaults.node.ts +2 -2
- package/src/runtime/i18n/backend/middleware.common.ts +5 -4
- package/src/runtime/i18n/detection/cache.ts +189 -0
- package/src/runtime/i18n/detection/detector.ts +166 -0
- package/src/runtime/i18n/detection/index.ts +10 -641
- package/src/runtime/i18n/detection/initOptions.ts +74 -0
- package/src/runtime/i18n/detection/language.ts +64 -0
- package/src/runtime/i18n/detection/middleware.node.ts +26 -7
- package/src/runtime/i18n/detection/middleware.ts +15 -7
- package/src/runtime/i18n/detection/path.ts +41 -0
- package/src/runtime/i18n/detection/priority.ts +82 -0
- package/src/runtime/i18n/detection/ssr.ts +47 -0
- package/src/runtime/i18n/detection/types.ts +41 -0
- package/src/runtime/i18n/instance.ts +98 -34
- package/src/runtime/i18n/react-i18next.ts +1 -6
- package/src/runtime/i18n/utils.ts +18 -9
- package/src/runtime/linkHelpers.ts +174 -0
- package/src/runtime/pluginSetup.ts +189 -0
- package/src/runtime/providerComposition.tsx +148 -0
- package/src/runtime/reactI18next.ts +20 -0
- package/src/runtime/routerAdapter.tsx +36 -15
- package/src/runtime/utils.ts +13 -35
- package/src/server/apiPrefix.ts +67 -0
- package/src/server/detectorOptions.ts +105 -0
- package/src/server/index.ts +14 -319
- package/src/server/redirectPolicy.ts +127 -0
- package/src/shared/detection.ts +1 -1
- package/src/shared/localisedUrls/config.ts +18 -0
- package/src/shared/localisedUrls/index.ts +24 -0
- package/src/shared/localisedUrls/normalise.ts +67 -0
- package/src/shared/localisedUrls/pathname.ts +60 -0
- package/src/shared/localisedUrls/patterns.ts +160 -0
- package/src/shared/localisedUrls/redirect.ts +93 -0
- package/src/shared/localisedUrls/resolve.ts +135 -0
- package/src/shared/localisedUrls/routes.ts +234 -0
- package/src/shared/localisedUrls/types.ts +18 -0
- package/src/shared/localisedUrls.ts +26 -623
- package/src/shared/utils.ts +2 -2
- package/tests/federatedI18nBoundary.client.test.tsx +112 -0
- package/tests/federatedI18nBoundary.test.tsx +120 -0
- package/tests/fixtures/localised-routes.golden.json +156 -0
- package/tests/link.test.tsx +111 -0
- package/tests/localisedUrlRewriteMatrix.fork.test.ts +147 -0
- package/tests/localisedUrls.test.ts +148 -2
- package/tests/reactI18nextRuntimeBoundary.test.ts +6 -3
- package/tests/redirectPolicy.test.ts +45 -0
- package/tests/routerAdapter.test.tsx +603 -0
- package/tests/type-fixture/fixture-globals.d.ts +11 -0
- package/tests/type-fixture/tsconfig.json +1 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { LocalisedUrlsOption } from '../shared/localisedUrls';
|
|
2
|
+
import type { I18nInstance } from './i18n';
|
|
3
|
+
type Navigate = (url: string, options?: {
|
|
4
|
+
replace?: boolean;
|
|
5
|
+
}) => Promise<void> | void;
|
|
6
|
+
type LocationLike = {
|
|
7
|
+
pathname: string;
|
|
8
|
+
search: string;
|
|
9
|
+
hash: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function getPathLanguage(pathname: string | undefined, languages: string[] | undefined, localePathRedirect: boolean | undefined): string | undefined;
|
|
12
|
+
export declare function cacheI18nLanguage(i18nInstance: I18nInstance, language: string): void;
|
|
13
|
+
export declare function changeI18nInstanceLanguage(i18nInstance: I18nInstance, language: string): Promise<void>;
|
|
14
|
+
interface ChangeModernI18nLanguageOptions {
|
|
15
|
+
i18nInstance: I18nInstance;
|
|
16
|
+
updateLanguage?: (newLang: string) => void;
|
|
17
|
+
localePathRedirect?: boolean;
|
|
18
|
+
ignoreRedirectRoutes?: string[] | ((pathname: string) => boolean);
|
|
19
|
+
localisedUrls?: LocalisedUrlsOption;
|
|
20
|
+
languages?: string[];
|
|
21
|
+
hasRouter: boolean;
|
|
22
|
+
navigate?: Navigate | null;
|
|
23
|
+
location?: LocationLike | null;
|
|
24
|
+
}
|
|
25
|
+
export declare function changeModernI18nLanguage(newLang: string, options: ChangeModernI18nLanguageOptions): Promise<void>;
|
|
26
|
+
export declare function translateI18n(i18nInstance: I18nInstance, key: string | string[], ...args: unknown[]): string;
|
|
27
|
+
export declare function isI18nLanguageSupported(languages: string[] | undefined, lang: string): boolean;
|
|
28
|
+
export declare function isI18nResourcesReady(i18nInstance: I18nInstance, currentLanguage: string): boolean;
|
|
29
|
+
export {};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type React from 'react';
|
|
1
|
+
import type { RuntimePlugin } from '@modern-js/runtime';
|
|
3
2
|
import type { BaseBackendOptions, BaseLocaleDetectionOptions } from '../shared/type';
|
|
4
3
|
import type { I18nInitOptions, I18nInstance } from './i18n';
|
|
4
|
+
import { type LoadReactI18nextIntegration } from './reactI18next';
|
|
5
5
|
import './types';
|
|
6
6
|
export type { I18nSdkLoader, I18nSdkLoadOptions } from '../shared/type';
|
|
7
7
|
export type { Resources } from './i18n/instance';
|
|
8
|
+
export type { LoadReactI18nextIntegration, ReactI18nextIntegration, } from './reactI18next';
|
|
8
9
|
export interface I18nPluginOptions {
|
|
9
10
|
entryName?: string;
|
|
10
11
|
localeDetection?: BaseLocaleDetectionOptions;
|
|
@@ -16,14 +17,9 @@ export interface I18nPluginOptions {
|
|
|
16
17
|
reactI18next?: boolean;
|
|
17
18
|
[key: string]: any;
|
|
18
19
|
}
|
|
19
|
-
export interface ReactI18nextIntegration {
|
|
20
|
-
I18nextProvider: React.ComponentType<any> | null;
|
|
21
|
-
initReactI18next: any | null;
|
|
22
|
-
}
|
|
23
|
-
export type LoadReactI18nextIntegration = () => Promise<ReactI18nextIntegration | null>;
|
|
24
20
|
export declare const createI18nPlugin: (loadReactI18nextIntegration?: LoadReactI18nextIntegration) => ((options: I18nPluginOptions) => RuntimePlugin);
|
|
25
21
|
export type { AllowedLinkTarget, CanonicalRoutePath, UltramodernCanonicalRoutes, } from './canonicalRoutes';
|
|
26
|
-
export { useModernI18n } from './context';
|
|
22
|
+
export { FederatedI18nBoundary, type FederatedI18nBoundaryProps, useModernI18n, } from './context';
|
|
27
23
|
export { I18nLink, type I18nLinkProps } from './I18nLink';
|
|
28
24
|
export { Link, type LinkActiveOptions, type LinkBaseProps, type LinkParams, type LinkProps, } from './Link';
|
|
29
25
|
export { canonicalPath, type LocalizedPathsConfig, localizePath, type UseLocalizedLocationReturn, type UseLocalizedPathsReturn, useLocalizedLocation, useLocalizedPaths, } from './localizedPaths';
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import type { TRuntimeContext } from '@modern-js/runtime';
|
|
2
1
|
import type React from 'react';
|
|
3
2
|
import type { LocalisedUrlsOption } from '../shared/localisedUrls';
|
|
4
3
|
import type { I18nInstance } from './i18n';
|
|
5
|
-
|
|
6
|
-
i18nInstance?: I18nInstance;
|
|
7
|
-
}
|
|
8
|
-
export declare function createContextValue(lang: string, i18nInstance: I18nInstance | undefined, entryName: string | undefined, languages: string[], localePathRedirect: boolean, ignoreRedirectRoutes: string[] | ((pathname: string) => boolean) | undefined, localisedUrls: LocalisedUrlsOption | undefined, setLang: (lang: string) => void): {
|
|
4
|
+
export declare function createContextValue(lang: string, i18nInstance: I18nInstance | undefined, entryName: string | undefined, languages: string[], localePathRedirect: boolean, ignoreRedirectRoutes: string[] | ((pathname: string) => boolean) | undefined, localisedUrls: LocalisedUrlsOption | undefined, setLang: (lang: string) => void, synchronizeLanguage: (lang: string) => void): {
|
|
9
5
|
language: string;
|
|
10
6
|
i18nInstance: I18nInstance;
|
|
11
7
|
entryName: string | undefined;
|
|
@@ -14,6 +10,7 @@ export declare function createContextValue(lang: string, i18nInstance: I18nInsta
|
|
|
14
10
|
ignoreRedirectRoutes: string[] | ((pathname: string) => boolean) | undefined;
|
|
15
11
|
localisedUrls: LocalisedUrlsOption | undefined;
|
|
16
12
|
updateLanguage: (lang: string) => void;
|
|
13
|
+
synchronizeLanguage: (lang: string) => void;
|
|
17
14
|
};
|
|
18
15
|
export declare function useSdkResourcesLoader(i18nInstance: I18nInstance | undefined, setForceUpdate: React.Dispatch<React.SetStateAction<number>>): void;
|
|
19
16
|
/**
|
|
@@ -26,5 +23,4 @@ export declare function useSdkResourcesLoader(i18nInstance: I18nInstance | undef
|
|
|
26
23
|
* We use process.env.MODERN_TARGET to ensure this code is only included in browser bundles.
|
|
27
24
|
*/
|
|
28
25
|
export declare function useClientSideRedirect(i18nInstance: I18nInstance | undefined, localePathRedirect: boolean, languages: string[], fallbackLanguage: string, ignoreRedirectRoutes?: string[] | ((pathname: string) => boolean), localisedUrls?: LocalisedUrlsOption): void;
|
|
29
|
-
export declare function useLanguageSync(i18nInstance: I18nInstance | undefined, localePathRedirect: boolean, languages: string[],
|
|
30
|
-
export {};
|
|
26
|
+
export declare function useLanguageSync(i18nInstance: I18nInstance | undefined, localePathRedirect: boolean, languages: string[], pathname: string | undefined, prevLangRef: React.MutableRefObject<string>, setLang: (lang: string) => void): (currentLang: string) => void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { BaseBackendOptions, ChainedBackendConfig } from '../../../shared/type';
|
|
2
2
|
import type { I18nInstance } from '../instance';
|
|
3
3
|
type BackendConfigWithChained = BaseBackendOptions & Partial<ChainedBackendConfig>;
|
|
4
|
+
type BackendConstructor = new (...args: never[]) => unknown;
|
|
4
5
|
/**
|
|
5
6
|
* Common logic for using i18next backend
|
|
6
7
|
* This function handles the backend selection and chained backend configuration
|
|
@@ -10,5 +11,5 @@ type BackendConfigWithChained = BaseBackendOptions & Partial<ChainedBackendConfi
|
|
|
10
11
|
* @param BackendBase - The base backend class (for non-chained use)
|
|
11
12
|
* @param backend - Optional backend configuration
|
|
12
13
|
*/
|
|
13
|
-
export declare function useI18nextBackendCommon(i18nInstance: I18nInstance, BackendWithSave:
|
|
14
|
+
export declare function useI18nextBackendCommon(i18nInstance: I18nInstance, BackendWithSave: BackendConstructor, BackendBase: BackendConstructor, backend?: BackendConfigWithChained): void;
|
|
14
15
|
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { I18nInitOptions, I18nInstance, LanguageDetectorOptions } from '../instance';
|
|
2
|
+
interface DetectorCacheEntry {
|
|
3
|
+
instance: I18nInstance;
|
|
4
|
+
isTemporary: boolean;
|
|
5
|
+
configKey: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const detectorInstanceCache: WeakMap<I18nInstance, DetectorCacheEntry>;
|
|
8
|
+
export declare const buildDetectorConfigKey: (languages: string[], fallbackLanguage: string, mergedDetection: LanguageDetectorOptions) => string;
|
|
9
|
+
export declare const pickSafeDetectionOptions: (userInitOptions?: I18nInitOptions) => Partial<I18nInitOptions> & Record<string, unknown>;
|
|
10
|
+
export declare const createDetectorInstance: (baseInstance: I18nInstance, configKey: string) => {
|
|
11
|
+
instance: I18nInstance;
|
|
12
|
+
isTemporary: boolean;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { I18nInstance } from '../instance';
|
|
2
|
+
import type { BaseLanguageDetectionOptions, LanguageDetectionSsrContext } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Priority 3: Detect language using i18next detector
|
|
5
|
+
*/
|
|
6
|
+
export declare const detectLanguageFromI18nextDetector: (i18nInstance: I18nInstance, options: BaseLanguageDetectionOptions & {
|
|
7
|
+
ssrContext?: LanguageDetectionSsrContext;
|
|
8
|
+
}) => Promise<string | undefined>;
|
|
@@ -1,50 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export {
|
|
5
|
-
export
|
|
6
|
-
export declare const getLanguageFromSSRData: (window: Window) => string | undefined;
|
|
7
|
-
export interface BaseLanguageDetectionOptions {
|
|
8
|
-
languages: string[];
|
|
9
|
-
fallbackLanguage: string;
|
|
10
|
-
localePathRedirect: boolean;
|
|
11
|
-
i18nextDetector: boolean;
|
|
12
|
-
detection?: LanguageDetectorOptions;
|
|
13
|
-
userInitOptions?: I18nInitOptions;
|
|
14
|
-
mergedBackend?: any;
|
|
15
|
-
}
|
|
16
|
-
export interface LanguageDetectionOptions extends BaseLanguageDetectionOptions {
|
|
17
|
-
pathname: string;
|
|
18
|
-
ssrContext?: any;
|
|
19
|
-
}
|
|
20
|
-
export interface LanguageDetectionResult {
|
|
21
|
-
detectedLanguage?: string;
|
|
22
|
-
finalLanguage: string;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Detect language with priority:
|
|
26
|
-
* Priority 1: SSR data (try window._SSR_DATA first, works for both SSR and CSR)
|
|
27
|
-
* Priority 2: Path detection
|
|
28
|
-
* Priority 3: i18next detector (reads from cookie/localStorage)
|
|
29
|
-
* Priority 4: User config language or fallback
|
|
30
|
-
*/
|
|
31
|
-
export declare const detectLanguageWithPriority: (i18nInstance: I18nInstance, options: LanguageDetectionOptions) => Promise<LanguageDetectionResult>;
|
|
32
|
-
/**
|
|
33
|
-
* Options for building i18n init options
|
|
34
|
-
*/
|
|
35
|
-
export interface BuildInitOptionsParams {
|
|
36
|
-
finalLanguage: string;
|
|
37
|
-
fallbackLanguage: string;
|
|
38
|
-
languages: string[];
|
|
39
|
-
userInitOptions?: I18nInitOptions;
|
|
40
|
-
mergedDetection?: any;
|
|
41
|
-
mergeBackend?: any;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Build i18n initialization options
|
|
45
|
-
*/
|
|
46
|
-
export declare const buildInitOptions: (params: BuildInitOptionsParams) => I18nInitOptions;
|
|
47
|
-
/**
|
|
48
|
-
* Merge detection and backend options
|
|
49
|
-
*/
|
|
50
|
-
export declare const mergeDetectionOptions: (i18nextDetector: boolean, detection?: LanguageDetectorOptions, localePathRedirect?: boolean, userInitOptions?: I18nInitOptions) => LanguageDetectorOptions;
|
|
1
|
+
export { buildInitOptions, mergeDetectionOptions } from './initOptions';
|
|
2
|
+
export { cacheUserLanguage } from './middleware';
|
|
3
|
+
export { detectLanguageWithPriority } from './priority';
|
|
4
|
+
export { exportServerLngToWindow, getLanguageFromSSRData } from './ssr';
|
|
5
|
+
export type { BaseLanguageDetectionOptions, BuildInitOptionsParams, LanguageDetectionOptions, LanguageDetectionResult, } from './types';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { I18nInitOptions, LanguageDetectorOptions } from '../instance';
|
|
2
|
+
import type { BuildInitOptionsParams } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Build i18n initialization options
|
|
5
|
+
*/
|
|
6
|
+
export declare const buildInitOptions: (params: BuildInitOptionsParams) => I18nInitOptions;
|
|
7
|
+
/**
|
|
8
|
+
* Merge detection and backend options
|
|
9
|
+
*/
|
|
10
|
+
export declare const mergeDetectionOptions: (i18nextDetector: boolean, detection?: LanguageDetectorOptions, localePathRedirect?: boolean, userInitOptions?: I18nInitOptions) => LanguageDetectorOptions;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a language is supported
|
|
3
|
+
* Also checks the base language code (e.g., 'zh-CN' matches 'zh')
|
|
4
|
+
*/
|
|
5
|
+
export declare const isLanguageSupported: (language: string | undefined, supportedLanguages: string[]) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Get the supported language that matches the given language
|
|
8
|
+
* Returns the exact match if available, otherwise returns the base language code match
|
|
9
|
+
* Returns undefined if no match is found
|
|
10
|
+
*/
|
|
11
|
+
export declare const getSupportedLanguage: (language: string | undefined, supportedLanguages: string[]) => string | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { I18nInstance } from '../instance';
|
|
1
|
+
import type { I18nInstance, LanguageDetectorOptions } from '../instance';
|
|
2
2
|
/**
|
|
3
3
|
* Register LanguageDetector plugin to i18n instance
|
|
4
4
|
* Must be called before init() to properly register the detector
|
|
@@ -9,16 +9,16 @@ export declare const useI18nextLanguageDetector: (i18nInstance: I18nInstance) =>
|
|
|
9
9
|
* Read language directly from localStorage/cookie
|
|
10
10
|
* Fallback when detector is not available in services
|
|
11
11
|
*/
|
|
12
|
-
export declare const readLanguageFromStorage: (detectionOptions?:
|
|
12
|
+
export declare const readLanguageFromStorage: (detectionOptions?: LanguageDetectorOptions) => string | undefined;
|
|
13
13
|
/**
|
|
14
14
|
* Detect language using i18next-browser-languagedetector
|
|
15
15
|
* For initialized instances without detector in services, manually create a detector instance
|
|
16
16
|
* For wrapper instances, access the underlying i18next instance's services
|
|
17
17
|
*/
|
|
18
|
-
export declare const detectLanguage: (i18nInstance: I18nInstance, _request?:
|
|
18
|
+
export declare const detectLanguage: (i18nInstance: I18nInstance, _request?: unknown, detectionOptions?: LanguageDetectorOptions) => string | undefined;
|
|
19
19
|
/**
|
|
20
20
|
* Cache user language to localStorage/cookie
|
|
21
21
|
* Uses LanguageDetector's cacheUserLanguage method when available
|
|
22
22
|
* For wrapper instances, access the underlying i18next instance's services
|
|
23
23
|
*/
|
|
24
|
-
export declare const cacheUserLanguage: (i18nInstance: I18nInstance, language: string, detectionOptions?:
|
|
24
|
+
export declare const cacheUserLanguage: (i18nInstance: I18nInstance, language: string, detectionOptions?: unknown) => void;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { I18nInstance } from '../instance';
|
|
2
|
-
export declare const cacheUserLanguage: (_i18nInstance: I18nInstance, _language: string, _detectionOptions?:
|
|
1
|
+
import type { I18nInstance, LanguageDetectorOptions } from '../instance';
|
|
2
|
+
export declare const cacheUserLanguage: (_i18nInstance: I18nInstance, _language: string, _detectionOptions?: unknown) => void;
|
|
3
3
|
/**
|
|
4
4
|
* Read language directly from storage (localStorage/cookie)
|
|
5
5
|
* Not available in Node.js environment, returns undefined
|
|
6
6
|
*/
|
|
7
|
-
export declare const readLanguageFromStorage: (_detectionOptions?:
|
|
7
|
+
export declare const readLanguageFromStorage: (_detectionOptions?: LanguageDetectorOptions) => string | undefined;
|
|
8
8
|
/**
|
|
9
9
|
* Register LanguageDetector plugin to i18n instance
|
|
10
10
|
* Must be called before init() to properly register the detector
|
|
@@ -14,4 +14,4 @@ export declare const useI18nextLanguageDetector: (i18nInstance: I18nInstance) =>
|
|
|
14
14
|
* Detect language using i18next-http-middleware LanguageDetector
|
|
15
15
|
* For initialized instances without detector in services, manually create a detector instance
|
|
16
16
|
*/
|
|
17
|
-
export declare const detectLanguage: (i18nInstance: I18nInstance, request?:
|
|
17
|
+
export declare const detectLanguage: (i18nInstance: I18nInstance, request?: unknown, detectionOptions?: LanguageDetectorOptions) => string | undefined;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Priority 2: Detect language from URL path
|
|
3
|
+
* Only returns a language if the path explicitly contains a language prefix
|
|
4
|
+
*/
|
|
5
|
+
export declare const detectLanguageFromPathPriority: (pathname: string, languages: string[], localePathRedirect: boolean) => string | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type I18nInstance } from '../instance';
|
|
2
|
+
import type { LanguageDetectionOptions, LanguageDetectionResult } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Detect language with priority:
|
|
5
|
+
* Priority 1: Path detection
|
|
6
|
+
* Priority 2: SSR data (try window._SSR_DATA first, works for both SSR and CSR)
|
|
7
|
+
* Priority 3: i18next detector (reads from cookie/localStorage)
|
|
8
|
+
* Priority 4: User config language or fallback
|
|
9
|
+
*/
|
|
10
|
+
export declare const detectLanguageWithPriority: (i18nInstance: I18nInstance, options: LanguageDetectionOptions) => Promise<LanguageDetectionResult>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type TRuntimeContext } from '@modern-js/runtime';
|
|
2
|
+
export declare function exportServerLngToWindow(context: TRuntimeContext, lng: string): void;
|
|
3
|
+
export declare const getLanguageFromSSRData: (window: Window) => string | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* Priority 1: Detect language from SSR data
|
|
6
|
+
* Try to get language from window._SSR_DATA first (both SSR and CSR projects)
|
|
7
|
+
* Returns undefined if SSR data is not available or invalid
|
|
8
|
+
*/
|
|
9
|
+
export declare const detectLanguageFromSSR: (languages: string[]) => string | undefined;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { BackendOptions, I18nInitOptions, LanguageDetectorOptions } from '../instance';
|
|
2
|
+
export interface LanguageDetectionSsrContext {
|
|
3
|
+
request?: unknown;
|
|
4
|
+
}
|
|
5
|
+
export interface BaseLanguageDetectionOptions {
|
|
6
|
+
languages: string[];
|
|
7
|
+
fallbackLanguage: string;
|
|
8
|
+
localePathRedirect: boolean;
|
|
9
|
+
i18nextDetector: boolean;
|
|
10
|
+
detection?: LanguageDetectorOptions;
|
|
11
|
+
userInitOptions?: I18nInitOptions;
|
|
12
|
+
mergedBackend?: BackendOptions;
|
|
13
|
+
}
|
|
14
|
+
export interface LanguageDetectionOptions extends BaseLanguageDetectionOptions {
|
|
15
|
+
pathname: string;
|
|
16
|
+
ssrContext?: LanguageDetectionSsrContext;
|
|
17
|
+
}
|
|
18
|
+
export interface LanguageDetectionResult {
|
|
19
|
+
detectedLanguage?: string;
|
|
20
|
+
finalLanguage: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Options for building i18n init options
|
|
24
|
+
*/
|
|
25
|
+
export interface BuildInitOptionsParams {
|
|
26
|
+
finalLanguage: string;
|
|
27
|
+
fallbackLanguage: string;
|
|
28
|
+
languages: string[];
|
|
29
|
+
userInitOptions?: I18nInitOptions;
|
|
30
|
+
mergedDetection?: LanguageDetectorOptions;
|
|
31
|
+
mergeBackend?: BackendOptions;
|
|
32
|
+
}
|
|
@@ -1,46 +1,49 @@
|
|
|
1
1
|
import type { BaseBackendOptions } from '../../shared/type';
|
|
2
|
-
|
|
2
|
+
interface I18nResourceStore {
|
|
3
3
|
data?: {
|
|
4
4
|
[language: string]: {
|
|
5
|
-
[namespace: string]:
|
|
6
|
-
[key: string]: any;
|
|
7
|
-
};
|
|
5
|
+
[namespace: string]: ResourceValue;
|
|
8
6
|
};
|
|
9
7
|
};
|
|
10
8
|
addResourceBundle?: (language: string, namespace: string, resources: Record<string, string>, deep?: boolean, overwrite?: boolean) => void;
|
|
11
9
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
type I18nWrapperInstance = I18nInstance & {
|
|
11
|
+
i18nInstance: {
|
|
12
|
+
instance: I18nInstance;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export declare function isI18nWrapperInstance(obj: unknown): obj is I18nWrapperInstance;
|
|
16
|
+
export declare function getActualI18nextInstance(instance: I18nInstance): I18nInstance;
|
|
15
17
|
export interface I18nInstance {
|
|
16
18
|
language: string;
|
|
17
19
|
isInitialized?: boolean;
|
|
18
20
|
init: {
|
|
19
|
-
(callback?: (error:
|
|
20
|
-
(options: I18nInitOptions, callback?: (error:
|
|
21
|
+
(callback?: (error: unknown, t: unknown) => void): Promise<unknown>;
|
|
22
|
+
(options: I18nInitOptions, callback?: (error: unknown, t: unknown) => void): Promise<unknown>;
|
|
21
23
|
};
|
|
22
|
-
changeLanguage?: (lng?: string, callback?: (error:
|
|
24
|
+
changeLanguage?: (lng?: string, callback?: (error: unknown, t: unknown) => void) => Promise<unknown>;
|
|
23
25
|
setLang?: (lang: string) => void | Promise<void>;
|
|
24
|
-
use: (plugin:
|
|
26
|
+
use: (plugin: unknown) => void;
|
|
25
27
|
createInstance?: (options?: I18nInitOptions) => I18nInstance;
|
|
26
|
-
cloneInstance?: () => I18nInstance;
|
|
28
|
+
cloneInstance?: (options?: I18nInitOptions) => I18nInstance;
|
|
27
29
|
store?: I18nResourceStore;
|
|
28
|
-
emit?: (event: string, ...args:
|
|
30
|
+
emit?: (event: string, ...args: unknown[]) => void;
|
|
29
31
|
reloadResources?: (language?: string, namespace?: string) => Promise<void>;
|
|
32
|
+
removeResourceBundle?: (language: string, namespace: string) => I18nInstance;
|
|
30
33
|
services?: {
|
|
31
34
|
languageDetector?: {
|
|
32
|
-
detect: (request?:
|
|
33
|
-
[key: string]:
|
|
35
|
+
detect: (request?: unknown, options?: unknown) => string | string[] | undefined;
|
|
36
|
+
[key: string]: unknown;
|
|
34
37
|
};
|
|
35
38
|
resourceStore?: I18nResourceStore;
|
|
36
|
-
backend?:
|
|
37
|
-
[key: string]:
|
|
39
|
+
backend?: unknown;
|
|
40
|
+
[key: string]: unknown;
|
|
38
41
|
};
|
|
39
42
|
options?: {
|
|
40
43
|
backend?: BackendOptions;
|
|
41
|
-
[key: string]:
|
|
44
|
+
[key: string]: unknown;
|
|
42
45
|
};
|
|
43
|
-
[key: string]:
|
|
46
|
+
[key: string]: unknown;
|
|
44
47
|
}
|
|
45
48
|
type LanguageDetectorOrder = string[];
|
|
46
49
|
type LanguageDetectorCaches = boolean | string[];
|
|
@@ -57,11 +60,11 @@ export interface LanguageDetectorOptions {
|
|
|
57
60
|
lookupHeader?: string;
|
|
58
61
|
}
|
|
59
62
|
export interface BackendOptions extends Omit<BaseBackendOptions, 'enabled'> {
|
|
60
|
-
parse?: (data: string) =>
|
|
61
|
-
stringify?: (data:
|
|
63
|
+
parse?: (data: string) => unknown;
|
|
64
|
+
stringify?: (data: unknown) => string;
|
|
62
65
|
[key: string]: any;
|
|
63
66
|
}
|
|
64
|
-
|
|
67
|
+
type ResourceValue = string | {
|
|
65
68
|
[key: string]: ResourceValue;
|
|
66
69
|
};
|
|
67
70
|
export interface Resources {
|
|
@@ -81,14 +84,15 @@ export type I18nInitOptions = {
|
|
|
81
84
|
defaultNS?: string | string[];
|
|
82
85
|
interpolation?: {
|
|
83
86
|
escapeValue?: boolean;
|
|
84
|
-
[key: string]:
|
|
87
|
+
[key: string]: unknown;
|
|
85
88
|
};
|
|
86
89
|
react?: {
|
|
87
90
|
useSuspense?: boolean;
|
|
88
|
-
[key: string]:
|
|
91
|
+
[key: string]: unknown;
|
|
89
92
|
};
|
|
93
|
+
forkResourceStore?: boolean;
|
|
90
94
|
};
|
|
91
|
-
export declare function isI18nInstance(obj:
|
|
92
|
-
export declare function getI18nextInstanceForProvider(instance: I18nInstance
|
|
93
|
-
export declare function getI18nInstance(userInstance?:
|
|
95
|
+
export declare function isI18nInstance(obj: unknown): obj is I18nInstance;
|
|
96
|
+
export declare function getI18nextInstanceForProvider(instance: I18nInstance, language?: string): I18nInstance;
|
|
97
|
+
export declare function getI18nInstance(userInstance?: unknown): Promise<I18nInstance>;
|
|
94
98
|
export {};
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
import type
|
|
2
|
-
interface ReactI18nextIntegration {
|
|
3
|
-
I18nextProvider: React.ComponentType<any> | null;
|
|
4
|
-
initReactI18next: any | null;
|
|
5
|
-
}
|
|
1
|
+
import type { ReactI18nextIntegration } from '../reactI18next';
|
|
6
2
|
export declare function getReactI18nextIntegration(): Promise<ReactI18nextIntegration>;
|
|
7
|
-
export {};
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import type { BaseBackendOptions } from '../../shared/type';
|
|
2
2
|
import type { I18nInitOptions, I18nInstance } from './instance';
|
|
3
|
-
|
|
3
|
+
type MergedBackendOptions = NonNullable<I18nInitOptions['backend']> & {
|
|
4
|
+
_useChainedBackend?: boolean;
|
|
5
|
+
_chainedBackendConfig?: {
|
|
6
|
+
backendOptions: Array<Record<string, unknown>>;
|
|
7
|
+
};
|
|
8
|
+
backends?: unknown[];
|
|
9
|
+
backendOptions?: unknown;
|
|
10
|
+
};
|
|
11
|
+
export declare function assertI18nInstance(obj: unknown): asserts obj is I18nInstance;
|
|
4
12
|
/**
|
|
5
13
|
* Build initialization options for i18n instance
|
|
6
14
|
*/
|
|
7
|
-
export declare const buildInitOptions: (finalLanguage: string, fallbackLanguage: string, languages: string[], mergedDetection:
|
|
15
|
+
export declare const buildInitOptions: (finalLanguage: string, fallbackLanguage: string, languages: string[], mergedDetection: I18nInitOptions['detection'], mergedBackend: MergedBackendOptions | undefined, userInitOptions?: I18nInitOptions, useSuspense?: boolean, i18nInstance?: I18nInstance) => Promise<I18nInitOptions>;
|
|
8
16
|
/**
|
|
9
17
|
* Ensure i18n instance language matches the final detected language
|
|
10
18
|
*/
|
|
@@ -17,13 +25,14 @@ export declare const ensureLanguageMatch: (i18nInstance: I18nInstance, finalLang
|
|
|
17
25
|
* @param options - Optional configuration
|
|
18
26
|
*/
|
|
19
27
|
export declare const changeI18nLanguage: (i18nInstance: I18nInstance, newLang: string, options?: {
|
|
20
|
-
detectionOptions?:
|
|
28
|
+
detectionOptions?: I18nInitOptions['detection'];
|
|
21
29
|
}) => Promise<void>;
|
|
22
30
|
/**
|
|
23
31
|
* Initialize i18n instance if not already initialized
|
|
24
32
|
*/
|
|
25
|
-
export declare const initializeI18nInstance: (i18nInstance: I18nInstance, finalLanguage: string, fallbackLanguage: string, languages: string[], mergedDetection:
|
|
33
|
+
export declare const initializeI18nInstance: (i18nInstance: I18nInstance, finalLanguage: string, fallbackLanguage: string, languages: string[], mergedDetection: I18nInitOptions['detection'], mergedBackend: MergedBackendOptions | undefined, userInitOptions?: I18nInitOptions, useSuspense?: boolean) => Promise<void>;
|
|
26
34
|
/**
|
|
27
35
|
* Setup cloned instance for SSR with backend support
|
|
28
36
|
*/
|
|
29
|
-
export declare const setupClonedInstance: (i18nInstance: I18nInstance, finalLanguage: string, fallbackLanguage: string, languages: string[], backendEnabled: boolean, backend: BaseBackendOptions | undefined, i18nextDetector: boolean, detection:
|
|
37
|
+
export declare const setupClonedInstance: (i18nInstance: I18nInstance, finalLanguage: string, fallbackLanguage: string, languages: string[], backendEnabled: boolean, backend: BaseBackendOptions | undefined, i18nextDetector: boolean, detection: I18nInitOptions['detection'], localePathRedirect: boolean, userInitOptions: I18nInitOptions | undefined) => Promise<void>;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const warnOnce: (key: string, message: string) => void;
|
|
2
|
+
export type LinkParams = Record<string, string | number | undefined>;
|
|
3
|
+
type NormalizedSearchValue = string | string[];
|
|
4
|
+
/**
|
|
5
|
+
* Interpolate `$param`, `:param`, optional (`{-$param}` / `:param?`) and splat
|
|
6
|
+
* (`$` / `*`) segments with concrete values before localization, so
|
|
7
|
+
* pattern-mapped slugs localize correctly.
|
|
8
|
+
*/
|
|
9
|
+
export declare const interpolateRouteParams: (pathname: string, params?: LinkParams) => string;
|
|
10
|
+
export declare const normalizeSearch: (search: string | Record<string, unknown> | undefined, searchFromTo: string) => {
|
|
11
|
+
searchString: string;
|
|
12
|
+
searchObject: Record<string, NormalizedSearchValue> | undefined;
|
|
13
|
+
};
|
|
14
|
+
type ActivePropsResult<TActiveProps extends Record<string, unknown>> = Record<string, unknown> & Partial<TActiveProps>;
|
|
15
|
+
export declare const splitActiveProps: <TActiveProps extends Record<string, unknown>>(active: boolean, activeProps?: TActiveProps) => ActivePropsResult<TActiveProps>;
|
|
16
|
+
export declare const mergeClassNames: (...values: Array<unknown>) => string | undefined;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { TInternalRuntimeContext } from '@modern-js/runtime/internal';
|
|
2
|
+
import type { BaseBackendOptions, BaseLocaleDetectionOptions } from '../shared/type';
|
|
3
|
+
import type { I18nInitOptions, I18nInstance } from './i18n';
|
|
4
|
+
import type { ReactI18nextIntegration } from './reactI18next';
|
|
5
|
+
interface RuntimeConfigWithI18n {
|
|
6
|
+
i18n?: {
|
|
7
|
+
initOptions?: I18nInitOptions;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
interface I18nRuntimeApi {
|
|
11
|
+
getRuntimeConfig: () => RuntimeConfigWithI18n;
|
|
12
|
+
}
|
|
13
|
+
export interface RuntimeContextWithI18n extends TInternalRuntimeContext {
|
|
14
|
+
i18nInstance?: I18nInstance;
|
|
15
|
+
changeLanguage?: (lang: string) => Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
interface SetupI18nBeforeRenderOptions {
|
|
18
|
+
api: I18nRuntimeApi;
|
|
19
|
+
userI18nInstance?: I18nInstance;
|
|
20
|
+
initOptions?: I18nInitOptions;
|
|
21
|
+
backend?: BaseBackendOptions;
|
|
22
|
+
backendEnabled: boolean;
|
|
23
|
+
i18nextDetector: boolean;
|
|
24
|
+
detection?: BaseLocaleDetectionOptions['detection'];
|
|
25
|
+
localePathRedirect: boolean;
|
|
26
|
+
languages: string[];
|
|
27
|
+
fallbackLanguage: string;
|
|
28
|
+
resolveReactI18nextIntegration: () => Promise<ReactI18nextIntegration | null>;
|
|
29
|
+
setI18nextProvider: (provider: ReactI18nextIntegration['I18nextProvider']) => void;
|
|
30
|
+
}
|
|
31
|
+
export declare function setupI18nBeforeRender(context: RuntimeContextWithI18n, options: SetupI18nBeforeRenderOptions): Promise<I18nInstance>;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { BaseLocaleDetectionOptions } from '../shared/type';
|
|
3
|
+
import type { I18nInstance } from './i18n';
|
|
4
|
+
interface I18nRootWrapperOptions {
|
|
5
|
+
entryName?: string;
|
|
6
|
+
htmlLangAttr: boolean;
|
|
7
|
+
localePathRedirect: boolean;
|
|
8
|
+
languages: string[];
|
|
9
|
+
fallbackLanguage: string;
|
|
10
|
+
ignoreRedirectRoutes?: BaseLocaleDetectionOptions['ignoreRedirectRoutes'];
|
|
11
|
+
localisedUrls?: BaseLocaleDetectionOptions['localisedUrls'];
|
|
12
|
+
getLatestI18nInstance: () => I18nInstance | undefined;
|
|
13
|
+
getI18nextProvider: () => React.ComponentType<any> | null | undefined;
|
|
14
|
+
}
|
|
15
|
+
export declare const createI18nRootWrapper: (options: I18nRootWrapperOptions) => (App: React.ComponentType<any>) => (props: Record<string, unknown>) => React.JSX.Element;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
export interface ReactI18nextIntegration {
|
|
3
|
+
I18nextProvider: React.ComponentType<any> | null;
|
|
4
|
+
initReactI18next: any | null;
|
|
5
|
+
}
|
|
6
|
+
export type LoadReactI18nextIntegration = () => Promise<ReactI18nextIntegration | null>;
|
|
7
|
+
export declare const resolveReactI18nextIntegration: (reactI18next: boolean, loadReactI18nextIntegration?: LoadReactI18nextIntegration) => Promise<ReactI18nextIntegration | null>;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
type I18nRouterFramework = 'react-router' | 'tanstack' | string;
|
|
3
|
+
interface I18nRouterLocation {
|
|
4
4
|
pathname: string;
|
|
5
5
|
search: string;
|
|
6
6
|
hash: string;
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
interface I18nRouterNavigateOptions {
|
|
9
9
|
replace?: boolean;
|
|
10
10
|
state?: unknown;
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
type I18nRouterNavigate = (href: string, options?: I18nRouterNavigateOptions) => void | Promise<void>;
|
|
13
|
+
type I18nRouterLink = React.ComponentType<{
|
|
14
14
|
to: string;
|
|
15
15
|
children?: React.ReactNode;
|
|
16
16
|
[key: string]: unknown;
|
|
17
17
|
}>;
|
|
18
|
-
|
|
18
|
+
interface I18nRouterAdapter {
|
|
19
19
|
framework?: I18nRouterFramework;
|
|
20
20
|
hasRouter: boolean;
|
|
21
21
|
location: I18nRouterLocation | null;
|
|
@@ -24,3 +24,4 @@ export interface I18nRouterAdapter {
|
|
|
24
24
|
params: Record<string, string>;
|
|
25
25
|
}
|
|
26
26
|
export declare const useI18nRouterAdapter: () => I18nRouterAdapter;
|
|
27
|
+
export {};
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import { type TInternalRuntimeContext } from '@modern-js/runtime/context';
|
|
2
1
|
import type { LocalisedUrlsOption } from '../shared/localisedUrls';
|
|
3
|
-
export declare const getPathname: (context:
|
|
2
|
+
export declare const getPathname: (context: {
|
|
3
|
+
ssrContext?: {
|
|
4
|
+
request?: {
|
|
5
|
+
pathname?: string;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
}) => string;
|
|
4
9
|
export declare const getEntryPath: () => string;
|
|
5
10
|
/**
|
|
6
11
|
* Helper function to get language from current pathname
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type ApiPrefixInput = string | string[] | undefined;
|
|
2
|
+
export declare const collectApiPrefixes: (routes: Array<{
|
|
3
|
+
isApi?: boolean;
|
|
4
|
+
urlPath?: string;
|
|
5
|
+
}>, bffPrefix?: ApiPrefixInput) => string[];
|
|
6
|
+
export declare const matchesApiPrefix: (pathname: string, apiPrefixes: string[]) => boolean;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { LanguageDetectorOptions } from '../runtime/i18n/instance';
|
|
2
|
+
/**
|
|
3
|
+
* Convert i18next detection options to hono languageDetector options
|
|
4
|
+
*/
|
|
5
|
+
export declare const convertToHonoLanguageDetectorOptions: (languages: string[], fallbackLanguage: string, detectionOptions?: LanguageDetectorOptions) => {
|
|
6
|
+
supportedLanguages: string[];
|
|
7
|
+
fallbackLanguage: string;
|
|
8
|
+
order: ("cookie" | "header" | "path" | "querystring")[];
|
|
9
|
+
lookupQueryString: string;
|
|
10
|
+
lookupCookie: string;
|
|
11
|
+
lookupFromHeaderKey: string;
|
|
12
|
+
caches?: false | ["cookie"] | undefined;
|
|
13
|
+
cookieOptions?: {
|
|
14
|
+
maxAge: number;
|
|
15
|
+
sameSite: "Lax" | "None" | "Strict";
|
|
16
|
+
secure: boolean;
|
|
17
|
+
httpOnly: boolean;
|
|
18
|
+
domain?: string | undefined;
|
|
19
|
+
} | undefined;
|
|
20
|
+
ignoreCase: boolean;
|
|
21
|
+
};
|