@bleedingdev/modern-js-plugin-i18n 3.2.0-ultramodern.12 → 3.2.0-ultramodern.121
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/README.md +221 -11
- package/dist/cjs/cli/index.js +32 -5
- package/dist/cjs/runtime/I18nLink.js +17 -28
- package/dist/cjs/runtime/Link.js +264 -0
- package/dist/cjs/runtime/canonicalRoutes.js +18 -0
- package/dist/cjs/runtime/context.js +41 -10
- package/dist/cjs/runtime/hooks.js +17 -10
- package/dist/cjs/runtime/i18n/backend/config.js +9 -5
- package/dist/cjs/runtime/i18n/backend/defaults.js +15 -10
- package/dist/cjs/runtime/i18n/backend/defaults.node.js +47 -8
- package/dist/cjs/runtime/i18n/backend/index.js +9 -5
- package/dist/cjs/runtime/i18n/backend/middleware.common.js +9 -5
- package/dist/cjs/runtime/i18n/backend/middleware.js +9 -5
- package/dist/cjs/runtime/i18n/backend/middleware.node.js +13 -9
- package/dist/cjs/runtime/i18n/backend/sdk-backend.js +9 -5
- package/dist/cjs/runtime/i18n/backend/sdk-event.js +16 -11
- package/dist/cjs/runtime/i18n/detection/config.js +9 -5
- package/dist/cjs/runtime/i18n/detection/index.js +9 -5
- package/dist/cjs/runtime/i18n/detection/middleware.js +9 -5
- package/dist/cjs/runtime/i18n/detection/middleware.node.js +9 -5
- package/dist/cjs/runtime/i18n/index.js +9 -5
- package/dist/cjs/runtime/i18n/instance.js +17 -37
- package/dist/cjs/runtime/i18n/react-i18next.js +53 -0
- package/dist/cjs/runtime/i18n/utils.js +9 -17
- package/dist/cjs/runtime/index.js +50 -15
- package/dist/cjs/runtime/localizedPaths.js +102 -0
- package/dist/cjs/runtime/routerAdapter.js +167 -0
- package/dist/cjs/runtime/utils.js +80 -97
- package/dist/cjs/server/index.js +62 -14
- package/dist/cjs/shared/deepMerge.js +12 -8
- package/dist/cjs/shared/detection.js +9 -5
- package/dist/cjs/shared/localisedUrls.js +351 -0
- package/dist/cjs/shared/utils.js +15 -11
- package/dist/esm/cli/index.mjs +23 -0
- package/dist/esm/runtime/I18nLink.mjs +7 -22
- package/dist/esm/runtime/Link.mjs +221 -0
- package/dist/esm/runtime/canonicalRoutes.mjs +0 -0
- package/dist/esm/runtime/context.mjs +34 -7
- package/dist/esm/runtime/hooks.mjs +9 -6
- package/dist/esm/runtime/i18n/backend/defaults.mjs +1 -1
- package/dist/esm/runtime/i18n/backend/defaults.node.mjs +24 -3
- package/dist/esm/runtime/i18n/backend/middleware.node.mjs +3 -3
- package/dist/esm/runtime/i18n/instance.mjs +1 -19
- package/dist/esm/runtime/i18n/react-i18next.mjs +15 -0
- package/dist/esm/runtime/i18n/utils.mjs +0 -12
- package/dist/esm/runtime/index.mjs +23 -13
- package/dist/esm/runtime/localizedPaths.mjs +55 -0
- package/dist/esm/runtime/routerAdapter.mjs +129 -0
- package/dist/esm/runtime/utils.mjs +19 -31
- package/dist/esm/server/index.mjs +46 -8
- package/dist/esm/shared/localisedUrls.mjs +283 -0
- package/dist/esm-node/cli/index.mjs +23 -0
- package/dist/esm-node/runtime/I18nLink.mjs +7 -22
- package/dist/esm-node/runtime/Link.mjs +222 -0
- package/dist/esm-node/runtime/canonicalRoutes.mjs +1 -0
- package/dist/esm-node/runtime/context.mjs +34 -7
- package/dist/esm-node/runtime/hooks.mjs +9 -6
- package/dist/esm-node/runtime/i18n/backend/defaults.mjs +1 -1
- package/dist/esm-node/runtime/i18n/backend/defaults.node.mjs +24 -3
- package/dist/esm-node/runtime/i18n/backend/middleware.node.mjs +3 -3
- package/dist/esm-node/runtime/i18n/instance.mjs +1 -19
- package/dist/esm-node/runtime/i18n/react-i18next.mjs +16 -0
- package/dist/esm-node/runtime/i18n/utils.mjs +0 -12
- package/dist/esm-node/runtime/index.mjs +23 -13
- package/dist/esm-node/runtime/localizedPaths.mjs +56 -0
- package/dist/esm-node/runtime/routerAdapter.mjs +130 -0
- package/dist/esm-node/runtime/utils.mjs +19 -31
- package/dist/esm-node/server/index.mjs +46 -8
- package/dist/esm-node/shared/localisedUrls.mjs +284 -0
- package/dist/types/cli/index.d.ts +1 -0
- package/dist/types/runtime/I18nLink.d.ts +6 -0
- package/dist/types/runtime/Link.d.ts +66 -0
- package/dist/types/runtime/canonicalRoutes.d.ts +60 -0
- package/dist/types/runtime/context.d.ts +3 -0
- package/dist/types/runtime/hooks.d.ts +4 -2
- package/dist/types/runtime/i18n/backend/defaults.node.d.ts +3 -2
- package/dist/types/runtime/i18n/backend/middleware.node.d.ts +1 -1
- package/dist/types/runtime/i18n/instance.d.ts +4 -6
- package/dist/types/runtime/i18n/react-i18next.d.ts +7 -0
- package/dist/types/runtime/index.d.ts +6 -1
- package/dist/types/runtime/localizedPaths.d.ts +39 -0
- package/dist/types/runtime/routerAdapter.d.ts +26 -0
- package/dist/types/runtime/types.d.ts +1 -1
- package/dist/types/runtime/utils.d.ts +13 -9
- package/dist/types/server/index.d.ts +6 -0
- package/dist/types/shared/localisedUrls.d.ts +36 -0
- package/dist/types/shared/type.d.ts +14 -0
- package/package.json +24 -24
- package/rstest.config.mts +44 -0
- package/src/cli/index.ts +44 -1
- package/src/runtime/I18nLink.tsx +14 -51
- package/src/runtime/Link.tsx +430 -0
- package/src/runtime/canonicalRoutes.ts +93 -0
- package/src/runtime/context.tsx +45 -7
- package/src/runtime/hooks.ts +13 -4
- package/src/runtime/i18n/backend/defaults.node.ts +40 -2
- package/src/runtime/i18n/backend/defaults.ts +3 -1
- package/src/runtime/i18n/backend/middleware.node.ts +1 -1
- package/src/runtime/i18n/instance.ts +3 -30
- package/src/runtime/i18n/react-i18next.ts +25 -0
- package/src/runtime/i18n/utils.ts +4 -26
- package/src/runtime/index.tsx +47 -12
- package/src/runtime/localizedPaths.ts +107 -0
- package/src/runtime/routerAdapter.tsx +332 -0
- package/src/runtime/types.ts +1 -1
- package/src/runtime/utils.ts +33 -38
- package/src/server/index.ts +108 -11
- package/src/shared/localisedUrls.ts +623 -0
- package/src/shared/type.ts +14 -0
- package/tests/backendDefaults.test.ts +51 -0
- package/tests/i18nUtils.test.ts +59 -0
- package/tests/link.test.tsx +525 -0
- package/tests/linkTypes.test.ts +28 -0
- package/tests/localisedUrls.test.ts +536 -0
- package/tests/routerAdapter.test.tsx +456 -0
- package/tests/type-fixture/linkTypes.fixture.tsx +51 -0
- package/tests/type-fixture/tsconfig.json +15 -0
- package/dist/esm/rslib-runtime.mjs +0 -18
- package/dist/esm-node/rslib-runtime.mjs +0 -19
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
3
|
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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");
|
|
9
13
|
};
|
|
10
14
|
})();
|
|
11
15
|
(()=>{
|
|
@@ -23,16 +27,6 @@ var __webpack_require__ = {};
|
|
|
23
27
|
})();
|
|
24
28
|
var __webpack_exports__ = {};
|
|
25
29
|
__webpack_require__.r(__webpack_exports__);
|
|
26
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
getActualI18nextInstance: ()=>getActualI18nextInstance,
|
|
28
|
-
getI18nInstance: ()=>getI18nInstance,
|
|
29
|
-
getI18nWrapperI18nextInstance: ()=>getI18nWrapperI18nextInstance,
|
|
30
|
-
getI18nextInstanceForProvider: ()=>getI18nextInstanceForProvider,
|
|
31
|
-
getI18nextProvider: ()=>getI18nextProvider,
|
|
32
|
-
getInitReactI18next: ()=>getInitReactI18next,
|
|
33
|
-
isI18nInstance: ()=>isI18nInstance,
|
|
34
|
-
isI18nWrapperInstance: ()=>isI18nWrapperInstance
|
|
35
|
-
});
|
|
36
30
|
function isI18nWrapperInstance(obj) {
|
|
37
31
|
if (!obj || 'object' != typeof obj) return false;
|
|
38
32
|
if (!obj.i18nInstance || 'object' != typeof obj.i18nInstance) return false;
|
|
@@ -75,14 +69,6 @@ async function createI18nextInstance() {
|
|
|
75
69
|
return null;
|
|
76
70
|
}
|
|
77
71
|
}
|
|
78
|
-
async function tryImportReactI18next() {
|
|
79
|
-
try {
|
|
80
|
-
const reactI18next = await import("react-i18next");
|
|
81
|
-
return reactI18next;
|
|
82
|
-
} catch (error) {
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
72
|
function getI18nextInstanceForProvider(instance) {
|
|
87
73
|
if (isI18nWrapperInstance(instance)) {
|
|
88
74
|
const i18nextInstance = getI18nWrapperI18nextInstance(instance);
|
|
@@ -99,22 +85,18 @@ async function getI18nInstance(userInstance) {
|
|
|
99
85
|
if (i18nextInstance) return i18nextInstance;
|
|
100
86
|
throw new Error('No i18n instance found');
|
|
101
87
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
88
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
89
|
+
getActualI18nextInstance: ()=>getActualI18nextInstance,
|
|
90
|
+
getI18nInstance: ()=>getI18nInstance,
|
|
91
|
+
getI18nWrapperI18nextInstance: ()=>getI18nWrapperI18nextInstance,
|
|
92
|
+
getI18nextInstanceForProvider: ()=>getI18nextInstanceForProvider,
|
|
93
|
+
isI18nInstance: ()=>isI18nInstance,
|
|
94
|
+
isI18nWrapperInstance: ()=>isI18nWrapperInstance
|
|
95
|
+
});
|
|
112
96
|
exports.getActualI18nextInstance = __webpack_exports__.getActualI18nextInstance;
|
|
113
97
|
exports.getI18nInstance = __webpack_exports__.getI18nInstance;
|
|
114
98
|
exports.getI18nWrapperI18nextInstance = __webpack_exports__.getI18nWrapperI18nextInstance;
|
|
115
99
|
exports.getI18nextInstanceForProvider = __webpack_exports__.getI18nextInstanceForProvider;
|
|
116
|
-
exports.getI18nextProvider = __webpack_exports__.getI18nextProvider;
|
|
117
|
-
exports.getInitReactI18next = __webpack_exports__.getInitReactI18next;
|
|
118
100
|
exports.isI18nInstance = __webpack_exports__.isI18nInstance;
|
|
119
101
|
exports.isI18nWrapperInstance = __webpack_exports__.isI18nWrapperInstance;
|
|
120
102
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
@@ -122,8 +104,6 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
|
122
104
|
"getI18nInstance",
|
|
123
105
|
"getI18nWrapperI18nextInstance",
|
|
124
106
|
"getI18nextInstanceForProvider",
|
|
125
|
-
"getI18nextProvider",
|
|
126
|
-
"getInitReactI18next",
|
|
127
107
|
"isI18nInstance",
|
|
128
108
|
"isI18nWrapperInstance"
|
|
129
109
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
async function tryImportReactI18next() {
|
|
31
|
+
try {
|
|
32
|
+
return await import("react-i18next");
|
|
33
|
+
} catch (error) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async function getReactI18nextIntegration() {
|
|
38
|
+
const reactI18nextModule = await tryImportReactI18next();
|
|
39
|
+
return {
|
|
40
|
+
I18nextProvider: reactI18nextModule?.I18nextProvider ?? null,
|
|
41
|
+
initReactI18next: reactI18nextModule?.initReactI18next ?? null
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
45
|
+
getReactI18nextIntegration: ()=>getReactI18nextIntegration
|
|
46
|
+
});
|
|
47
|
+
exports.getReactI18nextIntegration = __webpack_exports__.getReactI18nextIntegration;
|
|
48
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
49
|
+
"getReactI18nextIntegration"
|
|
50
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
51
|
+
Object.defineProperty(exports, '__esModule', {
|
|
52
|
+
value: true
|
|
53
|
+
});
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
3
|
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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");
|
|
9
13
|
};
|
|
10
14
|
})();
|
|
11
15
|
(()=>{
|
|
@@ -133,18 +137,6 @@ const initializeI18nInstance = async (i18nInstance, finalLanguage, fallbackLangu
|
|
|
133
137
|
};
|
|
134
138
|
}
|
|
135
139
|
}
|
|
136
|
-
if (mergedBackend && hasOptions(i18nInstance)) {
|
|
137
|
-
const defaultNS = initOptions.defaultNS || initOptions.ns || 'translation';
|
|
138
|
-
const ns = Array.isArray(defaultNS) ? defaultNS[0] : defaultNS;
|
|
139
|
-
let retries = 20;
|
|
140
|
-
while(retries > 0){
|
|
141
|
-
const actualInstance = (0, external_instance_js_namespaceObject.getActualI18nextInstance)(i18nInstance);
|
|
142
|
-
const store = actualInstance.store;
|
|
143
|
-
if (store?.data?.[finalLanguage]?.[ns]) break;
|
|
144
|
-
await new Promise((resolve)=>setTimeout(resolve, 100));
|
|
145
|
-
retries--;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
140
|
}
|
|
149
141
|
};
|
|
150
142
|
function hasOptions(instance) {
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
3
|
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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");
|
|
9
13
|
};
|
|
10
14
|
})();
|
|
11
15
|
(()=>{
|
|
@@ -25,8 +29,15 @@ var __webpack_exports__ = {};
|
|
|
25
29
|
__webpack_require__.r(__webpack_exports__);
|
|
26
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
31
|
I18nLink: ()=>external_I18nLink_js_namespaceObject.I18nLink,
|
|
32
|
+
Link: ()=>external_Link_js_namespaceObject.Link,
|
|
33
|
+
buildLocalizedUrl: ()=>external_utils_js_namespaceObject.buildLocalizedUrl,
|
|
34
|
+
canonicalPath: ()=>external_localizedPaths_js_namespaceObject.canonicalPath,
|
|
28
35
|
default: ()=>runtime,
|
|
29
36
|
i18nPlugin: ()=>i18nPlugin,
|
|
37
|
+
localizePath: ()=>external_localizedPaths_js_namespaceObject.localizePath,
|
|
38
|
+
splitUrlTarget: ()=>external_utils_js_namespaceObject.splitUrlTarget,
|
|
39
|
+
useLocalizedLocation: ()=>external_localizedPaths_js_namespaceObject.useLocalizedLocation,
|
|
40
|
+
useLocalizedPaths: ()=>external_localizedPaths_js_namespaceObject.useLocalizedPaths,
|
|
30
41
|
useModernI18n: ()=>external_context_js_namespaceObject.useModernI18n
|
|
31
42
|
});
|
|
32
43
|
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
@@ -46,22 +57,29 @@ const utils_js_namespaceObject = require("./i18n/utils.js");
|
|
|
46
57
|
const external_utils_js_namespaceObject = require("./utils.js");
|
|
47
58
|
require("./types.js");
|
|
48
59
|
const external_I18nLink_js_namespaceObject = require("./I18nLink.js");
|
|
60
|
+
const external_Link_js_namespaceObject = require("./Link.js");
|
|
61
|
+
const external_localizedPaths_js_namespaceObject = require("./localizedPaths.js");
|
|
49
62
|
const i18nPlugin = (options)=>({
|
|
50
63
|
name: '@modern-js/plugin-i18n',
|
|
51
64
|
setup: (api)=>{
|
|
52
|
-
const { entryName, i18nInstance: userI18nInstance, initOptions, localeDetection, backend, htmlLangAttr = false } = options;
|
|
53
|
-
const { localePathRedirect = false, i18nextDetector = true, languages = [], fallbackLanguage = 'en', detection, ignoreRedirectRoutes } = localeDetection || {};
|
|
65
|
+
const { entryName, i18nInstance: userI18nInstance, initOptions, localeDetection, backend, htmlLangAttr = false, reactI18next = true } = options;
|
|
66
|
+
const { localePathRedirect = false, i18nextDetector = true, languages = [], fallbackLanguage = 'en', detection, ignoreRedirectRoutes, localisedUrls } = localeDetection || {};
|
|
54
67
|
const { enabled: backendEnabled = false } = backend || {};
|
|
55
68
|
let latestI18nInstance;
|
|
56
69
|
let I18nextProvider;
|
|
70
|
+
const loadReactI18nextIntegration = async ()=>{
|
|
71
|
+
if (!reactI18next) return null;
|
|
72
|
+
const { getReactI18nextIntegration } = await import("./i18n/react-i18next.js");
|
|
73
|
+
return getReactI18nextIntegration();
|
|
74
|
+
};
|
|
57
75
|
api.onBeforeRender(async (context)=>{
|
|
58
76
|
let i18nInstance = await (0, index_js_namespaceObject.getI18nInstance)(userI18nInstance);
|
|
59
77
|
const { i18n: otherConfig } = api.getRuntimeConfig();
|
|
60
78
|
const { initOptions: otherInitOptions } = otherConfig || {};
|
|
61
79
|
const userInitOptions = (0, merge_namespaceObject.merge)(otherInitOptions || {}, initOptions || {});
|
|
62
|
-
const
|
|
63
|
-
I18nextProvider =
|
|
64
|
-
if (initReactI18next) i18nInstance.use(initReactI18next);
|
|
80
|
+
const reactI18nextIntegration = await loadReactI18nextIntegration();
|
|
81
|
+
I18nextProvider = reactI18nextIntegration?.I18nextProvider ?? null;
|
|
82
|
+
if (reactI18nextIntegration?.initReactI18next) i18nInstance.use(reactI18nextIntegration.initReactI18next);
|
|
65
83
|
const pathname = (0, external_utils_js_namespaceObject.getPathname)(context);
|
|
66
84
|
if (i18nextDetector) (0, detection_middleware_js_namespaceObject.useI18nextLanguageDetector)(i18nInstance);
|
|
67
85
|
const mergedDetection = (0, detection_index_js_namespaceObject.mergeDetectionOptions)(i18nextDetector, detection, localePathRedirect, userInitOptions);
|
|
@@ -121,16 +139,18 @@ const i18nPlugin = (options)=>({
|
|
|
121
139
|
]);
|
|
122
140
|
(0, external_hooks_js_namespaceObject.useSdkResourcesLoader)(i18nInstance, setForceUpdate);
|
|
123
141
|
(0, external_hooks_js_namespaceObject.useLanguageSync)(i18nInstance, localePathRedirect, languages, runtimeContextRef, prevLangRef, setLang);
|
|
124
|
-
(0, external_hooks_js_namespaceObject.useClientSideRedirect)(i18nInstance, localePathRedirect, languages, fallbackLanguage, ignoreRedirectRoutes);
|
|
125
|
-
const contextValue = (0, external_react_namespaceObject.useMemo)(()=>(0, external_hooks_js_namespaceObject.createContextValue)(lang, i18nInstance, entryName, languages, localePathRedirect, ignoreRedirectRoutes, setLang), [
|
|
142
|
+
(0, external_hooks_js_namespaceObject.useClientSideRedirect)(i18nInstance, localePathRedirect, languages, fallbackLanguage, ignoreRedirectRoutes, localisedUrls);
|
|
143
|
+
const contextValue = (0, external_react_namespaceObject.useMemo)(()=>(0, external_hooks_js_namespaceObject.createContextValue)(lang, i18nInstance, entryName, languages, localePathRedirect, ignoreRedirectRoutes, localisedUrls, setLang), [
|
|
126
144
|
lang,
|
|
127
145
|
i18nInstance,
|
|
128
146
|
entryName,
|
|
129
147
|
languages,
|
|
130
148
|
localePathRedirect,
|
|
131
149
|
ignoreRedirectRoutes,
|
|
150
|
+
localisedUrls,
|
|
132
151
|
forceUpdate
|
|
133
152
|
]);
|
|
153
|
+
const children = props.children;
|
|
134
154
|
const appContent = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
|
|
135
155
|
children: [
|
|
136
156
|
Boolean(htmlLangAttr) && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(head_namespaceObject.Helmet, {
|
|
@@ -140,9 +160,10 @@ const i18nPlugin = (options)=>({
|
|
|
140
160
|
}),
|
|
141
161
|
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_context_js_namespaceObject.ModernI18nProvider, {
|
|
142
162
|
value: contextValue,
|
|
143
|
-
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
|
|
144
|
-
...props
|
|
145
|
-
|
|
163
|
+
children: App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
|
|
164
|
+
...props,
|
|
165
|
+
children: children
|
|
166
|
+
}) : children
|
|
146
167
|
})
|
|
147
168
|
]
|
|
148
169
|
});
|
|
@@ -160,13 +181,27 @@ const i18nPlugin = (options)=>({
|
|
|
160
181
|
});
|
|
161
182
|
const runtime = i18nPlugin;
|
|
162
183
|
exports.I18nLink = __webpack_exports__.I18nLink;
|
|
184
|
+
exports.Link = __webpack_exports__.Link;
|
|
185
|
+
exports.buildLocalizedUrl = __webpack_exports__.buildLocalizedUrl;
|
|
186
|
+
exports.canonicalPath = __webpack_exports__.canonicalPath;
|
|
163
187
|
exports["default"] = __webpack_exports__["default"];
|
|
164
188
|
exports.i18nPlugin = __webpack_exports__.i18nPlugin;
|
|
189
|
+
exports.localizePath = __webpack_exports__.localizePath;
|
|
190
|
+
exports.splitUrlTarget = __webpack_exports__.splitUrlTarget;
|
|
191
|
+
exports.useLocalizedLocation = __webpack_exports__.useLocalizedLocation;
|
|
192
|
+
exports.useLocalizedPaths = __webpack_exports__.useLocalizedPaths;
|
|
165
193
|
exports.useModernI18n = __webpack_exports__.useModernI18n;
|
|
166
194
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
167
195
|
"I18nLink",
|
|
196
|
+
"Link",
|
|
197
|
+
"buildLocalizedUrl",
|
|
198
|
+
"canonicalPath",
|
|
168
199
|
"default",
|
|
169
200
|
"i18nPlugin",
|
|
201
|
+
"localizePath",
|
|
202
|
+
"splitUrlTarget",
|
|
203
|
+
"useLocalizedLocation",
|
|
204
|
+
"useLocalizedPaths",
|
|
170
205
|
"useModernI18n"
|
|
171
206
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
172
207
|
Object.defineProperty(exports, '__esModule', {
|
|
@@ -0,0 +1,102 @@
|
|
|
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
|
+
canonicalPath: ()=>canonicalPath,
|
|
32
|
+
localizePath: ()=>localizePath,
|
|
33
|
+
useLocalizedLocation: ()=>useLocalizedLocation,
|
|
34
|
+
useLocalizedPaths: ()=>useLocalizedPaths
|
|
35
|
+
});
|
|
36
|
+
const external_react_namespaceObject = require("react");
|
|
37
|
+
const localisedUrls_js_namespaceObject = require("../shared/localisedUrls.js");
|
|
38
|
+
const external_context_js_namespaceObject = require("./context.js");
|
|
39
|
+
const external_routerAdapter_js_namespaceObject = require("./routerAdapter.js");
|
|
40
|
+
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.localisedUrls);
|
|
42
|
+
const canonicalPath = (target, config)=>{
|
|
43
|
+
const { pathname, search, hash } = (0, external_utils_js_namespaceObject.splitUrlTarget)(target);
|
|
44
|
+
const resolvedPath = (0, localisedUrls_js_namespaceObject.canonicalTargetPathname)(pathname, config.languages, config.localisedUrls);
|
|
45
|
+
return `${resolvedPath}${search}${hash}`;
|
|
46
|
+
};
|
|
47
|
+
const useLocalizedPaths = ()=>{
|
|
48
|
+
const { supportedLanguages, localisedUrls } = (0, external_context_js_namespaceObject.useModernI18n)();
|
|
49
|
+
return (0, external_react_namespaceObject.useMemo)(()=>{
|
|
50
|
+
const config = {
|
|
51
|
+
languages: supportedLanguages,
|
|
52
|
+
localisedUrls
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
localizePath: (pathname, language)=>localizePath(pathname, language, config),
|
|
56
|
+
canonicalPath: (pathname)=>canonicalPath(pathname, config)
|
|
57
|
+
};
|
|
58
|
+
}, [
|
|
59
|
+
supportedLanguages,
|
|
60
|
+
localisedUrls
|
|
61
|
+
]);
|
|
62
|
+
};
|
|
63
|
+
const useLocalizedLocation = ()=>{
|
|
64
|
+
const { language, supportedLanguages, localisedUrls } = (0, external_context_js_namespaceObject.useModernI18n)();
|
|
65
|
+
const { location } = (0, external_routerAdapter_js_namespaceObject.useI18nRouterAdapter)();
|
|
66
|
+
const pathname = location?.pathname ?? '/';
|
|
67
|
+
const search = location?.search ?? '';
|
|
68
|
+
const hash = location?.hash ?? '';
|
|
69
|
+
return (0, external_react_namespaceObject.useMemo)(()=>{
|
|
70
|
+
const config = {
|
|
71
|
+
languages: supportedLanguages,
|
|
72
|
+
localisedUrls
|
|
73
|
+
};
|
|
74
|
+
const alternates = {};
|
|
75
|
+
for (const supportedLanguage of supportedLanguages)alternates[supportedLanguage] = `${localizePath(pathname, supportedLanguage, config)}${search}${hash}`;
|
|
76
|
+
return {
|
|
77
|
+
language,
|
|
78
|
+
canonical: canonicalPath(pathname, config),
|
|
79
|
+
alternates
|
|
80
|
+
};
|
|
81
|
+
}, [
|
|
82
|
+
language,
|
|
83
|
+
supportedLanguages,
|
|
84
|
+
localisedUrls,
|
|
85
|
+
pathname,
|
|
86
|
+
search,
|
|
87
|
+
hash
|
|
88
|
+
]);
|
|
89
|
+
};
|
|
90
|
+
exports.canonicalPath = __webpack_exports__.canonicalPath;
|
|
91
|
+
exports.localizePath = __webpack_exports__.localizePath;
|
|
92
|
+
exports.useLocalizedLocation = __webpack_exports__.useLocalizedLocation;
|
|
93
|
+
exports.useLocalizedPaths = __webpack_exports__.useLocalizedPaths;
|
|
94
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
95
|
+
"canonicalPath",
|
|
96
|
+
"localizePath",
|
|
97
|
+
"useLocalizedLocation",
|
|
98
|
+
"useLocalizedPaths"
|
|
99
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
100
|
+
Object.defineProperty(exports, '__esModule', {
|
|
101
|
+
value: true
|
|
102
|
+
});
|
|
@@ -0,0 +1,167 @@
|
|
|
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
|
+
useI18nRouterAdapter: ()=>useI18nRouterAdapter
|
|
32
|
+
});
|
|
33
|
+
const runtime_namespaceObject = require("@modern-js/runtime");
|
|
34
|
+
const context_namespaceObject = require("@modern-js/runtime/context");
|
|
35
|
+
const router_namespaceObject = require("@modern-js/runtime/router");
|
|
36
|
+
const external_react_namespaceObject = require("react");
|
|
37
|
+
const normalizeUrlPart = (value, prefix)=>{
|
|
38
|
+
if ('string' != typeof value || !value) return '';
|
|
39
|
+
return value.startsWith(prefix) ? value : `${prefix}${value}`;
|
|
40
|
+
};
|
|
41
|
+
const normalizeLocation = (location)=>{
|
|
42
|
+
if (!location || 'object' != typeof location) return null;
|
|
43
|
+
const locationValue = location;
|
|
44
|
+
if ('string' != typeof locationValue.pathname) return null;
|
|
45
|
+
return {
|
|
46
|
+
pathname: locationValue.pathname,
|
|
47
|
+
search: normalizeUrlPart('string' == typeof locationValue.search ? locationValue.search : locationValue.searchStr, '?'),
|
|
48
|
+
hash: normalizeUrlPart(locationValue.hash, '#')
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
const getWindowLocation = ()=>{
|
|
52
|
+
if (!(0, runtime_namespaceObject.isBrowser)()) return null;
|
|
53
|
+
return {
|
|
54
|
+
pathname: window.location.pathname,
|
|
55
|
+
search: window.location.search,
|
|
56
|
+
hash: window.location.hash
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
const getRouterFramework = (runtimeContext, internalContext, inReactRouter)=>{
|
|
60
|
+
const framework = (0, context_namespaceObject.getRouterRuntimeState)(internalContext)?.framework || (0, context_namespaceObject.getRouterRuntimeState)(runtimeContext)?.framework;
|
|
61
|
+
if (framework) return framework;
|
|
62
|
+
if (internalContext.router?.useRouter || runtimeContext.router?.useRouter) return 'tanstack';
|
|
63
|
+
if (internalContext.router?.useLocation || internalContext.router?.useHref || runtimeContext.router?.useLocation || runtimeContext.router?.useHref) return 'react-router';
|
|
64
|
+
if (inReactRouter) return 'react-router';
|
|
65
|
+
};
|
|
66
|
+
const getRouterInstance = (internalContext, contextRouter)=>{
|
|
67
|
+
if (contextRouter) return contextRouter;
|
|
68
|
+
const router = (0, context_namespaceObject.getRouterRuntimeState)(internalContext)?.instance;
|
|
69
|
+
if (!router || 'object' != typeof router) return null;
|
|
70
|
+
return router;
|
|
71
|
+
};
|
|
72
|
+
const getRouterStateLocation = (internalContext, contextRouter)=>{
|
|
73
|
+
const router = getRouterInstance(internalContext, contextRouter);
|
|
74
|
+
return normalizeLocation(router?.stores?.location?.get?.()) || normalizeLocation(router?.state?.location);
|
|
75
|
+
};
|
|
76
|
+
const getRouterParams = (internalContext, contextRouter)=>{
|
|
77
|
+
const router = getRouterInstance(internalContext, contextRouter);
|
|
78
|
+
const matches = router?.stores?.matches?.get?.() || router?.state?.matches;
|
|
79
|
+
if (!Array.isArray(matches)) return {};
|
|
80
|
+
return matches.reduce((params, match)=>{
|
|
81
|
+
if (match?.params) Object.assign(params, match.params);
|
|
82
|
+
return params;
|
|
83
|
+
}, {});
|
|
84
|
+
};
|
|
85
|
+
const useI18nRouterAdapter = ()=>{
|
|
86
|
+
const runtimeContext = (0, external_react_namespaceObject.useContext)(runtime_namespaceObject.RuntimeContext);
|
|
87
|
+
const internalContext = (0, external_react_namespaceObject.useContext)(context_namespaceObject.InternalRuntimeContext);
|
|
88
|
+
const inReactRouter = (0, router_namespaceObject.useInRouterContext)();
|
|
89
|
+
const reactRouterNavigate = inReactRouter ? (0, router_namespaceObject.useNavigate)() : null;
|
|
90
|
+
const reactRouterLocation = inReactRouter ? (0, router_namespaceObject.useLocation)() : null;
|
|
91
|
+
const reactRouterParams = inReactRouter ? (0, router_namespaceObject.useParams)() : {};
|
|
92
|
+
const framework = getRouterFramework(runtimeContext, internalContext, inReactRouter);
|
|
93
|
+
const contextUseRouter = inReactRouter || 'tanstack' !== framework ? void 0 : internalContext.router?.useRouter || runtimeContext.router?.useRouter;
|
|
94
|
+
const contextRouter = contextUseRouter ? contextUseRouter({
|
|
95
|
+
warn: false
|
|
96
|
+
}) : null;
|
|
97
|
+
const [, setRouterVersion] = (0, external_react_namespaceObject.useState)(0);
|
|
98
|
+
const hasRouter = 'tanstack' === framework || 'react-router' === framework || Boolean(reactRouterNavigate);
|
|
99
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
100
|
+
if ('tanstack' !== framework) return;
|
|
101
|
+
const router = getRouterInstance(internalContext, contextRouter);
|
|
102
|
+
if (!router) return;
|
|
103
|
+
const update = ()=>setRouterVersion((version)=>version + 1);
|
|
104
|
+
const unsubscribers = [];
|
|
105
|
+
if ('function' == typeof router.stores?.location?.subscribe) {
|
|
106
|
+
const unsubscribe = router.stores.location.subscribe(update);
|
|
107
|
+
if ('function' == typeof unsubscribe) unsubscribers.push(unsubscribe);
|
|
108
|
+
}
|
|
109
|
+
if ('function' == typeof router.subscribe) for (const eventType of [
|
|
110
|
+
'onBeforeNavigate',
|
|
111
|
+
'onBeforeLoad'
|
|
112
|
+
]){
|
|
113
|
+
const unsubscribe = router.subscribe(eventType, update);
|
|
114
|
+
if ('function' == typeof unsubscribe) unsubscribers.push(unsubscribe);
|
|
115
|
+
}
|
|
116
|
+
return ()=>{
|
|
117
|
+
for (const unsubscribe of unsubscribers)unsubscribe();
|
|
118
|
+
};
|
|
119
|
+
}, [
|
|
120
|
+
contextRouter,
|
|
121
|
+
framework,
|
|
122
|
+
internalContext
|
|
123
|
+
]);
|
|
124
|
+
const navigate = (0, external_react_namespaceObject.useCallback)((href, options)=>{
|
|
125
|
+
const router = getRouterInstance(internalContext, contextRouter);
|
|
126
|
+
const activeFramework = getRouterFramework(runtimeContext, internalContext, inReactRouter);
|
|
127
|
+
if ('tanstack' === activeFramework) {
|
|
128
|
+
if ('function' == typeof router?.navigate) return router.navigate({
|
|
129
|
+
to: href,
|
|
130
|
+
replace: options?.replace,
|
|
131
|
+
...options?.state === void 0 ? {} : {
|
|
132
|
+
state: options.state
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
throw new Error('TanStack router instance is not available.');
|
|
136
|
+
}
|
|
137
|
+
if (reactRouterNavigate) return reactRouterNavigate(href, options);
|
|
138
|
+
if ('react-router' === activeFramework) {
|
|
139
|
+
if ('function' == typeof router?.navigate) return router.navigate(href, options);
|
|
140
|
+
throw new Error('React Router instance is not available.');
|
|
141
|
+
}
|
|
142
|
+
}, [
|
|
143
|
+
contextRouter,
|
|
144
|
+
internalContext,
|
|
145
|
+
inReactRouter,
|
|
146
|
+
reactRouterNavigate,
|
|
147
|
+
runtimeContext
|
|
148
|
+
]);
|
|
149
|
+
const location = (reactRouterLocation ? normalizeLocation(reactRouterLocation) : getRouterStateLocation(internalContext, contextRouter)) || getWindowLocation();
|
|
150
|
+
const params = inReactRouter ? reactRouterParams : getRouterParams(internalContext, contextRouter);
|
|
151
|
+
const Link = 'tanstack' === framework ? internalContext.router?.Link || runtimeContext.router?.Link || null : 'react-router' === framework || inReactRouter ? router_namespaceObject.Link : null;
|
|
152
|
+
return {
|
|
153
|
+
framework,
|
|
154
|
+
hasRouter,
|
|
155
|
+
location,
|
|
156
|
+
navigate: hasRouter ? navigate : null,
|
|
157
|
+
Link,
|
|
158
|
+
params
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
exports.useI18nRouterAdapter = __webpack_exports__.useI18nRouterAdapter;
|
|
162
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
163
|
+
"useI18nRouterAdapter"
|
|
164
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
165
|
+
Object.defineProperty(exports, '__esModule', {
|
|
166
|
+
value: true
|
|
167
|
+
});
|