@bleedingdev/modern-js-plugin-i18n 3.4.0-ultramodern.1 → 3.4.0-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 +2 -1
- package/dist/cjs/runtime/core.js +204 -0
- package/dist/cjs/runtime/index.js +44 -173
- package/dist/cjs/runtime/no-react-i18next.js +76 -0
- package/dist/esm/cli/index.mjs +2 -1
- package/dist/esm/runtime/core.mjs +139 -0
- package/dist/esm/runtime/index.mjs +5 -140
- package/dist/esm/runtime/no-react-i18next.mjs +6 -0
- package/dist/esm-node/cli/index.mjs +2 -1
- package/dist/esm-node/runtime/core.mjs +140 -0
- package/dist/esm-node/runtime/index.mjs +5 -140
- package/dist/esm-node/runtime/no-react-i18next.mjs +7 -0
- package/dist/types/runtime/core.d.ts +30 -0
- package/dist/types/runtime/index.d.ts +2 -24
- package/dist/types/runtime/no-react-i18next.d.ts +3 -0
- package/package.json +21 -11
- package/rstest.config.mts +1 -0
- package/src/cli/index.ts +6 -1
- package/src/runtime/core.tsx +335 -0
- package/src/runtime/index.tsx +4 -316
- package/src/runtime/no-react-i18next.tsx +7 -0
- package/tests/localisedUrls.test.ts +35 -0
- package/tests/reactI18nextRuntimeBoundary.test.ts +27 -0
package/dist/cjs/cli/index.js
CHANGED
|
@@ -64,9 +64,10 @@ const i18nPlugin = (options = {})=>({
|
|
|
64
64
|
backend: backendOptions,
|
|
65
65
|
...extendedConfig
|
|
66
66
|
};
|
|
67
|
+
const runtimePluginPath = customPlugin?.runtime?.path || (false === config.reactI18next ? `@${metaName}/plugin-i18n/runtime/no-react-i18next` : `@${metaName}/plugin-i18n/runtime`);
|
|
67
68
|
plugins.push({
|
|
68
69
|
name: customPlugin?.runtime?.name || 'i18n',
|
|
69
|
-
path:
|
|
70
|
+
path: runtimePluginPath,
|
|
70
71
|
config
|
|
71
72
|
});
|
|
72
73
|
return {
|
|
@@ -0,0 +1,204 @@
|
|
|
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
|
+
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,
|
|
35
|
+
createI18nPlugin: ()=>createI18nPlugin,
|
|
36
|
+
localizePath: ()=>external_localizedPaths_js_namespaceObject.localizePath,
|
|
37
|
+
splitUrlTarget: ()=>external_utils_js_namespaceObject.splitUrlTarget,
|
|
38
|
+
useLocalizedLocation: ()=>external_localizedPaths_js_namespaceObject.useLocalizedLocation,
|
|
39
|
+
useLocalizedPaths: ()=>external_localizedPaths_js_namespaceObject.useLocalizedPaths,
|
|
40
|
+
useModernI18n: ()=>external_context_js_namespaceObject.useModernI18n
|
|
41
|
+
});
|
|
42
|
+
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
43
|
+
const runtime_namespaceObject = require("@modern-js/runtime");
|
|
44
|
+
const head_namespaceObject = require("@modern-js/runtime/head");
|
|
45
|
+
const merge_namespaceObject = require("@modern-js/runtime-utils/merge");
|
|
46
|
+
const external_react_namespaceObject = require("react");
|
|
47
|
+
const external_context_js_namespaceObject = require("./context.js");
|
|
48
|
+
const external_hooks_js_namespaceObject = require("./hooks.js");
|
|
49
|
+
const index_js_namespaceObject = require("./i18n/index.js");
|
|
50
|
+
const backend_index_js_namespaceObject = require("./i18n/backend/index.js");
|
|
51
|
+
const middleware_js_namespaceObject = require("./i18n/backend/middleware.js");
|
|
52
|
+
const detection_index_js_namespaceObject = require("./i18n/detection/index.js");
|
|
53
|
+
const detection_middleware_js_namespaceObject = require("./i18n/detection/middleware.js");
|
|
54
|
+
const instance_js_namespaceObject = require("./i18n/instance.js");
|
|
55
|
+
const utils_js_namespaceObject = require("./i18n/utils.js");
|
|
56
|
+
const external_utils_js_namespaceObject = require("./utils.js");
|
|
57
|
+
require("./types.js");
|
|
58
|
+
const external_I18nLink_js_namespaceObject = require("./I18nLink.js");
|
|
59
|
+
const external_Link_js_namespaceObject = require("./Link.js");
|
|
60
|
+
const external_localizedPaths_js_namespaceObject = require("./localizedPaths.js");
|
|
61
|
+
const createI18nPlugin = (loadReactI18nextIntegration)=>(options)=>({
|
|
62
|
+
name: '@modern-js/plugin-i18n',
|
|
63
|
+
setup: (api)=>{
|
|
64
|
+
const { entryName, i18nInstance: userI18nInstance, initOptions, localeDetection, backend, htmlLangAttr = false, reactI18next = true } = options;
|
|
65
|
+
const { localePathRedirect = false, i18nextDetector = true, languages = [], fallbackLanguage = 'en', detection, ignoreRedirectRoutes, localisedUrls } = localeDetection || {};
|
|
66
|
+
const { enabled: backendEnabled = false } = backend || {};
|
|
67
|
+
let latestI18nInstance;
|
|
68
|
+
let I18nextProvider;
|
|
69
|
+
const resolveReactI18nextIntegration = async ()=>{
|
|
70
|
+
if (!reactI18next) return null;
|
|
71
|
+
return loadReactI18nextIntegration?.() ?? null;
|
|
72
|
+
};
|
|
73
|
+
api.onBeforeRender(async (context)=>{
|
|
74
|
+
let i18nInstance = await (0, index_js_namespaceObject.getI18nInstance)(userI18nInstance);
|
|
75
|
+
const { i18n: otherConfig } = api.getRuntimeConfig();
|
|
76
|
+
const { initOptions: otherInitOptions } = otherConfig || {};
|
|
77
|
+
const userInitOptions = (0, merge_namespaceObject.merge)(otherInitOptions || {}, initOptions || {});
|
|
78
|
+
const reactI18nextIntegration = await resolveReactI18nextIntegration();
|
|
79
|
+
I18nextProvider = reactI18nextIntegration?.I18nextProvider ?? null;
|
|
80
|
+
if (reactI18nextIntegration?.initReactI18next) i18nInstance.use(reactI18nextIntegration.initReactI18next);
|
|
81
|
+
const pathname = (0, external_utils_js_namespaceObject.getPathname)(context);
|
|
82
|
+
if (i18nextDetector) (0, detection_middleware_js_namespaceObject.useI18nextLanguageDetector)(i18nInstance);
|
|
83
|
+
const mergedDetection = (0, detection_index_js_namespaceObject.mergeDetectionOptions)(i18nextDetector, detection, localePathRedirect, userInitOptions);
|
|
84
|
+
const mergedBackend = (0, backend_index_js_namespaceObject.mergeBackendOptions)(backend, userInitOptions);
|
|
85
|
+
const hasSdkConfig = 'function' == typeof userInitOptions?.backend?.sdk || mergedBackend?.sdk && 'function' == typeof mergedBackend.sdk;
|
|
86
|
+
if (mergedBackend && (backendEnabled || hasSdkConfig)) (0, middleware_js_namespaceObject.useI18nextBackend)(i18nInstance, mergedBackend);
|
|
87
|
+
const { finalLanguage } = await (0, detection_index_js_namespaceObject.detectLanguageWithPriority)(i18nInstance, {
|
|
88
|
+
languages,
|
|
89
|
+
fallbackLanguage,
|
|
90
|
+
localePathRedirect,
|
|
91
|
+
i18nextDetector,
|
|
92
|
+
detection,
|
|
93
|
+
userInitOptions,
|
|
94
|
+
mergedBackend,
|
|
95
|
+
pathname,
|
|
96
|
+
ssrContext: context.ssrContext
|
|
97
|
+
});
|
|
98
|
+
await (0, utils_js_namespaceObject.initializeI18nInstance)(i18nInstance, finalLanguage, fallbackLanguage, languages, mergedDetection, mergedBackend, userInitOptions);
|
|
99
|
+
if (!(0, runtime_namespaceObject.isBrowser)() && i18nInstance.cloneInstance) {
|
|
100
|
+
i18nInstance = i18nInstance.cloneInstance();
|
|
101
|
+
await (0, utils_js_namespaceObject.setupClonedInstance)(i18nInstance, finalLanguage, fallbackLanguage, languages, backendEnabled, backend, i18nextDetector, detection, localePathRedirect, userInitOptions);
|
|
102
|
+
}
|
|
103
|
+
if (localePathRedirect) await (0, utils_js_namespaceObject.ensureLanguageMatch)(i18nInstance, finalLanguage);
|
|
104
|
+
if (!(0, runtime_namespaceObject.isBrowser)()) (0, detection_index_js_namespaceObject.exportServerLngToWindow)(context, finalLanguage);
|
|
105
|
+
context.i18nInstance = i18nInstance;
|
|
106
|
+
latestI18nInstance = i18nInstance;
|
|
107
|
+
context.changeLanguage = async (newLang)=>{
|
|
108
|
+
await (0, utils_js_namespaceObject.changeI18nLanguage)(i18nInstance, newLang, {
|
|
109
|
+
detectionOptions: mergedDetection
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
api.wrapRoot((App)=>(props)=>{
|
|
114
|
+
const runtimeContext = (0, external_react_namespaceObject.useContext)(runtime_namespaceObject.RuntimeContext);
|
|
115
|
+
const i18nInstance = runtimeContext.i18nInstance || latestI18nInstance;
|
|
116
|
+
const initialLang = (0, external_react_namespaceObject.useMemo)(()=>i18nInstance?.language || (localeDetection?.fallbackLanguage ?? 'en'), [
|
|
117
|
+
i18nInstance?.language,
|
|
118
|
+
localeDetection?.fallbackLanguage
|
|
119
|
+
]);
|
|
120
|
+
const [lang, setLang] = (0, external_react_namespaceObject.useState)(initialLang);
|
|
121
|
+
const [forceUpdate, setForceUpdate] = (0, external_react_namespaceObject.useState)(0);
|
|
122
|
+
const prevLangRef = (0, external_react_namespaceObject.useRef)(lang);
|
|
123
|
+
const runtimeContextRef = (0, external_react_namespaceObject.useRef)(runtimeContext);
|
|
124
|
+
runtimeContextRef.current = runtimeContext;
|
|
125
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
126
|
+
if (i18nInstance?.language) {
|
|
127
|
+
const translator = i18nInstance.translator;
|
|
128
|
+
if (translator) translator.language = i18nInstance.language;
|
|
129
|
+
}
|
|
130
|
+
}, [
|
|
131
|
+
i18nInstance?.language
|
|
132
|
+
]);
|
|
133
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
134
|
+
prevLangRef.current = lang;
|
|
135
|
+
}, [
|
|
136
|
+
lang
|
|
137
|
+
]);
|
|
138
|
+
(0, external_hooks_js_namespaceObject.useSdkResourcesLoader)(i18nInstance, setForceUpdate);
|
|
139
|
+
(0, external_hooks_js_namespaceObject.useLanguageSync)(i18nInstance, localePathRedirect, languages, runtimeContextRef, prevLangRef, setLang);
|
|
140
|
+
(0, external_hooks_js_namespaceObject.useClientSideRedirect)(i18nInstance, localePathRedirect, languages, fallbackLanguage, ignoreRedirectRoutes, localisedUrls);
|
|
141
|
+
const contextValue = (0, external_react_namespaceObject.useMemo)(()=>(0, external_hooks_js_namespaceObject.createContextValue)(lang, i18nInstance, entryName, languages, localePathRedirect, ignoreRedirectRoutes, localisedUrls, setLang), [
|
|
142
|
+
lang,
|
|
143
|
+
i18nInstance,
|
|
144
|
+
entryName,
|
|
145
|
+
languages,
|
|
146
|
+
localePathRedirect,
|
|
147
|
+
ignoreRedirectRoutes,
|
|
148
|
+
localisedUrls,
|
|
149
|
+
forceUpdate
|
|
150
|
+
]);
|
|
151
|
+
const children = props.children;
|
|
152
|
+
const appContent = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
|
|
153
|
+
children: [
|
|
154
|
+
Boolean(htmlLangAttr) && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(head_namespaceObject.Helmet, {
|
|
155
|
+
htmlAttributes: {
|
|
156
|
+
lang
|
|
157
|
+
}
|
|
158
|
+
}),
|
|
159
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_context_js_namespaceObject.ModernI18nProvider, {
|
|
160
|
+
value: contextValue,
|
|
161
|
+
children: App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
|
|
162
|
+
...props,
|
|
163
|
+
children: children
|
|
164
|
+
}) : children
|
|
165
|
+
})
|
|
166
|
+
]
|
|
167
|
+
});
|
|
168
|
+
if (!i18nInstance) return appContent;
|
|
169
|
+
if (I18nextProvider) {
|
|
170
|
+
const i18nextInstanceForProvider = (0, instance_js_namespaceObject.getI18nextInstanceForProvider)(i18nInstance);
|
|
171
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(I18nextProvider, {
|
|
172
|
+
i18n: i18nextInstanceForProvider,
|
|
173
|
+
children: appContent
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
return appContent;
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
exports.I18nLink = __webpack_exports__.I18nLink;
|
|
181
|
+
exports.Link = __webpack_exports__.Link;
|
|
182
|
+
exports.buildLocalizedUrl = __webpack_exports__.buildLocalizedUrl;
|
|
183
|
+
exports.canonicalPath = __webpack_exports__.canonicalPath;
|
|
184
|
+
exports.createI18nPlugin = __webpack_exports__.createI18nPlugin;
|
|
185
|
+
exports.localizePath = __webpack_exports__.localizePath;
|
|
186
|
+
exports.splitUrlTarget = __webpack_exports__.splitUrlTarget;
|
|
187
|
+
exports.useLocalizedLocation = __webpack_exports__.useLocalizedLocation;
|
|
188
|
+
exports.useLocalizedPaths = __webpack_exports__.useLocalizedPaths;
|
|
189
|
+
exports.useModernI18n = __webpack_exports__.useModernI18n;
|
|
190
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
191
|
+
"I18nLink",
|
|
192
|
+
"Link",
|
|
193
|
+
"buildLocalizedUrl",
|
|
194
|
+
"canonicalPath",
|
|
195
|
+
"createI18nPlugin",
|
|
196
|
+
"localizePath",
|
|
197
|
+
"splitUrlTarget",
|
|
198
|
+
"useLocalizedLocation",
|
|
199
|
+
"useLocalizedPaths",
|
|
200
|
+
"useModernI18n"
|
|
201
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
202
|
+
Object.defineProperty(exports, '__esModule', {
|
|
203
|
+
value: true
|
|
204
|
+
});
|
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
2
|
+
var __webpack_modules__ = {
|
|
3
|
+
"./core" (module) {
|
|
4
|
+
module.exports = require("./core.js");
|
|
5
|
+
},
|
|
6
|
+
"./i18n/react-i18next" (module) {
|
|
7
|
+
module.exports = require("./i18n/react-i18next.js");
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var __webpack_module_cache__ = {};
|
|
11
|
+
function __webpack_require__(moduleId) {
|
|
12
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
13
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
14
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
15
|
+
exports: {}
|
|
16
|
+
};
|
|
17
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
18
|
+
return module.exports;
|
|
19
|
+
}
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.n = (module)=>{
|
|
22
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
23
|
+
__webpack_require__.d(getter, {
|
|
24
|
+
a: getter
|
|
25
|
+
});
|
|
26
|
+
return getter;
|
|
27
|
+
};
|
|
28
|
+
})();
|
|
3
29
|
(()=>{
|
|
4
30
|
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
31
|
var define = (defs, kind)=>{
|
|
@@ -26,183 +52,28 @@ var __webpack_require__ = {};
|
|
|
26
52
|
};
|
|
27
53
|
})();
|
|
28
54
|
var __webpack_exports__ = {};
|
|
29
|
-
|
|
30
|
-
__webpack_require__.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const runtime_namespaceObject = require("@modern-js/runtime");
|
|
45
|
-
const head_namespaceObject = require("@modern-js/runtime/head");
|
|
46
|
-
const merge_namespaceObject = require("@modern-js/runtime-utils/merge");
|
|
47
|
-
const external_react_namespaceObject = require("react");
|
|
48
|
-
const external_context_js_namespaceObject = require("./context.js");
|
|
49
|
-
const external_hooks_js_namespaceObject = require("./hooks.js");
|
|
50
|
-
const index_js_namespaceObject = require("./i18n/index.js");
|
|
51
|
-
const backend_index_js_namespaceObject = require("./i18n/backend/index.js");
|
|
52
|
-
const middleware_js_namespaceObject = require("./i18n/backend/middleware.js");
|
|
53
|
-
const detection_index_js_namespaceObject = require("./i18n/detection/index.js");
|
|
54
|
-
const detection_middleware_js_namespaceObject = require("./i18n/detection/middleware.js");
|
|
55
|
-
const instance_js_namespaceObject = require("./i18n/instance.js");
|
|
56
|
-
const utils_js_namespaceObject = require("./i18n/utils.js");
|
|
57
|
-
const external_utils_js_namespaceObject = require("./utils.js");
|
|
58
|
-
require("./types.js");
|
|
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");
|
|
62
|
-
const i18nPlugin = (options)=>({
|
|
63
|
-
name: '@modern-js/plugin-i18n',
|
|
64
|
-
setup: (api)=>{
|
|
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 || {};
|
|
67
|
-
const { enabled: backendEnabled = false } = backend || {};
|
|
68
|
-
let latestI18nInstance;
|
|
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
|
-
};
|
|
75
|
-
api.onBeforeRender(async (context)=>{
|
|
76
|
-
let i18nInstance = await (0, index_js_namespaceObject.getI18nInstance)(userI18nInstance);
|
|
77
|
-
const { i18n: otherConfig } = api.getRuntimeConfig();
|
|
78
|
-
const { initOptions: otherInitOptions } = otherConfig || {};
|
|
79
|
-
const userInitOptions = (0, merge_namespaceObject.merge)(otherInitOptions || {}, initOptions || {});
|
|
80
|
-
const reactI18nextIntegration = await loadReactI18nextIntegration();
|
|
81
|
-
I18nextProvider = reactI18nextIntegration?.I18nextProvider ?? null;
|
|
82
|
-
if (reactI18nextIntegration?.initReactI18next) i18nInstance.use(reactI18nextIntegration.initReactI18next);
|
|
83
|
-
const pathname = (0, external_utils_js_namespaceObject.getPathname)(context);
|
|
84
|
-
if (i18nextDetector) (0, detection_middleware_js_namespaceObject.useI18nextLanguageDetector)(i18nInstance);
|
|
85
|
-
const mergedDetection = (0, detection_index_js_namespaceObject.mergeDetectionOptions)(i18nextDetector, detection, localePathRedirect, userInitOptions);
|
|
86
|
-
const mergedBackend = (0, backend_index_js_namespaceObject.mergeBackendOptions)(backend, userInitOptions);
|
|
87
|
-
const hasSdkConfig = 'function' == typeof userInitOptions?.backend?.sdk || mergedBackend?.sdk && 'function' == typeof mergedBackend.sdk;
|
|
88
|
-
if (mergedBackend && (backendEnabled || hasSdkConfig)) (0, middleware_js_namespaceObject.useI18nextBackend)(i18nInstance, mergedBackend);
|
|
89
|
-
const { finalLanguage } = await (0, detection_index_js_namespaceObject.detectLanguageWithPriority)(i18nInstance, {
|
|
90
|
-
languages,
|
|
91
|
-
fallbackLanguage,
|
|
92
|
-
localePathRedirect,
|
|
93
|
-
i18nextDetector,
|
|
94
|
-
detection,
|
|
95
|
-
userInitOptions,
|
|
96
|
-
mergedBackend,
|
|
97
|
-
pathname,
|
|
98
|
-
ssrContext: context.ssrContext
|
|
99
|
-
});
|
|
100
|
-
await (0, utils_js_namespaceObject.initializeI18nInstance)(i18nInstance, finalLanguage, fallbackLanguage, languages, mergedDetection, mergedBackend, userInitOptions);
|
|
101
|
-
if (!(0, runtime_namespaceObject.isBrowser)() && i18nInstance.cloneInstance) {
|
|
102
|
-
i18nInstance = i18nInstance.cloneInstance();
|
|
103
|
-
await (0, utils_js_namespaceObject.setupClonedInstance)(i18nInstance, finalLanguage, fallbackLanguage, languages, backendEnabled, backend, i18nextDetector, detection, localePathRedirect, userInitOptions);
|
|
104
|
-
}
|
|
105
|
-
if (localePathRedirect) await (0, utils_js_namespaceObject.ensureLanguageMatch)(i18nInstance, finalLanguage);
|
|
106
|
-
if (!(0, runtime_namespaceObject.isBrowser)()) (0, detection_index_js_namespaceObject.exportServerLngToWindow)(context, finalLanguage);
|
|
107
|
-
context.i18nInstance = i18nInstance;
|
|
108
|
-
latestI18nInstance = i18nInstance;
|
|
109
|
-
context.changeLanguage = async (newLang)=>{
|
|
110
|
-
await (0, utils_js_namespaceObject.changeI18nLanguage)(i18nInstance, newLang, {
|
|
111
|
-
detectionOptions: mergedDetection
|
|
112
|
-
});
|
|
113
|
-
};
|
|
114
|
-
});
|
|
115
|
-
api.wrapRoot((App)=>(props)=>{
|
|
116
|
-
const runtimeContext = (0, external_react_namespaceObject.useContext)(runtime_namespaceObject.RuntimeContext);
|
|
117
|
-
const i18nInstance = runtimeContext.i18nInstance || latestI18nInstance;
|
|
118
|
-
const initialLang = (0, external_react_namespaceObject.useMemo)(()=>i18nInstance?.language || (localeDetection?.fallbackLanguage ?? 'en'), [
|
|
119
|
-
i18nInstance?.language,
|
|
120
|
-
localeDetection?.fallbackLanguage
|
|
121
|
-
]);
|
|
122
|
-
const [lang, setLang] = (0, external_react_namespaceObject.useState)(initialLang);
|
|
123
|
-
const [forceUpdate, setForceUpdate] = (0, external_react_namespaceObject.useState)(0);
|
|
124
|
-
const prevLangRef = (0, external_react_namespaceObject.useRef)(lang);
|
|
125
|
-
const runtimeContextRef = (0, external_react_namespaceObject.useRef)(runtimeContext);
|
|
126
|
-
runtimeContextRef.current = runtimeContext;
|
|
127
|
-
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
128
|
-
if (i18nInstance?.language) {
|
|
129
|
-
const translator = i18nInstance.translator;
|
|
130
|
-
if (translator) translator.language = i18nInstance.language;
|
|
131
|
-
}
|
|
132
|
-
}, [
|
|
133
|
-
i18nInstance?.language
|
|
134
|
-
]);
|
|
135
|
-
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
136
|
-
prevLangRef.current = lang;
|
|
137
|
-
}, [
|
|
138
|
-
lang
|
|
139
|
-
]);
|
|
140
|
-
(0, external_hooks_js_namespaceObject.useSdkResourcesLoader)(i18nInstance, setForceUpdate);
|
|
141
|
-
(0, external_hooks_js_namespaceObject.useLanguageSync)(i18nInstance, localePathRedirect, languages, runtimeContextRef, prevLangRef, 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), [
|
|
144
|
-
lang,
|
|
145
|
-
i18nInstance,
|
|
146
|
-
entryName,
|
|
147
|
-
languages,
|
|
148
|
-
localePathRedirect,
|
|
149
|
-
ignoreRedirectRoutes,
|
|
150
|
-
localisedUrls,
|
|
151
|
-
forceUpdate
|
|
152
|
-
]);
|
|
153
|
-
const children = props.children;
|
|
154
|
-
const appContent = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
|
|
155
|
-
children: [
|
|
156
|
-
Boolean(htmlLangAttr) && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(head_namespaceObject.Helmet, {
|
|
157
|
-
htmlAttributes: {
|
|
158
|
-
lang
|
|
159
|
-
}
|
|
160
|
-
}),
|
|
161
|
-
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_context_js_namespaceObject.ModernI18nProvider, {
|
|
162
|
-
value: contextValue,
|
|
163
|
-
children: App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
|
|
164
|
-
...props,
|
|
165
|
-
children: children
|
|
166
|
-
}) : children
|
|
167
|
-
})
|
|
168
|
-
]
|
|
169
|
-
});
|
|
170
|
-
if (!i18nInstance) return appContent;
|
|
171
|
-
if (I18nextProvider) {
|
|
172
|
-
const i18nextInstanceForProvider = (0, instance_js_namespaceObject.getI18nextInstanceForProvider)(i18nInstance);
|
|
173
|
-
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(I18nextProvider, {
|
|
174
|
-
i18n: i18nextInstanceForProvider,
|
|
175
|
-
children: appContent
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
return appContent;
|
|
179
|
-
});
|
|
180
|
-
}
|
|
55
|
+
(()=>{
|
|
56
|
+
__webpack_require__.r(__webpack_exports__);
|
|
57
|
+
var _core__rspack_import_0 = __webpack_require__("./core");
|
|
58
|
+
var _i18n_react_i18next__rspack_import_1 = __webpack_require__("./i18n/react-i18next");
|
|
59
|
+
var __rspack_reexport = {};
|
|
60
|
+
for(const __rspack_import_key in _core__rspack_import_0)if ([
|
|
61
|
+
"i18nPlugin",
|
|
62
|
+
"default"
|
|
63
|
+
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_core__rspack_import_0[__rspack_import_key];
|
|
64
|
+
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
65
|
+
const i18nPlugin = (0, _core__rspack_import_0.createI18nPlugin)(_i18n_react_i18next__rspack_import_1.getReactI18nextIntegration);
|
|
66
|
+
const __rspack_default_export = i18nPlugin;
|
|
67
|
+
__webpack_require__.d(__webpack_exports__, {}, {
|
|
68
|
+
default: __rspack_default_export,
|
|
69
|
+
i18nPlugin: i18nPlugin
|
|
181
70
|
});
|
|
182
|
-
|
|
183
|
-
exports.I18nLink = __webpack_exports__.I18nLink;
|
|
184
|
-
exports.Link = __webpack_exports__.Link;
|
|
185
|
-
exports.buildLocalizedUrl = __webpack_exports__.buildLocalizedUrl;
|
|
186
|
-
exports.canonicalPath = __webpack_exports__.canonicalPath;
|
|
71
|
+
})();
|
|
187
72
|
exports["default"] = __webpack_exports__["default"];
|
|
188
73
|
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;
|
|
193
|
-
exports.useModernI18n = __webpack_exports__.useModernI18n;
|
|
194
74
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
195
|
-
"I18nLink",
|
|
196
|
-
"Link",
|
|
197
|
-
"buildLocalizedUrl",
|
|
198
|
-
"canonicalPath",
|
|
199
75
|
"default",
|
|
200
|
-
"i18nPlugin"
|
|
201
|
-
"localizePath",
|
|
202
|
-
"splitUrlTarget",
|
|
203
|
-
"useLocalizedLocation",
|
|
204
|
-
"useLocalizedPaths",
|
|
205
|
-
"useModernI18n"
|
|
76
|
+
"i18nPlugin"
|
|
206
77
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
207
78
|
Object.defineProperty(exports, '__esModule', {
|
|
208
79
|
value: true
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_modules__ = {
|
|
3
|
+
"./core" (module) {
|
|
4
|
+
module.exports = require("./core.js");
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
var __webpack_module_cache__ = {};
|
|
8
|
+
function __webpack_require__(moduleId) {
|
|
9
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
10
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
11
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
12
|
+
exports: {}
|
|
13
|
+
};
|
|
14
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
15
|
+
return module.exports;
|
|
16
|
+
}
|
|
17
|
+
(()=>{
|
|
18
|
+
__webpack_require__.n = (module)=>{
|
|
19
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
20
|
+
__webpack_require__.d(getter, {
|
|
21
|
+
a: getter
|
|
22
|
+
});
|
|
23
|
+
return getter;
|
|
24
|
+
};
|
|
25
|
+
})();
|
|
26
|
+
(()=>{
|
|
27
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
28
|
+
var define = (defs, kind)=>{
|
|
29
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
[kind]: defs[key]
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
define(getters, "get");
|
|
35
|
+
define(values, "value");
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
(()=>{
|
|
39
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
40
|
+
})();
|
|
41
|
+
(()=>{
|
|
42
|
+
__webpack_require__.r = (exports1)=>{
|
|
43
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
44
|
+
value: 'Module'
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
47
|
+
value: true
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
})();
|
|
51
|
+
var __webpack_exports__ = {};
|
|
52
|
+
(()=>{
|
|
53
|
+
__webpack_require__.r(__webpack_exports__);
|
|
54
|
+
var _core__rspack_import_0 = __webpack_require__("./core");
|
|
55
|
+
var __rspack_reexport = {};
|
|
56
|
+
for(const __rspack_import_key in _core__rspack_import_0)if ([
|
|
57
|
+
"i18nPlugin",
|
|
58
|
+
"default"
|
|
59
|
+
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_core__rspack_import_0[__rspack_import_key];
|
|
60
|
+
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
61
|
+
const i18nPlugin = (0, _core__rspack_import_0.createI18nPlugin)();
|
|
62
|
+
const __rspack_default_export = i18nPlugin;
|
|
63
|
+
__webpack_require__.d(__webpack_exports__, {}, {
|
|
64
|
+
default: __rspack_default_export,
|
|
65
|
+
i18nPlugin: i18nPlugin
|
|
66
|
+
});
|
|
67
|
+
})();
|
|
68
|
+
exports["default"] = __webpack_exports__["default"];
|
|
69
|
+
exports.i18nPlugin = __webpack_exports__.i18nPlugin;
|
|
70
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
71
|
+
"default",
|
|
72
|
+
"i18nPlugin"
|
|
73
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
74
|
+
Object.defineProperty(exports, '__esModule', {
|
|
75
|
+
value: true
|
|
76
|
+
});
|
package/dist/esm/cli/index.mjs
CHANGED
|
@@ -31,9 +31,10 @@ const i18nPlugin = (options = {})=>({
|
|
|
31
31
|
backend: backendOptions,
|
|
32
32
|
...extendedConfig
|
|
33
33
|
};
|
|
34
|
+
const runtimePluginPath = customPlugin?.runtime?.path || (false === config.reactI18next ? `@${metaName}/plugin-i18n/runtime/no-react-i18next` : `@${metaName}/plugin-i18n/runtime`);
|
|
34
35
|
plugins.push({
|
|
35
36
|
name: customPlugin?.runtime?.name || 'i18n',
|
|
36
|
-
path:
|
|
37
|
+
path: runtimePluginPath,
|
|
37
38
|
config
|
|
38
39
|
});
|
|
39
40
|
return {
|