@bleedingdev/modern-js-plugin-i18n 3.9.0-ultramodern.2 → 3.9.0-ultramodern.21
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 +10 -21
- package/dist/cjs/cli/localisedRoutes.js +47 -0
- package/dist/cjs/runtime/Link.js +19 -32
- package/dist/cjs/runtime/context.js +30 -73
- package/dist/cjs/runtime/contextHelpers.js +5 -5
- package/dist/cjs/runtime/contexts.js +49 -0
- package/dist/cjs/runtime/core.js +27 -14
- package/dist/cjs/runtime/hooks.js +7 -8
- package/dist/cjs/runtime/localizedPaths.js +11 -9
- package/dist/cjs/runtime/navigation.js +48 -0
- package/dist/cjs/runtime/providerComposition.js +37 -13
- package/dist/cjs/runtime/routerAdapter.js +33 -140
- package/dist/cjs/runtime/sharedContexts.js +43 -0
- package/dist/cjs/runtime/utils.js +21 -19
- package/dist/cjs/server/defaultUrlStrategy.js +48 -0
- package/dist/cjs/server/index.js +11 -7
- package/dist/cjs/server/mappedUrlStrategy.js +43 -0
- package/dist/cjs/server/redirectPolicy.js +33 -24
- package/dist/cjs/shared/mappedUrlStrategy.js +63 -0
- package/dist/cjs/shared/urlStrategy.js +48 -0
- package/dist/esm/cli/index.mjs +10 -21
- package/dist/esm/cli/localisedRoutes.mjs +9 -0
- package/dist/esm/runtime/Link.mjs +19 -32
- package/dist/esm/runtime/context.mjs +20 -72
- package/dist/esm/runtime/contextHelpers.mjs +5 -5
- package/dist/esm/runtime/contexts.mjs +5 -0
- package/dist/esm/runtime/core.mjs +13 -6
- package/dist/esm/runtime/hooks.mjs +7 -8
- package/dist/esm/runtime/localizedPaths.mjs +11 -9
- package/dist/esm/runtime/navigation.mjs +7 -0
- package/dist/esm/runtime/providerComposition.mjs +38 -14
- package/dist/esm/runtime/routerAdapter.mjs +28 -141
- package/dist/esm/runtime/sharedContexts.mjs +1 -0
- package/dist/esm/runtime/utils.mjs +19 -17
- package/dist/esm/server/defaultUrlStrategy.mjs +7 -0
- package/dist/esm/server/index.mjs +11 -7
- package/dist/esm/server/mappedUrlStrategy.mjs +1 -0
- package/dist/esm/server/redirectPolicy.mjs +33 -24
- package/dist/esm/shared/mappedUrlStrategy.mjs +19 -0
- package/dist/esm/shared/urlStrategy.mjs +7 -0
- package/dist/esm-node/cli/index.mjs +10 -21
- package/dist/esm-node/cli/localisedRoutes.mjs +10 -0
- package/dist/esm-node/runtime/Link.mjs +19 -32
- package/dist/esm-node/runtime/context.mjs +20 -72
- package/dist/esm-node/runtime/contextHelpers.mjs +5 -5
- package/dist/esm-node/runtime/contexts.mjs +6 -0
- package/dist/esm-node/runtime/core.mjs +13 -6
- package/dist/esm-node/runtime/hooks.mjs +7 -8
- package/dist/esm-node/runtime/localizedPaths.mjs +11 -9
- package/dist/esm-node/runtime/navigation.mjs +8 -0
- package/dist/esm-node/runtime/providerComposition.mjs +38 -14
- package/dist/esm-node/runtime/routerAdapter.mjs +28 -141
- package/dist/esm-node/runtime/sharedContexts.mjs +2 -0
- package/dist/esm-node/runtime/utils.mjs +19 -17
- package/dist/esm-node/server/defaultUrlStrategy.mjs +8 -0
- package/dist/esm-node/server/index.mjs +11 -7
- package/dist/esm-node/server/mappedUrlStrategy.mjs +2 -0
- package/dist/esm-node/server/redirectPolicy.mjs +33 -24
- package/dist/esm-node/shared/mappedUrlStrategy.mjs +20 -0
- package/dist/esm-node/shared/urlStrategy.mjs +8 -0
- package/dist/types/cli/localisedRoutes.d.ts +19 -0
- package/dist/types/runtime/context.d.ts +8 -11
- package/dist/types/runtime/contextHelpers.d.ts +2 -2
- package/dist/types/runtime/contexts.d.ts +6 -0
- package/dist/types/runtime/core.d.ts +12 -2
- package/dist/types/runtime/hooks.d.ts +4 -5
- package/dist/types/runtime/localizedPaths.d.ts +4 -4
- package/dist/types/runtime/navigation.d.ts +10 -0
- package/dist/types/runtime/providerComposition.d.ts +13 -1
- package/dist/types/runtime/routerAdapter.d.ts +23 -6
- package/dist/types/runtime/sharedContexts.d.ts +1 -0
- package/dist/types/runtime/utils.d.ts +4 -12
- package/dist/types/server/defaultUrlStrategy.d.ts +11 -0
- package/dist/types/server/index.d.ts +2 -0
- package/dist/types/server/mappedUrlStrategy.d.ts +7 -0
- package/dist/types/server/redirectPolicy.d.ts +5 -13
- package/dist/types/shared/mappedUrlStrategy.d.ts +27 -0
- package/dist/types/shared/type.d.ts +7 -11
- package/dist/types/shared/urlStrategy.d.ts +18 -0
- package/package.json +42 -19
- package/rslib.config.mts +8 -1
- package/rstest.config.mts +6 -5
- package/src/cli/index.ts +42 -42
- package/src/cli/localisedRoutes.ts +53 -0
- package/src/runtime/Link.tsx +20 -40
- package/src/runtime/context.tsx +33 -157
- package/src/runtime/contextHelpers.ts +7 -5
- package/src/runtime/contexts.ts +16 -0
- package/src/runtime/core.tsx +53 -6
- package/src/runtime/hooks.ts +14 -9
- package/src/runtime/i18n/instance.ts +1 -2
- package/src/runtime/localizedPaths.ts +24 -19
- package/src/runtime/navigation.tsx +20 -0
- package/src/runtime/providerComposition.tsx +71 -23
- package/src/runtime/routerAdapter.tsx +65 -339
- package/src/runtime/sharedContexts.ts +8 -0
- package/src/runtime/utils.ts +49 -31
- package/src/server/defaultUrlStrategy.ts +27 -0
- package/src/server/index.ts +39 -9
- package/src/server/mappedUrlStrategy.ts +10 -0
- package/src/server/redirectPolicy.ts +85 -70
- package/src/shared/mappedUrlStrategy.ts +59 -0
- package/src/shared/type.ts +7 -11
- package/src/shared/urlStrategy.ts +38 -0
- package/tests/backendDefaults.test.ts +2 -23
- package/tests/defaultUrlStrategy.test.ts +107 -0
- package/tests/federatedI18nBoundaryResolver.test.tsx +65 -0
- package/tests/i18nUtils.test.ts +31 -65
- package/tests/link.test.tsx +13 -511
- package/tests/localisedRouteGeneration.test.ts +200 -0
- package/tests/localisedUrls.test.ts +16 -208
- package/tests/mappedUrlStrategyDerivation.test.ts +62 -0
- package/tests/navigation.test.tsx +403 -0
- package/tests/reactI18nextRuntimeBoundary.test.ts +8 -83
- package/tests/redirectPolicy.test.ts +89 -27
- package/tests/routerAdapter.test.tsx +98 -1171
- package/tests/urlStrategySerialization.test.ts +122 -0
- package/tsconfig.json +4 -2
- package/tests/federatedI18nBoundary.client.test.tsx +0 -129
- package/tests/federatedI18nBoundary.test.tsx +0 -132
- package/tests/linkTypes.test.ts +0 -59
- package/tests/localisedUrlRewriteMatrix.fork.test.ts +0 -147
- package/tests/peerCohort.test.ts +0 -25
- package/tests/type-fixture/fixture-globals.d.ts +0 -11
- package/tests/type-fixture/i18nInstanceTypes.fixture.ts +0 -29
- package/tests/type-fixture/linkTypes.fixture.tsx +0 -51
- package/tests/type-fixture/tsconfig.json +0 -16
|
@@ -33,23 +33,25 @@ __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");
|
|
37
36
|
const external_react_namespaceObject = require("react");
|
|
38
37
|
const external_context_js_namespaceObject = require("./context.js");
|
|
39
38
|
const external_routerAdapter_js_namespaceObject = require("./routerAdapter.js");
|
|
40
39
|
const external_utils_js_namespaceObject = require("./utils.js");
|
|
41
|
-
const localizePath = (pathname, language, config)=>(0, external_utils_js_namespaceObject.buildLocalizedUrl)(pathname, language, config.languages, config.
|
|
40
|
+
const localizePath = (pathname, language, config)=>(0, external_utils_js_namespaceObject.buildLocalizedUrl)(pathname, language, config.languages, config.urlStrategy);
|
|
42
41
|
const canonicalPath = (target, config)=>{
|
|
43
42
|
const { pathname, search, hash } = (0, external_utils_js_namespaceObject.splitUrlTarget)(target);
|
|
44
|
-
|
|
43
|
+
if (config.urlStrategy) return `${config.urlStrategy.canonicalPathname(pathname, config.languages)}${search}${hash}`;
|
|
44
|
+
const segments = pathname.split('/').filter(Boolean);
|
|
45
|
+
if (segments[0] && config.languages.some((language)=>language.toLowerCase() === segments[0].toLowerCase())) segments.shift();
|
|
46
|
+
const resolvedPath = `/${segments.join('/')}`;
|
|
45
47
|
return `${resolvedPath}${search}${hash}`;
|
|
46
48
|
};
|
|
47
49
|
const useLocalizedPaths = ()=>{
|
|
48
|
-
const { supportedLanguages,
|
|
50
|
+
const { supportedLanguages, urlStrategy } = (0, external_context_js_namespaceObject.useModernI18n)();
|
|
49
51
|
return (0, external_react_namespaceObject.useMemo)(()=>{
|
|
50
52
|
const config = {
|
|
51
53
|
languages: supportedLanguages,
|
|
52
|
-
|
|
54
|
+
urlStrategy
|
|
53
55
|
};
|
|
54
56
|
return {
|
|
55
57
|
localizePath: (pathname, language)=>localizePath(pathname, language, config),
|
|
@@ -57,11 +59,11 @@ const useLocalizedPaths = ()=>{
|
|
|
57
59
|
};
|
|
58
60
|
}, [
|
|
59
61
|
supportedLanguages,
|
|
60
|
-
|
|
62
|
+
urlStrategy
|
|
61
63
|
]);
|
|
62
64
|
};
|
|
63
65
|
const useLocalizedLocation = ()=>{
|
|
64
|
-
const { language, supportedLanguages,
|
|
66
|
+
const { language, supportedLanguages, urlStrategy } = (0, external_context_js_namespaceObject.useModernI18n)();
|
|
65
67
|
const { location } = (0, external_routerAdapter_js_namespaceObject.useI18nRouterAdapter)();
|
|
66
68
|
const pathname = location?.pathname ?? '/';
|
|
67
69
|
const search = location?.search ?? '';
|
|
@@ -69,7 +71,7 @@ const useLocalizedLocation = ()=>{
|
|
|
69
71
|
return (0, external_react_namespaceObject.useMemo)(()=>{
|
|
70
72
|
const config = {
|
|
71
73
|
languages: supportedLanguages,
|
|
72
|
-
|
|
74
|
+
urlStrategy
|
|
73
75
|
};
|
|
74
76
|
const alternates = {};
|
|
75
77
|
for (const supportedLanguage of supportedLanguages)alternates[supportedLanguage] = `${localizePath(pathname, supportedLanguage, config)}${search}${hash}`;
|
|
@@ -81,7 +83,7 @@ const useLocalizedLocation = ()=>{
|
|
|
81
83
|
}, [
|
|
82
84
|
language,
|
|
83
85
|
supportedLanguages,
|
|
84
|
-
|
|
86
|
+
urlStrategy,
|
|
85
87
|
pathname,
|
|
86
88
|
search,
|
|
87
89
|
hash
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
I18nRouterNavigationProvider: ()=>I18nRouterNavigationProvider,
|
|
32
|
+
useIntegratedRouterAdapter: ()=>useIntegratedRouterAdapter
|
|
33
|
+
});
|
|
34
|
+
const router_navigation_namespaceObject = require("@modern-js/i18n-runtime-extensions/router-navigation");
|
|
35
|
+
const external_routerAdapter_js_namespaceObject = require("./routerAdapter.js");
|
|
36
|
+
const { I18nRouterNavigationProvider, useIntegratedRouterAdapter } = (0, router_navigation_namespaceObject.createI18nRouterNavigation)({
|
|
37
|
+
I18nNavigationProvider: external_routerAdapter_js_namespaceObject.I18nNavigationProvider,
|
|
38
|
+
useNativeI18nRouterAdapter: external_routerAdapter_js_namespaceObject.useNativeI18nRouterAdapter
|
|
39
|
+
});
|
|
40
|
+
exports.I18nRouterNavigationProvider = __webpack_exports__.I18nRouterNavigationProvider;
|
|
41
|
+
exports.useIntegratedRouterAdapter = __webpack_exports__.useIntegratedRouterAdapter;
|
|
42
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
43
|
+
"I18nRouterNavigationProvider",
|
|
44
|
+
"useIntegratedRouterAdapter"
|
|
45
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
46
|
+
Object.defineProperty(exports, '__esModule', {
|
|
47
|
+
value: true
|
|
48
|
+
});
|
|
@@ -31,7 +31,6 @@ __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");
|
|
35
34
|
const runtime_namespaceObject = require("@modern-js/runtime");
|
|
36
35
|
const head_namespaceObject = require("@modern-js/runtime/head");
|
|
37
36
|
const external_react_namespaceObject = require("react");
|
|
@@ -39,8 +38,14 @@ const external_context_js_namespaceObject = require("./context.js");
|
|
|
39
38
|
const external_hooks_js_namespaceObject = require("./hooks.js");
|
|
40
39
|
const instance_js_namespaceObject = require("./i18n/instance.js");
|
|
41
40
|
const external_routerAdapter_js_namespaceObject = require("./routerAdapter.js");
|
|
42
|
-
const
|
|
43
|
-
|
|
41
|
+
const NativeLanguageSynchronization = ({ i18nInstance, localePathRedirect, languages, pathname, prevLangRef, setLang, children })=>{
|
|
42
|
+
const synchronizeLanguage = (0, external_hooks_js_namespaceObject.useLanguageSync)(i18nInstance, localePathRedirect, languages, pathname, prevLangRef, setLang);
|
|
43
|
+
return children(synchronizeLanguage);
|
|
44
|
+
};
|
|
45
|
+
const createI18nRootWrapper = (options)=>(App)=>{
|
|
46
|
+
const LanguageSynchronization = options.LanguageSynchronization ?? NativeLanguageSynchronization;
|
|
47
|
+
const I18nRoot = (props)=>{
|
|
48
|
+
const { entryName, htmlLangAttr, localePathRedirect, languages, fallbackLanguage, ignoreRedirectRoutes, urlStrategy, getLatestI18nInstance, getI18nextProvider } = options;
|
|
44
49
|
const runtimeContext = (0, external_react_namespaceObject.useContext)(runtime_namespaceObject.RuntimeContext);
|
|
45
50
|
const i18nInstance = runtimeContext.i18nInstance || getLatestI18nInstance();
|
|
46
51
|
const initialLang = (0, external_react_namespaceObject.useMemo)(()=>i18nInstance?.language || fallbackLanguage, [
|
|
@@ -65,18 +70,16 @@ const createI18nRootWrapper = (options)=>(App)=>(props)=>{
|
|
|
65
70
|
lang
|
|
66
71
|
]);
|
|
67
72
|
(0, external_hooks_js_namespaceObject.useSdkResourcesLoader)(i18nInstance, setForceUpdate);
|
|
68
|
-
|
|
69
|
-
(0, external_hooks_js_namespaceObject.
|
|
70
|
-
const contextValue = (0, external_react_namespaceObject.useMemo)(()=>(0, external_hooks_js_namespaceObject.createContextValue)(lang, i18nInstance, entryName, languages, localePathRedirect, ignoreRedirectRoutes, localisedUrls, setLang, synchronizeLanguage), [
|
|
73
|
+
(0, external_hooks_js_namespaceObject.useClientSideRedirect)(i18nInstance, localePathRedirect, languages, fallbackLanguage, ignoreRedirectRoutes, urlStrategy);
|
|
74
|
+
const contextValue = (0, external_react_namespaceObject.useMemo)(()=>(0, external_hooks_js_namespaceObject.createContextValue)(lang, i18nInstance, entryName, languages, localePathRedirect, ignoreRedirectRoutes, setLang, urlStrategy), [
|
|
71
75
|
lang,
|
|
72
76
|
i18nInstance,
|
|
73
77
|
entryName,
|
|
74
78
|
languages,
|
|
75
79
|
localePathRedirect,
|
|
76
80
|
ignoreRedirectRoutes,
|
|
77
|
-
|
|
78
|
-
forceUpdate
|
|
79
|
-
synchronizeLanguage
|
|
81
|
+
urlStrategy,
|
|
82
|
+
forceUpdate
|
|
80
83
|
]);
|
|
81
84
|
const I18nextProvider = getI18nextProvider();
|
|
82
85
|
const i18nextInstanceForProvider = (0, external_react_namespaceObject.useMemo)(()=>i18nInstance ? (0, instance_js_namespaceObject.getI18nextInstanceForProvider)(i18nInstance, lang) : void 0, [
|
|
@@ -99,14 +102,35 @@ const createI18nRootWrapper = (options)=>(App)=>(props)=>{
|
|
|
99
102
|
lang
|
|
100
103
|
}
|
|
101
104
|
}),
|
|
102
|
-
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(LanguageSynchronization, {
|
|
106
|
+
i18nInstance: i18nInstance,
|
|
107
|
+
localePathRedirect: localePathRedirect,
|
|
108
|
+
languages: languages,
|
|
109
|
+
pathname: location?.pathname,
|
|
110
|
+
prevLangRef: prevLangRef,
|
|
111
|
+
setLang: setLang,
|
|
112
|
+
children: (synchronizeLanguage)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_context_js_namespaceObject.ModernI18nProvider, {
|
|
113
|
+
i18nextProvider: I18nextProvider,
|
|
114
|
+
value: {
|
|
115
|
+
...contextValue,
|
|
116
|
+
synchronizeLanguage
|
|
117
|
+
},
|
|
118
|
+
children: appContent
|
|
119
|
+
})
|
|
106
120
|
})
|
|
107
121
|
]
|
|
108
122
|
});
|
|
109
123
|
};
|
|
124
|
+
const { NavigationProvider } = options;
|
|
125
|
+
if (!NavigationProvider) return I18nRoot;
|
|
126
|
+
return function(props) {
|
|
127
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(NavigationProvider, {
|
|
128
|
+
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(I18nRoot, {
|
|
129
|
+
...props
|
|
130
|
+
})
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
};
|
|
110
134
|
exports.createI18nRootWrapper = __webpack_exports__.createI18nRootWrapper;
|
|
111
135
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
112
136
|
"createI18nRootWrapper"
|
|
@@ -28,160 +28,53 @@ var __webpack_require__ = {};
|
|
|
28
28
|
var __webpack_exports__ = {};
|
|
29
29
|
__webpack_require__.r(__webpack_exports__);
|
|
30
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
-
|
|
31
|
+
I18nNavigationProvider: ()=>I18nNavigationProvider,
|
|
32
|
+
useI18nRouterAdapter: ()=>useI18nRouterAdapter,
|
|
33
|
+
useNativeI18nRouterAdapter: ()=>useNativeI18nRouterAdapter
|
|
32
34
|
});
|
|
35
|
+
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
36
|
+
const contexts_namespaceObject = require("@modern-js/plugin-i18n/runtime/contexts");
|
|
33
37
|
const runtime_namespaceObject = require("@modern-js/runtime");
|
|
34
38
|
const context_namespaceObject = require("@modern-js/runtime/context");
|
|
35
39
|
const external_react_namespaceObject = require("react");
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
};
|
|
40
|
-
const
|
|
41
|
-
if (!location || 'object' != typeof location) return null;
|
|
42
|
-
const locationValue = location;
|
|
43
|
-
if ('string' != typeof locationValue.pathname) return null;
|
|
44
|
-
return {
|
|
45
|
-
pathname: locationValue.pathname,
|
|
46
|
-
search: normalizeUrlPart('string' == typeof locationValue.search ? locationValue.search : locationValue.searchStr, '?'),
|
|
47
|
-
hash: normalizeUrlPart(locationValue.hash, '#')
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
const getWindowLocation = ()=>{
|
|
51
|
-
if (!(0, runtime_namespaceObject.isBrowser)()) return null;
|
|
52
|
-
return {
|
|
53
|
-
pathname: window.location.pathname,
|
|
54
|
-
search: window.location.search,
|
|
55
|
-
hash: window.location.hash
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
const getRouterFramework = (runtimeContext, internalContext, inReactRouter)=>{
|
|
59
|
-
const framework = (0, context_namespaceObject.getRouterRuntimeState)(internalContext)?.framework || (0, context_namespaceObject.getRouterRuntimeState)(runtimeContext)?.framework;
|
|
60
|
-
if (framework) return framework;
|
|
61
|
-
if (internalContext.router?.useRouter || runtimeContext.router?.useRouter) return 'tanstack';
|
|
62
|
-
if (internalContext.router?.useLocation || internalContext.router?.useHref || runtimeContext.router?.useLocation || runtimeContext.router?.useHref) return 'react-router';
|
|
63
|
-
if (inReactRouter) return 'react-router';
|
|
64
|
-
};
|
|
65
|
-
const getRouterInstance = (internalContext, contextRouter)=>{
|
|
66
|
-
if (contextRouter) return contextRouter;
|
|
67
|
-
const router = (0, context_namespaceObject.getRouterRuntimeState)(internalContext)?.instance;
|
|
68
|
-
if (!router || 'object' != typeof router) return null;
|
|
69
|
-
return router;
|
|
70
|
-
};
|
|
71
|
-
const getRouterStateLocation = (internalContext, contextRouter)=>{
|
|
72
|
-
const router = getRouterInstance(internalContext, contextRouter);
|
|
73
|
-
return normalizeLocation(router?.stores?.location?.get?.()) || normalizeLocation(router?.state?.location);
|
|
74
|
-
};
|
|
75
|
-
const getRouterParams = (internalContext, contextRouter)=>{
|
|
76
|
-
const router = getRouterInstance(internalContext, contextRouter);
|
|
77
|
-
const matches = router?.stores?.matches?.get?.() || router?.state?.matches;
|
|
78
|
-
if (!Array.isArray(matches)) return {};
|
|
79
|
-
return matches.reduce((params, match)=>{
|
|
80
|
-
if (match?.params) Object.assign(params, match.params);
|
|
81
|
-
return params;
|
|
82
|
-
}, {});
|
|
83
|
-
};
|
|
84
|
-
const getRouterSnapshot = (internalContext, contextRouter)=>{
|
|
85
|
-
const location = getRouterStateLocation(internalContext, contextRouter);
|
|
86
|
-
const params = getRouterParams(internalContext, contextRouter);
|
|
87
|
-
return JSON.stringify([
|
|
88
|
-
location?.pathname ?? '',
|
|
89
|
-
location?.search ?? '',
|
|
90
|
-
location?.hash ?? '',
|
|
91
|
-
Object.entries(params).sort(([left], [right])=>left.localeCompare(right))
|
|
92
|
-
]);
|
|
93
|
-
};
|
|
94
|
-
const useI18nRouterAdapter = ()=>{
|
|
40
|
+
const I18nNavigationProvider = ({ children, value })=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(contexts_namespaceObject.I18nNavigationContext.Provider, {
|
|
41
|
+
value: value,
|
|
42
|
+
children: children
|
|
43
|
+
});
|
|
44
|
+
const useNativeI18nRouterAdapter = ()=>{
|
|
95
45
|
const runtimeContext = (0, external_react_namespaceObject.useContext)(runtime_namespaceObject.RuntimeContext);
|
|
96
46
|
const internalContext = (0, external_react_namespaceObject.useContext)(context_namespaceObject.InternalRuntimeContext);
|
|
97
47
|
const routerApi = internalContext.router || runtimeContext.router;
|
|
98
|
-
const
|
|
99
|
-
const
|
|
100
|
-
const
|
|
101
|
-
const
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
const hasRouter = 'tanstack' === framework || 'react-router' === framework || Boolean(reactRouterNavigate);
|
|
108
|
-
const subscribeToRouter = (0, external_react_namespaceObject.useCallback)((update)=>{
|
|
109
|
-
const router = getRouterInstance(internalContext, contextRouter);
|
|
110
|
-
if (!router) return ()=>void 0;
|
|
111
|
-
const unsubscribers = [];
|
|
112
|
-
if ('react-router' === framework && !inReactRouter && 'function' == typeof router.subscribe) {
|
|
113
|
-
const subscribe = router.subscribe;
|
|
114
|
-
const unsubscribe = subscribe.call(router, update);
|
|
115
|
-
if ('function' == typeof unsubscribe) unsubscribers.push(unsubscribe);
|
|
116
|
-
}
|
|
117
|
-
if ('tanstack' === framework && 'function' == typeof router.stores?.location?.subscribe) {
|
|
118
|
-
const unsubscribe = router.stores.location.subscribe(update);
|
|
119
|
-
if ('function' == typeof unsubscribe) unsubscribers.push(unsubscribe);
|
|
120
|
-
}
|
|
121
|
-
if ('tanstack' === framework && 'function' == typeof router.subscribe) {
|
|
122
|
-
const subscribe = router.subscribe;
|
|
123
|
-
for (const eventType of [
|
|
124
|
-
'onBeforeNavigate',
|
|
125
|
-
'onBeforeLoad'
|
|
126
|
-
]){
|
|
127
|
-
const unsubscribe = subscribe.call(router, eventType, update);
|
|
128
|
-
if ('function' == typeof unsubscribe) unsubscribers.push(unsubscribe);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return ()=>{
|
|
132
|
-
for (const unsubscribe of unsubscribers)unsubscribe();
|
|
133
|
-
};
|
|
134
|
-
}, [
|
|
135
|
-
contextRouter,
|
|
136
|
-
framework,
|
|
137
|
-
inReactRouter,
|
|
138
|
-
internalContext
|
|
139
|
-
]);
|
|
140
|
-
const getSnapshot = (0, external_react_namespaceObject.useCallback)(()=>getRouterSnapshot(internalContext, contextRouter), [
|
|
141
|
-
contextRouter,
|
|
142
|
-
internalContext
|
|
143
|
-
]);
|
|
144
|
-
(0, external_react_namespaceObject.useSyncExternalStore)(subscribeToRouter, getSnapshot, getSnapshot);
|
|
145
|
-
const navigate = (0, external_react_namespaceObject.useCallback)((href, options)=>{
|
|
146
|
-
const router = getRouterInstance(internalContext, contextRouter);
|
|
147
|
-
const activeFramework = getRouterFramework(runtimeContext, internalContext, inReactRouter);
|
|
148
|
-
if ('tanstack' === activeFramework) {
|
|
149
|
-
if ('function' == typeof router?.navigate) return router.navigate({
|
|
150
|
-
to: href,
|
|
151
|
-
replace: options?.replace,
|
|
152
|
-
...options?.state === void 0 ? {} : {
|
|
153
|
-
state: options.state
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
throw new Error('TanStack router instance is not available.');
|
|
157
|
-
}
|
|
158
|
-
if (reactRouterNavigate) return reactRouterNavigate(href, options);
|
|
159
|
-
if ('react-router' === activeFramework) {
|
|
160
|
-
if ('function' == typeof router?.navigate) return router.navigate(href, options);
|
|
161
|
-
throw new Error('React Router instance is not available.');
|
|
162
|
-
}
|
|
163
|
-
}, [
|
|
164
|
-
contextRouter,
|
|
165
|
-
internalContext,
|
|
166
|
-
inReactRouter,
|
|
167
|
-
reactRouterNavigate,
|
|
168
|
-
runtimeContext
|
|
169
|
-
]);
|
|
170
|
-
const location = (reactRouterLocation ? normalizeLocation(reactRouterLocation) : getRouterStateLocation(internalContext, contextRouter)) || getWindowLocation();
|
|
171
|
-
const params = inReactRouter ? reactRouterParams : getRouterParams(internalContext, contextRouter);
|
|
172
|
-
const Link = 'tanstack' === framework ? internalContext.router?.Link || runtimeContext.router?.Link || null : 'react-router' === framework || inReactRouter ? routerApi?.Link ?? null : null;
|
|
48
|
+
const hasRouter = routerApi?.useInRouterContext?.() ?? false;
|
|
49
|
+
const navigate = hasRouter ? routerApi?.useNavigate?.() ?? null : null;
|
|
50
|
+
const routerLocation = hasRouter ? routerApi?.useLocation?.() ?? null : null;
|
|
51
|
+
const params = hasRouter ? routerApi?.useParams?.() ?? {} : {};
|
|
52
|
+
const location = routerLocation ?? ((0, runtime_namespaceObject.isBrowser)() ? {
|
|
53
|
+
pathname: window.location.pathname,
|
|
54
|
+
search: window.location.search,
|
|
55
|
+
hash: window.location.hash
|
|
56
|
+
} : null);
|
|
173
57
|
return {
|
|
174
|
-
framework,
|
|
58
|
+
framework: hasRouter ? 'react-router' : void 0,
|
|
175
59
|
hasRouter,
|
|
60
|
+
navigate,
|
|
176
61
|
location,
|
|
177
|
-
|
|
178
|
-
Link
|
|
179
|
-
params
|
|
62
|
+
params,
|
|
63
|
+
Link: hasRouter ? routerApi?.Link ?? null : null
|
|
180
64
|
};
|
|
181
65
|
};
|
|
66
|
+
const useI18nRouterAdapter = ()=>{
|
|
67
|
+
const provided = (0, external_react_namespaceObject.useContext)(contexts_namespaceObject.I18nNavigationContext);
|
|
68
|
+
const native = useNativeI18nRouterAdapter();
|
|
69
|
+
return provided ?? native;
|
|
70
|
+
};
|
|
71
|
+
exports.I18nNavigationProvider = __webpack_exports__.I18nNavigationProvider;
|
|
182
72
|
exports.useI18nRouterAdapter = __webpack_exports__.useI18nRouterAdapter;
|
|
73
|
+
exports.useNativeI18nRouterAdapter = __webpack_exports__.useNativeI18nRouterAdapter;
|
|
183
74
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
184
|
-
"
|
|
75
|
+
"I18nNavigationProvider",
|
|
76
|
+
"useI18nRouterAdapter",
|
|
77
|
+
"useNativeI18nRouterAdapter"
|
|
185
78
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
186
79
|
Object.defineProperty(exports, '__esModule', {
|
|
187
80
|
value: true
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
ModernI18nContext: ()=>contexts_namespaceObject.ModernI18nContext,
|
|
32
|
+
ReactI18nextProviderContext: ()=>contexts_namespaceObject.ReactI18nextProviderContext
|
|
33
|
+
});
|
|
34
|
+
const contexts_namespaceObject = require("@modern-js/plugin-i18n/runtime/contexts");
|
|
35
|
+
exports.ModernI18nContext = __webpack_exports__.ModernI18nContext;
|
|
36
|
+
exports.ReactI18nextProviderContext = __webpack_exports__.ReactI18nextProviderContext;
|
|
37
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
38
|
+
"ModernI18nContext",
|
|
39
|
+
"ReactI18nextProviderContext"
|
|
40
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
41
|
+
Object.defineProperty(exports, '__esModule', {
|
|
42
|
+
value: true
|
|
43
|
+
});
|
|
@@ -34,11 +34,13 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
34
34
|
getLanguageFromPath: ()=>getLanguageFromPath,
|
|
35
35
|
getPathname: ()=>getPathname,
|
|
36
36
|
shouldIgnoreRedirect: ()=>shouldIgnoreRedirect,
|
|
37
|
-
splitUrlTarget: ()=>splitUrlTarget
|
|
37
|
+
splitUrlTarget: ()=>url_namespaceObject.splitUrlTarget
|
|
38
38
|
});
|
|
39
|
-
const i18n_runtime_extensions_namespaceObject = require("@modern-js/i18n-runtime-extensions");
|
|
40
39
|
const runtime_namespaceObject = require("@modern-js/runtime");
|
|
41
40
|
const context_namespaceObject = require("@modern-js/runtime/context");
|
|
41
|
+
const url_namespaceObject = require("@modern-js/runtime-utils/url");
|
|
42
|
+
const mappedUrlStrategy_js_namespaceObject = require("../shared/mappedUrlStrategy.js");
|
|
43
|
+
const urlStrategy_js_namespaceObject = require("../shared/urlStrategy.js");
|
|
42
44
|
const getPathname = (context)=>{
|
|
43
45
|
if ((0, runtime_namespaceObject.isBrowser)()) return window.location.pathname;
|
|
44
46
|
return context.ssrContext?.request?.pathname || '/';
|
|
@@ -54,22 +56,14 @@ const getLanguageFromPath = (pathname, languages, fallbackLanguage)=>{
|
|
|
54
56
|
if (languages.includes(firstSegment)) return firstSegment;
|
|
55
57
|
return fallbackLanguage;
|
|
56
58
|
};
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
pathname,
|
|
66
|
-
search,
|
|
67
|
-
hash
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
const buildLocalizedUrl = (target, language, languages, localisedUrls)=>{
|
|
71
|
-
const { pathname, search, hash } = splitUrlTarget(target);
|
|
72
|
-
const localizedPathname = (0, i18n_runtime_extensions_namespaceObject.localiseTargetPathname)(pathname, language, languages, localisedUrls);
|
|
59
|
+
const buildLocalizedUrl = (target, language, languages, urlStrategy)=>{
|
|
60
|
+
const { pathname, search, hash } = (0, url_namespaceObject.splitUrlTarget)(target);
|
|
61
|
+
const strategy = (0, urlStrategy_js_namespaceObject.asI18nUrlStrategy)(urlStrategy);
|
|
62
|
+
if (strategy) return `${strategy.localizePathname(pathname, language, languages)}${search}${hash}`;
|
|
63
|
+
const segments = pathname.split('/').filter(Boolean);
|
|
64
|
+
if (segments[0] && languages.some((item)=>item.toLowerCase() === segments[0].toLowerCase())) segments[0] = language;
|
|
65
|
+
else segments.unshift(language);
|
|
66
|
+
const localizedPathname = `/${segments.join('/')}`;
|
|
73
67
|
return `${localizedPathname}${search}${hash}`;
|
|
74
68
|
};
|
|
75
69
|
const detectLanguageFromPath = (pathname, languages, localePathRedirect)=>{
|
|
@@ -89,7 +83,15 @@ const detectLanguageFromPath = (pathname, languages, localePathRedirect)=>{
|
|
|
89
83
|
detected: false
|
|
90
84
|
};
|
|
91
85
|
};
|
|
92
|
-
const shouldIgnoreRedirect = (pathname, languages, ignoreRedirectRoutes
|
|
86
|
+
const shouldIgnoreRedirect = (pathname, languages, ignoreRedirectRoutes, urlStrategy)=>{
|
|
87
|
+
if ((0, mappedUrlStrategy_js_namespaceObject.isDefaultLocaleRedirectSkipPath)(pathname, languages)) return true;
|
|
88
|
+
if ((0, urlStrategy_js_namespaceObject.asI18nUrlStrategy)(urlStrategy)?.shouldSkipRedirect?.(pathname, languages)) return true;
|
|
89
|
+
if (!ignoreRedirectRoutes) return false;
|
|
90
|
+
const segments = pathname.split('/').filter(Boolean);
|
|
91
|
+
if (segments[0] && languages.some((item)=>item.toLowerCase() === segments[0].toLowerCase())) segments.shift();
|
|
92
|
+
const normalizedPath = `/${segments.join('/')}`;
|
|
93
|
+
return 'function' == typeof ignoreRedirectRoutes ? ignoreRedirectRoutes(normalizedPath) : ignoreRedirectRoutes.some((pattern)=>normalizedPath === pattern || normalizedPath.startsWith(`${pattern}/`));
|
|
94
|
+
};
|
|
93
95
|
exports.buildLocalizedUrl = __webpack_exports__.buildLocalizedUrl;
|
|
94
96
|
exports.detectLanguageFromPath = __webpack_exports__.detectLanguageFromPath;
|
|
95
97
|
exports.getEntryPath = __webpack_exports__.getEntryPath;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
createDefaultUrlStrategy: ()=>createDefaultUrlStrategy,
|
|
32
|
+
resolveDefaultUrlStrategy: ()=>resolveDefaultUrlStrategy
|
|
33
|
+
});
|
|
34
|
+
const external_mappedUrlStrategy_js_namespaceObject = require("./mappedUrlStrategy.js");
|
|
35
|
+
const createDefaultUrlStrategy = (localisedUrls)=>(0, external_mappedUrlStrategy_js_namespaceObject.createMappedUrlStrategy)(localisedUrls);
|
|
36
|
+
const resolveDefaultUrlStrategy = (localisedUrls)=>{
|
|
37
|
+
if (!localisedUrls || 'object' != typeof localisedUrls || 0 === Object.keys(localisedUrls).length) return;
|
|
38
|
+
return createDefaultUrlStrategy(localisedUrls);
|
|
39
|
+
};
|
|
40
|
+
exports.createDefaultUrlStrategy = __webpack_exports__.createDefaultUrlStrategy;
|
|
41
|
+
exports.resolveDefaultUrlStrategy = __webpack_exports__.resolveDefaultUrlStrategy;
|
|
42
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
43
|
+
"createDefaultUrlStrategy",
|
|
44
|
+
"resolveDefaultUrlStrategy"
|
|
45
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
46
|
+
Object.defineProperty(exports, '__esModule', {
|
|
47
|
+
value: true
|
|
48
|
+
});
|
package/dist/cjs/server/index.js
CHANGED
|
@@ -33,10 +33,11 @@ __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");
|
|
37
36
|
const hono_namespaceObject = require("@modern-js/server-core/hono");
|
|
37
|
+
const urlStrategy_js_namespaceObject = require("../shared/urlStrategy.js");
|
|
38
38
|
const utils_js_namespaceObject = require("../shared/utils.js");
|
|
39
39
|
const external_apiPrefix_js_namespaceObject = require("./apiPrefix.js");
|
|
40
|
+
const external_defaultUrlStrategy_js_namespaceObject = require("./defaultUrlStrategy.js");
|
|
40
41
|
const external_detectorOptions_js_namespaceObject = require("./detectorOptions.js");
|
|
41
42
|
const external_redirectPolicy_js_namespaceObject = require("./redirectPolicy.js");
|
|
42
43
|
const { languageDetector } = hono_namespaceObject;
|
|
@@ -59,7 +60,10 @@ const i18nServerPlugin = (options)=>({
|
|
|
59
60
|
const { entryName } = route;
|
|
60
61
|
if (!entryName) return;
|
|
61
62
|
if (!options.localeDetection) return;
|
|
62
|
-
const
|
|
63
|
+
const entryLocaleDetection = (0, utils_js_namespaceObject.getLocaleDetectionOptions)(entryName, options.localeDetection);
|
|
64
|
+
const { localePathRedirect, i18nextDetector = true, languages = [], fallbackLanguage = 'en', detection, ignoreRedirectRoutes } = entryLocaleDetection;
|
|
65
|
+
const legacyLocalisedUrls = Reflect.get(entryLocaleDetection, 'localisedUrls');
|
|
66
|
+
const urlStrategy = (0, urlStrategy_js_namespaceObject.asI18nUrlStrategy)(options.resolveUrlStrategy?.(entryName)) ?? (0, external_defaultUrlStrategy_js_namespaceObject.resolveDefaultUrlStrategy)(legacyLocalisedUrls);
|
|
63
67
|
const staticRoutePrefixes = options.staticRoutePrefixes;
|
|
64
68
|
const originUrlPath = route.urlPath;
|
|
65
69
|
const urlPath = originUrlPath.endsWith('/') ? `${originUrlPath}*` : `${originUrlPath}/*`;
|
|
@@ -74,6 +78,7 @@ const i18nServerPlugin = (options)=>({
|
|
|
74
78
|
const url = new URL(c.req.url);
|
|
75
79
|
const pathname = url.pathname;
|
|
76
80
|
if ((0, external_apiPrefix_js_namespaceObject.matchesApiPrefix)(pathname, apiPrefixes)) return await next();
|
|
81
|
+
if ((0, external_redirectPolicy_js_namespaceObject.shouldIgnoreRedirect)(pathname, urlPath, ignoreRedirectRoutes, urlStrategy, languages)) return await next();
|
|
77
82
|
if ((0, external_redirectPolicy_js_namespaceObject.isStaticResourceRequest)(pathname, staticRoutePrefixes, languages)) return await next();
|
|
78
83
|
if ('/' === originUrlPath) {
|
|
79
84
|
const pathSegments = pathname.split('/').filter(Boolean);
|
|
@@ -94,7 +99,7 @@ const i18nServerPlugin = (options)=>({
|
|
|
94
99
|
const pathname = url.pathname;
|
|
95
100
|
if ((0, external_apiPrefix_js_namespaceObject.matchesApiPrefix)(pathname, apiPrefixes)) return await next();
|
|
96
101
|
if ((0, external_redirectPolicy_js_namespaceObject.isStaticResourceRequest)(pathname, staticRoutePrefixes, languages)) return await next();
|
|
97
|
-
if ((0, external_redirectPolicy_js_namespaceObject.shouldIgnoreRedirect)(pathname, urlPath, ignoreRedirectRoutes)) return await next();
|
|
102
|
+
if ((0, external_redirectPolicy_js_namespaceObject.shouldIgnoreRedirect)(pathname, urlPath, ignoreRedirectRoutes, urlStrategy, languages)) return await next();
|
|
98
103
|
if ('/' === originUrlPath) {
|
|
99
104
|
const pathSegments = pathname.split('/').filter(Boolean);
|
|
100
105
|
if (pathSegments.length > 0) {
|
|
@@ -107,12 +112,11 @@ const i18nServerPlugin = (options)=>({
|
|
|
107
112
|
let detectedLanguage = null;
|
|
108
113
|
if (i18nextDetector) detectedLanguage = c.get('language') || null;
|
|
109
114
|
const targetLanguage = detectedLanguage || fallbackLanguage;
|
|
110
|
-
const localizedUrl = (0, external_redirectPolicy_js_namespaceObject.buildLocalizedUrl)(c.req, originUrlPath, targetLanguage, languages,
|
|
115
|
+
const localizedUrl = (0, external_redirectPolicy_js_namespaceObject.buildLocalizedUrl)(c.req, originUrlPath, targetLanguage, languages, urlStrategy);
|
|
111
116
|
return (0, external_redirectPolicy_js_namespaceObject.createLocaleRedirectResponse)(localizedUrl);
|
|
112
117
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const expectedUrl = (0, external_redirectPolicy_js_namespaceObject.buildLocalizedUrl)(c.req, originUrlPath, language, languages, localisedUrls);
|
|
118
|
+
if (urlStrategy) {
|
|
119
|
+
const expectedUrl = (0, external_redirectPolicy_js_namespaceObject.buildLocalizedUrl)(c.req, originUrlPath, language, languages, urlStrategy);
|
|
116
120
|
if (expectedUrl !== `${pathname}${url.search}${url.hash}`) return (0, external_redirectPolicy_js_namespaceObject.createLocaleRedirectResponse)(expectedUrl);
|
|
117
121
|
}
|
|
118
122
|
await next();
|