@bleedingdev/modern-js-plugin-i18n 3.8.3-ultramodern.1 → 3.8.3-ultramodern.2
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 +3 -3
- package/dist/cjs/runtime/context.js +19 -6
- package/dist/cjs/runtime/hooks.js +8 -11
- package/dist/cjs/runtime/localizedPaths.js +2 -2
- package/dist/cjs/runtime/providerComposition.js +3 -1
- package/dist/cjs/runtime/utils.js +3 -3
- package/dist/cjs/server/index.js +2 -2
- package/dist/cjs/server/redirectPolicy.js +6 -6
- package/dist/esm/cli/index.mjs +1 -1
- package/dist/esm/runtime/context.mjs +19 -6
- package/dist/esm/runtime/hooks.mjs +8 -11
- package/dist/esm/runtime/localizedPaths.mjs +1 -1
- package/dist/esm/runtime/providerComposition.mjs +3 -1
- package/dist/esm/runtime/utils.mjs +1 -1
- package/dist/esm/server/index.mjs +1 -1
- package/dist/esm/server/redirectPolicy.mjs +1 -1
- package/dist/esm-node/cli/index.mjs +1 -1
- package/dist/esm-node/runtime/context.mjs +19 -6
- package/dist/esm-node/runtime/hooks.mjs +8 -11
- package/dist/esm-node/runtime/localizedPaths.mjs +1 -1
- package/dist/esm-node/runtime/providerComposition.mjs +3 -1
- package/dist/esm-node/runtime/utils.mjs +1 -1
- package/dist/esm-node/server/index.mjs +1 -1
- package/dist/esm-node/server/redirectPolicy.mjs +1 -1
- package/dist/types/runtime/context.d.ts +3 -2
- package/dist/types/runtime/contextHelpers.d.ts +1 -1
- package/dist/types/runtime/hooks.d.ts +1 -1
- package/dist/types/runtime/localizedPaths.d.ts +1 -1
- package/dist/types/runtime/utils.d.ts +1 -1
- package/dist/types/shared/type.d.ts +1 -1
- package/package.json +32 -11
- package/src/cli/index.ts +4 -4
- package/src/runtime/context.tsx +38 -14
- package/src/runtime/contextHelpers.ts +1 -1
- package/src/runtime/hooks.ts +9 -10
- package/src/runtime/localizedPaths.ts +4 -2
- package/src/runtime/providerComposition.tsx +5 -2
- package/src/runtime/utils.ts +4 -4
- package/src/server/index.ts +1 -1
- package/src/server/redirectPolicy.ts +1 -1
- package/src/shared/type.ts +1 -1
- package/tests/federatedI18nBoundary.client.test.tsx +21 -4
- package/tests/federatedI18nBoundary.test.tsx +15 -3
- package/tests/linkTypes.test.ts +20 -0
- package/tests/localisedUrlRewriteMatrix.fork.test.ts +1 -1
- package/tests/localisedUrls.test.ts +0 -351
- package/tests/routerAdapter.test.tsx +5 -12
- package/dist/cjs/shared/localisedUrls/config.js +0 -49
- package/dist/cjs/shared/localisedUrls/index.js +0 -91
- package/dist/cjs/shared/localisedUrls/normalise.js +0 -87
- package/dist/cjs/shared/localisedUrls/pathname.js +0 -68
- package/dist/cjs/shared/localisedUrls/patterns.js +0 -130
- package/dist/cjs/shared/localisedUrls/redirect.js +0 -103
- package/dist/cjs/shared/localisedUrls/resolve.js +0 -88
- package/dist/cjs/shared/localisedUrls/routes.js +0 -130
- package/dist/cjs/shared/localisedUrls/types.js +0 -18
- package/dist/cjs/shared/localisedUrls.js +0 -85
- package/dist/esm/shared/localisedUrls/config.mjs +0 -11
- package/dist/esm/shared/localisedUrls/index.mjs +0 -7
- package/dist/esm/shared/localisedUrls/normalise.mjs +0 -37
- package/dist/esm/shared/localisedUrls/pathname.mjs +0 -24
- package/dist/esm/shared/localisedUrls/patterns.mjs +0 -86
- package/dist/esm/shared/localisedUrls/redirect.mjs +0 -56
- package/dist/esm/shared/localisedUrls/resolve.mjs +0 -47
- package/dist/esm/shared/localisedUrls/routes.mjs +0 -89
- package/dist/esm/shared/localisedUrls/types.mjs +0 -0
- package/dist/esm/shared/localisedUrls.mjs +0 -1
- package/dist/esm-node/shared/localisedUrls/config.mjs +0 -12
- package/dist/esm-node/shared/localisedUrls/index.mjs +0 -8
- package/dist/esm-node/shared/localisedUrls/normalise.mjs +0 -38
- package/dist/esm-node/shared/localisedUrls/pathname.mjs +0 -25
- package/dist/esm-node/shared/localisedUrls/patterns.mjs +0 -87
- package/dist/esm-node/shared/localisedUrls/redirect.mjs +0 -57
- package/dist/esm-node/shared/localisedUrls/resolve.mjs +0 -48
- package/dist/esm-node/shared/localisedUrls/routes.mjs +0 -90
- package/dist/esm-node/shared/localisedUrls/types.mjs +0 -1
- package/dist/esm-node/shared/localisedUrls.mjs +0 -2
- package/dist/types/shared/localisedUrls/config.d.ts +0 -9
- package/dist/types/shared/localisedUrls/index.d.ts +0 -9
- package/dist/types/shared/localisedUrls/normalise.d.ts +0 -10
- package/dist/types/shared/localisedUrls/pathname.d.ts +0 -4
- package/dist/types/shared/localisedUrls/patterns.d.ts +0 -5
- package/dist/types/shared/localisedUrls/redirect.d.ts +0 -11
- package/dist/types/shared/localisedUrls/resolve.d.ts +0 -7
- package/dist/types/shared/localisedUrls/routes.d.ts +0 -3
- package/dist/types/shared/localisedUrls/types.d.ts +0 -14
- package/dist/types/shared/localisedUrls.d.ts +0 -2
- package/src/shared/localisedUrls/config.ts +0 -18
- package/src/shared/localisedUrls/index.ts +0 -24
- package/src/shared/localisedUrls/normalise.ts +0 -67
- package/src/shared/localisedUrls/pathname.ts +0 -60
- package/src/shared/localisedUrls/patterns.ts +0 -160
- package/src/shared/localisedUrls/redirect.ts +0 -93
- package/src/shared/localisedUrls/resolve.ts +0 -135
- package/src/shared/localisedUrls/routes.ts +0 -234
- package/src/shared/localisedUrls/types.ts +0 -18
- package/src/shared/localisedUrls.ts +0 -26
package/dist/cjs/cli/index.js
CHANGED
|
@@ -31,8 +31,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
31
31
|
default: ()=>cli,
|
|
32
32
|
i18nPlugin: ()=>i18nPlugin
|
|
33
33
|
});
|
|
34
|
+
const i18n_runtime_extensions_namespaceObject = require("@modern-js/i18n-runtime-extensions");
|
|
34
35
|
const server_core_namespaceObject = require("@modern-js/server-core");
|
|
35
|
-
const localisedUrls_js_namespaceObject = require("../shared/localisedUrls.js");
|
|
36
36
|
const utils_js_namespaceObject = require("../shared/utils.js");
|
|
37
37
|
const external_locales_js_namespaceObject = require("./locales.js");
|
|
38
38
|
require("../runtime/types.js");
|
|
@@ -87,14 +87,14 @@ const i18nPlugin = (options = {})=>({
|
|
|
87
87
|
entrypoint,
|
|
88
88
|
routes
|
|
89
89
|
};
|
|
90
|
-
const localisedUrlsConfig = (0,
|
|
90
|
+
const localisedUrlsConfig = (0, i18n_runtime_extensions_namespaceObject.resolveLocalisedUrlsConfig)(localisedUrls);
|
|
91
91
|
if (!localisedUrlsConfig.enabled) return {
|
|
92
92
|
entrypoint,
|
|
93
93
|
routes
|
|
94
94
|
};
|
|
95
95
|
return {
|
|
96
96
|
entrypoint,
|
|
97
|
-
routes: (0,
|
|
97
|
+
routes: (0, i18n_runtime_extensions_namespaceObject.applyLocalisedUrlsToRoutes)(routes, languages, localisedUrlsConfig.map)
|
|
98
98
|
};
|
|
99
99
|
});
|
|
100
100
|
api._internalServerPlugins(({ plugins })=>{
|
|
@@ -38,18 +38,27 @@ const external_contextHelpers_js_namespaceObject = require("./contextHelpers.js"
|
|
|
38
38
|
const instance_js_namespaceObject = require("./i18n/instance.js");
|
|
39
39
|
const external_routerAdapter_js_namespaceObject = require("./routerAdapter.js");
|
|
40
40
|
const modernI18nContextKey = Symbol.for('@modern-js/plugin-i18n/runtime/ModernI18nContext');
|
|
41
|
-
const
|
|
41
|
+
const reactI18nextProviderContextKey = Symbol.for('@modern-js/plugin-i18n/runtime/ReactI18nextProviderContext');
|
|
42
|
+
const getGlobalContext = (key, defaultValue)=>{
|
|
42
43
|
const globalStore = globalThis;
|
|
43
|
-
globalStore[
|
|
44
|
-
return globalStore[
|
|
44
|
+
globalStore[key] ??= /*#__PURE__*/ (0, external_react_namespaceObject.createContext)(defaultValue);
|
|
45
|
+
return globalStore[key];
|
|
45
46
|
};
|
|
46
|
-
const ModernI18nContext =
|
|
47
|
-
const
|
|
47
|
+
const ModernI18nContext = getGlobalContext(modernI18nContextKey, null);
|
|
48
|
+
const ReactI18nextProviderContext = getGlobalContext(reactI18nextProviderContextKey, null);
|
|
49
|
+
const ModernI18nProvider = ({ children, i18nextProvider, value })=>{
|
|
50
|
+
const content = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ModernI18nContext.Provider, {
|
|
48
51
|
value: value,
|
|
49
52
|
children: children
|
|
50
53
|
});
|
|
54
|
+
return void 0 === i18nextProvider ? content : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ReactI18nextProviderContext.Provider, {
|
|
55
|
+
value: i18nextProvider,
|
|
56
|
+
children: content
|
|
57
|
+
});
|
|
58
|
+
};
|
|
51
59
|
const FederatedI18nBoundary = ({ children, defaultNamespace, fallbackLanguage, resources, supportedLanguages })=>{
|
|
52
60
|
const parent = (0, external_react_namespaceObject.useContext)(ModernI18nContext);
|
|
61
|
+
const I18nextProvider = (0, external_react_namespaceObject.useContext)(ReactI18nextProviderContext);
|
|
53
62
|
if (!parent) throw new Error('FederatedI18nBoundary must be used within ModernI18nProvider');
|
|
54
63
|
const languages = supportedLanguages ?? parent.languages ?? Object.keys(resources);
|
|
55
64
|
const scopedInstance = (0, external_react_namespaceObject.useMemo)(()=>{
|
|
@@ -96,10 +105,14 @@ const FederatedI18nBoundary = ({ children, defaultNamespace, fallbackLanguage, r
|
|
|
96
105
|
parent,
|
|
97
106
|
scopedInstance
|
|
98
107
|
]);
|
|
99
|
-
|
|
108
|
+
const scopedContent = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ModernI18nProvider, {
|
|
100
109
|
value: value,
|
|
101
110
|
children: children
|
|
102
111
|
});
|
|
112
|
+
return I18nextProvider ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(I18nextProvider, {
|
|
113
|
+
i18n: scopedInstance,
|
|
114
|
+
children: scopedContent
|
|
115
|
+
}) : scopedContent;
|
|
103
116
|
};
|
|
104
117
|
const useModernI18n = ()=>{
|
|
105
118
|
const context = (0, external_react_namespaceObject.useContext)(ModernI18nContext);
|
|
@@ -114,7 +114,7 @@ function useSdkResourcesLoader(i18nInstance, setForceUpdate) {
|
|
|
114
114
|
]);
|
|
115
115
|
}
|
|
116
116
|
function useClientSideRedirect(i18nInstance, localePathRedirect, languages, fallbackLanguage, ignoreRedirectRoutes, localisedUrls) {
|
|
117
|
-
const
|
|
117
|
+
const urlRef = (0, external_react_namespaceObject.useRef)('');
|
|
118
118
|
const { navigate, location, hasRouter } = (0, external_routerAdapter_js_namespaceObject.useI18nRouterAdapter)();
|
|
119
119
|
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
120
120
|
if ('browser' !== process.env.MODERN_TARGET) return;
|
|
@@ -123,7 +123,7 @@ function useClientSideRedirect(i18nInstance, localePathRedirect, languages, fall
|
|
|
123
123
|
const ssrData = window._SSR_DATA;
|
|
124
124
|
if (ssrData) return;
|
|
125
125
|
} catch {}
|
|
126
|
-
if (
|
|
126
|
+
if (urlRef.current === (location?.pathname || window.location.pathname)) return;
|
|
127
127
|
if (!i18nInstance.isInitialized) return;
|
|
128
128
|
const currentPathname = hasRouter && location ? location.pathname : window.location.pathname;
|
|
129
129
|
const currentSearch = hasRouter && location ? location.search : window.location.search;
|
|
@@ -132,17 +132,14 @@ function useClientSideRedirect(i18nInstance, localePathRedirect, languages, fall
|
|
|
132
132
|
const relativePath = currentPathname.replace(entryPath, '');
|
|
133
133
|
if ((0, external_utils_js_namespaceObject.shouldIgnoreRedirect)(relativePath, languages, ignoreRedirectRoutes)) return;
|
|
134
134
|
const pathDetection = (0, external_utils_js_namespaceObject.detectLanguageFromPath)(currentPathname, languages, localePathRedirect);
|
|
135
|
-
|
|
136
|
-
const targetLanguage = i18nInstance.language || fallbackLanguage || languages[0] || 'en';
|
|
135
|
+
const targetLanguage = pathDetection.language || i18nInstance.language || fallbackLanguage || languages[0] || 'en';
|
|
137
136
|
const newPath = (0, external_utils_js_namespaceObject.buildLocalizedUrl)(relativePath, targetLanguage, languages, localisedUrls);
|
|
138
137
|
const newUrl = entryPath + newPath + currentSearch + currentHash;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
else window.location.replace(newUrl);
|
|
145
|
-
}
|
|
138
|
+
urlRef.current = currentPathname;
|
|
139
|
+
if (newUrl !== currentPathname + currentSearch + currentHash) if (hasRouter && navigate && location) navigate(newUrl, {
|
|
140
|
+
replace: true
|
|
141
|
+
});
|
|
142
|
+
else window.location.replace(newUrl);
|
|
146
143
|
}, [
|
|
147
144
|
navigate,
|
|
148
145
|
location,
|
|
@@ -33,15 +33,15 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
33
33
|
useLocalizedLocation: ()=>useLocalizedLocation,
|
|
34
34
|
useLocalizedPaths: ()=>useLocalizedPaths
|
|
35
35
|
});
|
|
36
|
+
const i18n_runtime_extensions_namespaceObject = require("@modern-js/i18n-runtime-extensions");
|
|
36
37
|
const external_react_namespaceObject = require("react");
|
|
37
|
-
const localisedUrls_js_namespaceObject = require("../shared/localisedUrls.js");
|
|
38
38
|
const external_context_js_namespaceObject = require("./context.js");
|
|
39
39
|
const external_routerAdapter_js_namespaceObject = require("./routerAdapter.js");
|
|
40
40
|
const external_utils_js_namespaceObject = require("./utils.js");
|
|
41
41
|
const localizePath = (pathname, language, config)=>(0, external_utils_js_namespaceObject.buildLocalizedUrl)(pathname, language, config.languages, config.localisedUrls);
|
|
42
42
|
const canonicalPath = (target, config)=>{
|
|
43
43
|
const { pathname, search, hash } = (0, external_utils_js_namespaceObject.splitUrlTarget)(target);
|
|
44
|
-
const resolvedPath = (0,
|
|
44
|
+
const resolvedPath = (0, i18n_runtime_extensions_namespaceObject.canonicalTargetPathname)(pathname, config.languages, config.localisedUrls);
|
|
45
45
|
return `${resolvedPath}${search}${hash}`;
|
|
46
46
|
};
|
|
47
47
|
const useLocalizedPaths = ()=>{
|
|
@@ -31,6 +31,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
31
31
|
createI18nRootWrapper: ()=>createI18nRootWrapper
|
|
32
32
|
});
|
|
33
33
|
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
34
|
+
const i18n_runtime_extensions_namespaceObject = require("@modern-js/i18n-runtime-extensions");
|
|
34
35
|
const runtime_namespaceObject = require("@modern-js/runtime");
|
|
35
36
|
const head_namespaceObject = require("@modern-js/runtime/head");
|
|
36
37
|
const external_react_namespaceObject = require("react");
|
|
@@ -64,7 +65,7 @@ const createI18nRootWrapper = (options)=>(App)=>(props)=>{
|
|
|
64
65
|
lang
|
|
65
66
|
]);
|
|
66
67
|
(0, external_hooks_js_namespaceObject.useSdkResourcesLoader)(i18nInstance, setForceUpdate);
|
|
67
|
-
const synchronizeLanguage = (0,
|
|
68
|
+
const synchronizeLanguage = (0, i18n_runtime_extensions_namespaceObject.useLanguageSync)(i18nInstance, localePathRedirect, languages, location?.pathname, prevLangRef, setLang);
|
|
68
69
|
(0, external_hooks_js_namespaceObject.useClientSideRedirect)(i18nInstance, localePathRedirect, languages, fallbackLanguage, ignoreRedirectRoutes, localisedUrls);
|
|
69
70
|
const contextValue = (0, external_react_namespaceObject.useMemo)(()=>(0, external_hooks_js_namespaceObject.createContextValue)(lang, i18nInstance, entryName, languages, localePathRedirect, ignoreRedirectRoutes, localisedUrls, setLang, synchronizeLanguage), [
|
|
70
71
|
lang,
|
|
@@ -99,6 +100,7 @@ const createI18nRootWrapper = (options)=>(App)=>(props)=>{
|
|
|
99
100
|
}
|
|
100
101
|
}),
|
|
101
102
|
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_context_js_namespaceObject.ModernI18nProvider, {
|
|
103
|
+
i18nextProvider: I18nextProvider,
|
|
102
104
|
value: contextValue,
|
|
103
105
|
children: appContent
|
|
104
106
|
})
|
|
@@ -36,9 +36,9 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
36
36
|
shouldIgnoreRedirect: ()=>shouldIgnoreRedirect,
|
|
37
37
|
splitUrlTarget: ()=>splitUrlTarget
|
|
38
38
|
});
|
|
39
|
+
const i18n_runtime_extensions_namespaceObject = require("@modern-js/i18n-runtime-extensions");
|
|
39
40
|
const runtime_namespaceObject = require("@modern-js/runtime");
|
|
40
41
|
const context_namespaceObject = require("@modern-js/runtime/context");
|
|
41
|
-
const localisedUrls_js_namespaceObject = require("../shared/localisedUrls.js");
|
|
42
42
|
const getPathname = (context)=>{
|
|
43
43
|
if ((0, runtime_namespaceObject.isBrowser)()) return window.location.pathname;
|
|
44
44
|
return context.ssrContext?.request?.pathname || '/';
|
|
@@ -69,7 +69,7 @@ const splitUrlTarget = (target)=>{
|
|
|
69
69
|
};
|
|
70
70
|
const buildLocalizedUrl = (target, language, languages, localisedUrls)=>{
|
|
71
71
|
const { pathname, search, hash } = splitUrlTarget(target);
|
|
72
|
-
const localizedPathname = (0,
|
|
72
|
+
const localizedPathname = (0, i18n_runtime_extensions_namespaceObject.localiseTargetPathname)(pathname, language, languages, localisedUrls);
|
|
73
73
|
return `${localizedPathname}${search}${hash}`;
|
|
74
74
|
};
|
|
75
75
|
const detectLanguageFromPath = (pathname, languages, localePathRedirect)=>{
|
|
@@ -89,7 +89,7 @@ const detectLanguageFromPath = (pathname, languages, localePathRedirect)=>{
|
|
|
89
89
|
detected: false
|
|
90
90
|
};
|
|
91
91
|
};
|
|
92
|
-
const shouldIgnoreRedirect = (pathname, languages, ignoreRedirectRoutes)=>(0,
|
|
92
|
+
const shouldIgnoreRedirect = (pathname, languages, ignoreRedirectRoutes)=>(0, i18n_runtime_extensions_namespaceObject.shouldSkipLocaleRedirect)(pathname, languages, ignoreRedirectRoutes);
|
|
93
93
|
exports.buildLocalizedUrl = __webpack_exports__.buildLocalizedUrl;
|
|
94
94
|
exports.detectLanguageFromPath = __webpack_exports__.detectLanguageFromPath;
|
|
95
95
|
exports.getEntryPath = __webpack_exports__.getEntryPath;
|
package/dist/cjs/server/index.js
CHANGED
|
@@ -33,8 +33,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
33
33
|
i18nServerPlugin: ()=>i18nServerPlugin,
|
|
34
34
|
matchesApiPrefix: ()=>external_apiPrefix_js_namespaceObject.matchesApiPrefix
|
|
35
35
|
});
|
|
36
|
+
const i18n_runtime_extensions_namespaceObject = require("@modern-js/i18n-runtime-extensions");
|
|
36
37
|
const hono_namespaceObject = require("@modern-js/server-core/hono");
|
|
37
|
-
const localisedUrls_js_namespaceObject = require("../shared/localisedUrls.js");
|
|
38
38
|
const utils_js_namespaceObject = require("../shared/utils.js");
|
|
39
39
|
const external_apiPrefix_js_namespaceObject = require("./apiPrefix.js");
|
|
40
40
|
const external_detectorOptions_js_namespaceObject = require("./detectorOptions.js");
|
|
@@ -110,7 +110,7 @@ const i18nServerPlugin = (options)=>({
|
|
|
110
110
|
const localizedUrl = (0, external_redirectPolicy_js_namespaceObject.buildLocalizedUrl)(c.req, originUrlPath, targetLanguage, languages, localisedUrls);
|
|
111
111
|
return (0, external_redirectPolicy_js_namespaceObject.createLocaleRedirectResponse)(localizedUrl);
|
|
112
112
|
}
|
|
113
|
-
const localisedUrlsConfig = (0,
|
|
113
|
+
const localisedUrlsConfig = (0, i18n_runtime_extensions_namespaceObject.resolveLocalisedUrlsConfig)(localisedUrls);
|
|
114
114
|
if (localisedUrlsConfig.enabled) {
|
|
115
115
|
const expectedUrl = (0, external_redirectPolicy_js_namespaceObject.buildLocalizedUrl)(c.req, originUrlPath, language, languages, localisedUrls);
|
|
116
116
|
if (expectedUrl !== `${pathname}${url.search}${url.hash}`) return (0, external_redirectPolicy_js_namespaceObject.createLocaleRedirectResponse)(expectedUrl);
|
|
@@ -34,7 +34,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
34
34
|
isStaticResourceRequest: ()=>isStaticResourceRequest,
|
|
35
35
|
shouldIgnoreRedirect: ()=>shouldIgnoreRedirect
|
|
36
36
|
});
|
|
37
|
-
const
|
|
37
|
+
const i18n_runtime_extensions_namespaceObject = require("@modern-js/i18n-runtime-extensions");
|
|
38
38
|
const stripUrlPathPrefix = (pathname, urlPath)=>{
|
|
39
39
|
const basePath = urlPath.replace('/*', '');
|
|
40
40
|
if (!basePath || '/' === basePath) return pathname;
|
|
@@ -43,13 +43,13 @@ const stripUrlPathPrefix = (pathname, urlPath)=>{
|
|
|
43
43
|
};
|
|
44
44
|
const shouldIgnoreRedirect = (pathname, urlPath, ignoreRedirectRoutes)=>{
|
|
45
45
|
const remainingPath = stripUrlPathPrefix(pathname, urlPath);
|
|
46
|
-
return (0,
|
|
46
|
+
return (0, i18n_runtime_extensions_namespaceObject.shouldSkipLocaleRedirect)(remainingPath, [], ignoreRedirectRoutes);
|
|
47
47
|
};
|
|
48
48
|
const isStaticResourceRequest = (pathname, staticRoutePrefixes, languages = [])=>{
|
|
49
|
-
if ((0,
|
|
50
|
-
const matchesStaticRoutePrefix = (targetPathname)=>staticRoutePrefixes.some((prefix)=>(0,
|
|
49
|
+
if ((0, i18n_runtime_extensions_namespaceObject.isDefaultLocaleRedirectSkipPath)(pathname, languages)) return true;
|
|
50
|
+
const matchesStaticRoutePrefix = (targetPathname)=>staticRoutePrefixes.some((prefix)=>(0, i18n_runtime_extensions_namespaceObject.matchesPathPrefix)(targetPathname, prefix));
|
|
51
51
|
if (matchesStaticRoutePrefix(pathname)) return true;
|
|
52
|
-
const pathWithoutLanguage = (0,
|
|
52
|
+
const pathWithoutLanguage = (0, i18n_runtime_extensions_namespaceObject.stripLanguagePrefix)(pathname, languages);
|
|
53
53
|
return pathWithoutLanguage !== pathname && matchesStaticRoutePrefix(pathWithoutLanguage);
|
|
54
54
|
};
|
|
55
55
|
const getLanguageFromPath = (req, urlPath, languages)=>{
|
|
@@ -66,7 +66,7 @@ const buildLocalizedUrl = (req, urlPath, language, languages, localisedUrls)=>{
|
|
|
66
66
|
const pathname = url.pathname;
|
|
67
67
|
const basePath = urlPath.replace('/*', '');
|
|
68
68
|
const remainingPath = stripUrlPathPrefix(pathname, urlPath);
|
|
69
|
-
const newPathname = (0,
|
|
69
|
+
const newPathname = (0, i18n_runtime_extensions_namespaceObject.localiseTargetPathname)(remainingPath, language, languages, localisedUrls);
|
|
70
70
|
const suffix = `${url.search}${url.hash}`;
|
|
71
71
|
const localizedUrl = '/' === basePath ? newPathname + suffix : basePath + newPathname + suffix;
|
|
72
72
|
return localizedUrl;
|
package/dist/esm/cli/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { applyLocalisedUrlsToRoutes, resolveLocalisedUrlsConfig } from "@modern-js/i18n-runtime-extensions";
|
|
1
2
|
import { getPublicDirRoutePrefixes } from "@modern-js/server-core";
|
|
2
|
-
import { applyLocalisedUrlsToRoutes, resolveLocalisedUrlsConfig } from "../shared/localisedUrls.mjs";
|
|
3
3
|
import { getBackendOptions, getLocaleDetectionOptions } from "../shared/utils.mjs";
|
|
4
4
|
import { applyDetectedBackendPaths, detectLocalesDirectory } from "./locales.mjs";
|
|
5
5
|
import "../runtime/types.mjs";
|
|
@@ -4,18 +4,27 @@ import { changeModernI18nLanguage, getPathLanguage, isI18nLanguageSupported, isI
|
|
|
4
4
|
import { getActualI18nextInstance } from "./i18n/instance.mjs";
|
|
5
5
|
import { useI18nRouterAdapter } from "./routerAdapter.mjs";
|
|
6
6
|
const modernI18nContextKey = Symbol.for('@modern-js/plugin-i18n/runtime/ModernI18nContext');
|
|
7
|
-
const
|
|
7
|
+
const reactI18nextProviderContextKey = Symbol.for('@modern-js/plugin-i18n/runtime/ReactI18nextProviderContext');
|
|
8
|
+
const getGlobalContext = (key, defaultValue)=>{
|
|
8
9
|
const globalStore = globalThis;
|
|
9
|
-
globalStore[
|
|
10
|
-
return globalStore[
|
|
10
|
+
globalStore[key] ??= /*#__PURE__*/ createContext(defaultValue);
|
|
11
|
+
return globalStore[key];
|
|
11
12
|
};
|
|
12
|
-
const ModernI18nContext =
|
|
13
|
-
const
|
|
13
|
+
const ModernI18nContext = getGlobalContext(modernI18nContextKey, null);
|
|
14
|
+
const ReactI18nextProviderContext = getGlobalContext(reactI18nextProviderContextKey, null);
|
|
15
|
+
const ModernI18nProvider = ({ children, i18nextProvider, value })=>{
|
|
16
|
+
const content = /*#__PURE__*/ jsx(ModernI18nContext.Provider, {
|
|
14
17
|
value: value,
|
|
15
18
|
children: children
|
|
16
19
|
});
|
|
20
|
+
return void 0 === i18nextProvider ? content : /*#__PURE__*/ jsx(ReactI18nextProviderContext.Provider, {
|
|
21
|
+
value: i18nextProvider,
|
|
22
|
+
children: content
|
|
23
|
+
});
|
|
24
|
+
};
|
|
17
25
|
const FederatedI18nBoundary = ({ children, defaultNamespace, fallbackLanguage, resources, supportedLanguages })=>{
|
|
18
26
|
const parent = useContext(ModernI18nContext);
|
|
27
|
+
const I18nextProvider = useContext(ReactI18nextProviderContext);
|
|
19
28
|
if (!parent) throw new Error('FederatedI18nBoundary must be used within ModernI18nProvider');
|
|
20
29
|
const languages = supportedLanguages ?? parent.languages ?? Object.keys(resources);
|
|
21
30
|
const scopedInstance = useMemo(()=>{
|
|
@@ -62,10 +71,14 @@ const FederatedI18nBoundary = ({ children, defaultNamespace, fallbackLanguage, r
|
|
|
62
71
|
parent,
|
|
63
72
|
scopedInstance
|
|
64
73
|
]);
|
|
65
|
-
|
|
74
|
+
const scopedContent = /*#__PURE__*/ jsx(ModernI18nProvider, {
|
|
66
75
|
value: value,
|
|
67
76
|
children: children
|
|
68
77
|
});
|
|
78
|
+
return I18nextProvider ? /*#__PURE__*/ jsx(I18nextProvider, {
|
|
79
|
+
i18n: scopedInstance,
|
|
80
|
+
children: scopedContent
|
|
81
|
+
}) : scopedContent;
|
|
69
82
|
};
|
|
70
83
|
const useModernI18n = ()=>{
|
|
71
84
|
const context = useContext(ModernI18nContext);
|
|
@@ -79,7 +79,7 @@ function useSdkResourcesLoader(i18nInstance, setForceUpdate) {
|
|
|
79
79
|
]);
|
|
80
80
|
}
|
|
81
81
|
function useClientSideRedirect(i18nInstance, localePathRedirect, languages, fallbackLanguage, ignoreRedirectRoutes, localisedUrls) {
|
|
82
|
-
const
|
|
82
|
+
const urlRef = useRef('');
|
|
83
83
|
const { navigate, location, hasRouter } = useI18nRouterAdapter();
|
|
84
84
|
useEffect(()=>{
|
|
85
85
|
if ('browser' !== process.env.MODERN_TARGET) return;
|
|
@@ -88,7 +88,7 @@ function useClientSideRedirect(i18nInstance, localePathRedirect, languages, fall
|
|
|
88
88
|
const ssrData = window._SSR_DATA;
|
|
89
89
|
if (ssrData) return;
|
|
90
90
|
} catch {}
|
|
91
|
-
if (
|
|
91
|
+
if (urlRef.current === (location?.pathname || window.location.pathname)) return;
|
|
92
92
|
if (!i18nInstance.isInitialized) return;
|
|
93
93
|
const currentPathname = hasRouter && location ? location.pathname : window.location.pathname;
|
|
94
94
|
const currentSearch = hasRouter && location ? location.search : window.location.search;
|
|
@@ -97,17 +97,14 @@ function useClientSideRedirect(i18nInstance, localePathRedirect, languages, fall
|
|
|
97
97
|
const relativePath = currentPathname.replace(entryPath, '');
|
|
98
98
|
if (shouldIgnoreRedirect(relativePath, languages, ignoreRedirectRoutes)) return;
|
|
99
99
|
const pathDetection = detectLanguageFromPath(currentPathname, languages, localePathRedirect);
|
|
100
|
-
|
|
101
|
-
const targetLanguage = i18nInstance.language || fallbackLanguage || languages[0] || 'en';
|
|
100
|
+
const targetLanguage = pathDetection.language || i18nInstance.language || fallbackLanguage || languages[0] || 'en';
|
|
102
101
|
const newPath = buildLocalizedUrl(relativePath, targetLanguage, languages, localisedUrls);
|
|
103
102
|
const newUrl = entryPath + newPath + currentSearch + currentHash;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
else window.location.replace(newUrl);
|
|
110
|
-
}
|
|
103
|
+
urlRef.current = currentPathname;
|
|
104
|
+
if (newUrl !== currentPathname + currentSearch + currentHash) if (hasRouter && navigate && location) navigate(newUrl, {
|
|
105
|
+
replace: true
|
|
106
|
+
});
|
|
107
|
+
else window.location.replace(newUrl);
|
|
111
108
|
}, [
|
|
112
109
|
navigate,
|
|
113
110
|
location,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { canonicalTargetPathname } from "@modern-js/i18n-runtime-extensions";
|
|
1
2
|
import { useMemo } from "react";
|
|
2
|
-
import { canonicalTargetPathname } from "../shared/localisedUrls.mjs";
|
|
3
3
|
import { useModernI18n } from "./context.mjs";
|
|
4
4
|
import { useI18nRouterAdapter } from "./routerAdapter.mjs";
|
|
5
5
|
import { buildLocalizedUrl, splitUrlTarget } from "./utils.mjs";
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useLanguageSync } from "@modern-js/i18n-runtime-extensions";
|
|
2
3
|
import { RuntimeContext } from "@modern-js/runtime";
|
|
3
4
|
import { Helmet } from "@modern-js/runtime/head";
|
|
4
5
|
import { useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
5
6
|
import { ModernI18nProvider } from "./context.mjs";
|
|
6
|
-
import { createContextValue, useClientSideRedirect,
|
|
7
|
+
import { createContextValue, useClientSideRedirect, useSdkResourcesLoader } from "./hooks.mjs";
|
|
7
8
|
import { getI18nextInstanceForProvider } from "./i18n/instance.mjs";
|
|
8
9
|
import { useI18nRouterAdapter } from "./routerAdapter.mjs";
|
|
9
10
|
const createI18nRootWrapper = (options)=>(App)=>(props)=>{
|
|
@@ -67,6 +68,7 @@ const createI18nRootWrapper = (options)=>(App)=>(props)=>{
|
|
|
67
68
|
}
|
|
68
69
|
}),
|
|
69
70
|
/*#__PURE__*/ jsx(ModernI18nProvider, {
|
|
71
|
+
i18nextProvider: I18nextProvider,
|
|
70
72
|
value: contextValue,
|
|
71
73
|
children: appContent
|
|
72
74
|
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { localiseTargetPathname, shouldSkipLocaleRedirect } from "@modern-js/i18n-runtime-extensions";
|
|
1
2
|
import { isBrowser } from "@modern-js/runtime";
|
|
2
3
|
import { getGlobalBasename } from "@modern-js/runtime/context";
|
|
3
|
-
import { localiseTargetPathname, shouldSkipLocaleRedirect } from "../shared/localisedUrls.mjs";
|
|
4
4
|
const getPathname = (context)=>{
|
|
5
5
|
if (isBrowser()) return window.location.pathname;
|
|
6
6
|
return context.ssrContext?.request?.pathname || '/';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { resolveLocalisedUrlsConfig } from "
|
|
1
|
+
import { resolveLocalisedUrlsConfig } from "@modern-js/i18n-runtime-extensions";
|
|
2
2
|
import { getLocaleDetectionOptions } from "../shared/utils.mjs";
|
|
3
3
|
import { collectApiPrefixes, matchesApiPrefix } from "./apiPrefix.mjs";
|
|
4
4
|
import { convertToHonoLanguageDetectorOptions } from "./detectorOptions.mjs";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isDefaultLocaleRedirectSkipPath, localiseTargetPathname, matchesPathPrefix, shouldSkipLocaleRedirect, stripLanguagePrefix } from "
|
|
1
|
+
import { isDefaultLocaleRedirectSkipPath, localiseTargetPathname, matchesPathPrefix, shouldSkipLocaleRedirect, stripLanguagePrefix } from "@modern-js/i18n-runtime-extensions";
|
|
2
2
|
const stripUrlPathPrefix = (pathname, urlPath)=>{
|
|
3
3
|
const basePath = urlPath.replace('/*', '');
|
|
4
4
|
if (!basePath || '/' === basePath) return pathname;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
+
import { applyLocalisedUrlsToRoutes, resolveLocalisedUrlsConfig } from "@modern-js/i18n-runtime-extensions";
|
|
2
3
|
import { getPublicDirRoutePrefixes } from "@modern-js/server-core";
|
|
3
|
-
import { applyLocalisedUrlsToRoutes, resolveLocalisedUrlsConfig } from "../shared/localisedUrls.mjs";
|
|
4
4
|
import { getBackendOptions, getLocaleDetectionOptions } from "../shared/utils.mjs";
|
|
5
5
|
import { applyDetectedBackendPaths, detectLocalesDirectory } from "./locales.mjs";
|
|
6
6
|
import "../runtime/types.mjs";
|
|
@@ -5,18 +5,27 @@ import { changeModernI18nLanguage, getPathLanguage, isI18nLanguageSupported, isI
|
|
|
5
5
|
import { getActualI18nextInstance } from "./i18n/instance.mjs";
|
|
6
6
|
import { useI18nRouterAdapter } from "./routerAdapter.mjs";
|
|
7
7
|
const modernI18nContextKey = Symbol.for('@modern-js/plugin-i18n/runtime/ModernI18nContext');
|
|
8
|
-
const
|
|
8
|
+
const reactI18nextProviderContextKey = Symbol.for('@modern-js/plugin-i18n/runtime/ReactI18nextProviderContext');
|
|
9
|
+
const getGlobalContext = (key, defaultValue)=>{
|
|
9
10
|
const globalStore = globalThis;
|
|
10
|
-
globalStore[
|
|
11
|
-
return globalStore[
|
|
11
|
+
globalStore[key] ??= /*#__PURE__*/ createContext(defaultValue);
|
|
12
|
+
return globalStore[key];
|
|
12
13
|
};
|
|
13
|
-
const ModernI18nContext =
|
|
14
|
-
const
|
|
14
|
+
const ModernI18nContext = getGlobalContext(modernI18nContextKey, null);
|
|
15
|
+
const ReactI18nextProviderContext = getGlobalContext(reactI18nextProviderContextKey, null);
|
|
16
|
+
const ModernI18nProvider = ({ children, i18nextProvider, value })=>{
|
|
17
|
+
const content = /*#__PURE__*/ jsx(ModernI18nContext.Provider, {
|
|
15
18
|
value: value,
|
|
16
19
|
children: children
|
|
17
20
|
});
|
|
21
|
+
return void 0 === i18nextProvider ? content : /*#__PURE__*/ jsx(ReactI18nextProviderContext.Provider, {
|
|
22
|
+
value: i18nextProvider,
|
|
23
|
+
children: content
|
|
24
|
+
});
|
|
25
|
+
};
|
|
18
26
|
const FederatedI18nBoundary = ({ children, defaultNamespace, fallbackLanguage, resources, supportedLanguages })=>{
|
|
19
27
|
const parent = useContext(ModernI18nContext);
|
|
28
|
+
const I18nextProvider = useContext(ReactI18nextProviderContext);
|
|
20
29
|
if (!parent) throw new Error('FederatedI18nBoundary must be used within ModernI18nProvider');
|
|
21
30
|
const languages = supportedLanguages ?? parent.languages ?? Object.keys(resources);
|
|
22
31
|
const scopedInstance = useMemo(()=>{
|
|
@@ -63,10 +72,14 @@ const FederatedI18nBoundary = ({ children, defaultNamespace, fallbackLanguage, r
|
|
|
63
72
|
parent,
|
|
64
73
|
scopedInstance
|
|
65
74
|
]);
|
|
66
|
-
|
|
75
|
+
const scopedContent = /*#__PURE__*/ jsx(ModernI18nProvider, {
|
|
67
76
|
value: value,
|
|
68
77
|
children: children
|
|
69
78
|
});
|
|
79
|
+
return I18nextProvider ? /*#__PURE__*/ jsx(I18nextProvider, {
|
|
80
|
+
i18n: scopedInstance,
|
|
81
|
+
children: scopedContent
|
|
82
|
+
}) : scopedContent;
|
|
70
83
|
};
|
|
71
84
|
const useModernI18n = ()=>{
|
|
72
85
|
const context = useContext(ModernI18nContext);
|
|
@@ -80,7 +80,7 @@ function useSdkResourcesLoader(i18nInstance, setForceUpdate) {
|
|
|
80
80
|
]);
|
|
81
81
|
}
|
|
82
82
|
function useClientSideRedirect(i18nInstance, localePathRedirect, languages, fallbackLanguage, ignoreRedirectRoutes, localisedUrls) {
|
|
83
|
-
const
|
|
83
|
+
const urlRef = useRef('');
|
|
84
84
|
const { navigate, location, hasRouter } = useI18nRouterAdapter();
|
|
85
85
|
useEffect(()=>{
|
|
86
86
|
if ('browser' !== process.env.MODERN_TARGET) return;
|
|
@@ -89,7 +89,7 @@ function useClientSideRedirect(i18nInstance, localePathRedirect, languages, fall
|
|
|
89
89
|
const ssrData = window._SSR_DATA;
|
|
90
90
|
if (ssrData) return;
|
|
91
91
|
} catch {}
|
|
92
|
-
if (
|
|
92
|
+
if (urlRef.current === (location?.pathname || window.location.pathname)) return;
|
|
93
93
|
if (!i18nInstance.isInitialized) return;
|
|
94
94
|
const currentPathname = hasRouter && location ? location.pathname : window.location.pathname;
|
|
95
95
|
const currentSearch = hasRouter && location ? location.search : window.location.search;
|
|
@@ -98,17 +98,14 @@ function useClientSideRedirect(i18nInstance, localePathRedirect, languages, fall
|
|
|
98
98
|
const relativePath = currentPathname.replace(entryPath, '');
|
|
99
99
|
if (shouldIgnoreRedirect(relativePath, languages, ignoreRedirectRoutes)) return;
|
|
100
100
|
const pathDetection = detectLanguageFromPath(currentPathname, languages, localePathRedirect);
|
|
101
|
-
|
|
102
|
-
const targetLanguage = i18nInstance.language || fallbackLanguage || languages[0] || 'en';
|
|
101
|
+
const targetLanguage = pathDetection.language || i18nInstance.language || fallbackLanguage || languages[0] || 'en';
|
|
103
102
|
const newPath = buildLocalizedUrl(relativePath, targetLanguage, languages, localisedUrls);
|
|
104
103
|
const newUrl = entryPath + newPath + currentSearch + currentHash;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
else window.location.replace(newUrl);
|
|
111
|
-
}
|
|
104
|
+
urlRef.current = currentPathname;
|
|
105
|
+
if (newUrl !== currentPathname + currentSearch + currentHash) if (hasRouter && navigate && location) navigate(newUrl, {
|
|
106
|
+
replace: true
|
|
107
|
+
});
|
|
108
|
+
else window.location.replace(newUrl);
|
|
112
109
|
}, [
|
|
113
110
|
navigate,
|
|
114
111
|
location,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
+
import { canonicalTargetPathname } from "@modern-js/i18n-runtime-extensions";
|
|
2
3
|
import { useMemo } from "react";
|
|
3
|
-
import { canonicalTargetPathname } from "../shared/localisedUrls.mjs";
|
|
4
4
|
import { useModernI18n } from "./context.mjs";
|
|
5
5
|
import { useI18nRouterAdapter } from "./routerAdapter.mjs";
|
|
6
6
|
import { buildLocalizedUrl, splitUrlTarget } from "./utils.mjs";
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useLanguageSync } from "@modern-js/i18n-runtime-extensions";
|
|
3
4
|
import { RuntimeContext } from "@modern-js/runtime";
|
|
4
5
|
import { Helmet } from "@modern-js/runtime/head";
|
|
5
6
|
import { useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
6
7
|
import { ModernI18nProvider } from "./context.mjs";
|
|
7
|
-
import { createContextValue, useClientSideRedirect,
|
|
8
|
+
import { createContextValue, useClientSideRedirect, useSdkResourcesLoader } from "./hooks.mjs";
|
|
8
9
|
import { getI18nextInstanceForProvider } from "./i18n/instance.mjs";
|
|
9
10
|
import { useI18nRouterAdapter } from "./routerAdapter.mjs";
|
|
10
11
|
const createI18nRootWrapper = (options)=>(App)=>(props)=>{
|
|
@@ -68,6 +69,7 @@ const createI18nRootWrapper = (options)=>(App)=>(props)=>{
|
|
|
68
69
|
}
|
|
69
70
|
}),
|
|
70
71
|
/*#__PURE__*/ jsx(ModernI18nProvider, {
|
|
72
|
+
i18nextProvider: I18nextProvider,
|
|
71
73
|
value: contextValue,
|
|
72
74
|
children: appContent
|
|
73
75
|
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
+
import { localiseTargetPathname, shouldSkipLocaleRedirect } from "@modern-js/i18n-runtime-extensions";
|
|
2
3
|
import { isBrowser } from "@modern-js/runtime";
|
|
3
4
|
import { getGlobalBasename } from "@modern-js/runtime/context";
|
|
4
|
-
import { localiseTargetPathname, shouldSkipLocaleRedirect } from "../shared/localisedUrls.mjs";
|
|
5
5
|
const getPathname = (context)=>{
|
|
6
6
|
if (isBrowser()) return window.location.pathname;
|
|
7
7
|
return context.ssrContext?.request?.pathname || '/';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import { resolveLocalisedUrlsConfig } from "
|
|
2
|
+
import { resolveLocalisedUrlsConfig } from "@modern-js/i18n-runtime-extensions";
|
|
3
3
|
import { getLocaleDetectionOptions } from "../shared/utils.mjs";
|
|
4
4
|
import { collectApiPrefixes, matchesApiPrefix } from "./apiPrefix.mjs";
|
|
5
5
|
import { convertToHonoLanguageDetectorOptions } from "./detectorOptions.mjs";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import { isDefaultLocaleRedirectSkipPath, localiseTargetPathname, matchesPathPrefix, shouldSkipLocaleRedirect, stripLanguagePrefix } from "
|
|
2
|
+
import { isDefaultLocaleRedirectSkipPath, localiseTargetPathname, matchesPathPrefix, shouldSkipLocaleRedirect, stripLanguagePrefix } from "@modern-js/i18n-runtime-extensions";
|
|
3
3
|
const stripUrlPathPrefix = (pathname, urlPath)=>{
|
|
4
4
|
const basePath = urlPath.replace('/*', '');
|
|
5
5
|
if (!basePath || '/' === basePath) return pathname;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { LocalisedUrlsOption } from '@modern-js/i18n-runtime-extensions';
|
|
2
|
+
import type { ComponentType, FC, ReactNode } from 'react';
|
|
3
3
|
import type { I18nInstance } from './i18n';
|
|
4
4
|
import type { Resources } from './i18n/instance';
|
|
5
5
|
interface ModernI18nContextValue {
|
|
@@ -15,6 +15,7 @@ interface ModernI18nContextValue {
|
|
|
15
15
|
}
|
|
16
16
|
interface ModernI18nProviderProps {
|
|
17
17
|
children: ReactNode;
|
|
18
|
+
i18nextProvider?: ComponentType<any> | null;
|
|
18
19
|
value: ModernI18nContextValue;
|
|
19
20
|
}
|
|
20
21
|
export declare const ModernI18nProvider: FC<ModernI18nProviderProps>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { LocalisedUrlsOption } from '@modern-js/i18n-runtime-extensions';
|
|
1
2
|
import type React from 'react';
|
|
2
|
-
import type { LocalisedUrlsOption } from '../shared/localisedUrls';
|
|
3
3
|
import type { I18nInstance } from './i18n';
|
|
4
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): {
|
|
5
5
|
language: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { LocalisedUrlsOption } from '@modern-js/i18n-runtime-extensions';
|
|
1
2
|
import type { LanguageDetectorOptions, Resources } from '../runtime/i18n/instance';
|
|
2
|
-
import type { LocalisedUrlsOption } from './localisedUrls';
|
|
3
3
|
export interface BaseLocaleDetectionOptions {
|
|
4
4
|
localePathRedirect?: boolean;
|
|
5
5
|
i18nextDetector?: boolean;
|