@bleedingdev/modern-js-plugin-i18n 3.2.0-ultramodern.30 → 3.2.0-ultramodern.35

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.
@@ -28,8 +28,6 @@ __webpack_require__.d(__webpack_exports__, {
28
28
  getI18nInstance: ()=>getI18nInstance,
29
29
  getI18nWrapperI18nextInstance: ()=>getI18nWrapperI18nextInstance,
30
30
  getI18nextInstanceForProvider: ()=>getI18nextInstanceForProvider,
31
- getI18nextProvider: ()=>getI18nextProvider,
32
- getInitReactI18next: ()=>getInitReactI18next,
33
31
  isI18nInstance: ()=>isI18nInstance,
34
32
  isI18nWrapperInstance: ()=>isI18nWrapperInstance
35
33
  });
@@ -75,16 +73,6 @@ async function createI18nextInstance() {
75
73
  return null;
76
74
  }
77
75
  }
78
- function getOptionalReactI18nextPackageName() {
79
- return "react-i18next";
80
- }
81
- async function tryImportReactI18next() {
82
- try {
83
- return await import(getOptionalReactI18nextPackageName());
84
- } catch (error) {
85
- return null;
86
- }
87
- }
88
76
  function getI18nextInstanceForProvider(instance) {
89
77
  if (isI18nWrapperInstance(instance)) {
90
78
  const i18nextInstance = getI18nWrapperI18nextInstance(instance);
@@ -101,22 +89,10 @@ async function getI18nInstance(userInstance) {
101
89
  if (i18nextInstance) return i18nextInstance;
102
90
  throw new Error('No i18n instance found');
103
91
  }
104
- async function getInitReactI18next() {
105
- const reactI18nextModule = await tryImportReactI18next();
106
- if (reactI18nextModule) return reactI18nextModule.initReactI18next;
107
- return null;
108
- }
109
- async function getI18nextProvider() {
110
- const reactI18nextModule = await tryImportReactI18next();
111
- if (reactI18nextModule) return reactI18nextModule.I18nextProvider;
112
- return null;
113
- }
114
92
  exports.getActualI18nextInstance = __webpack_exports__.getActualI18nextInstance;
115
93
  exports.getI18nInstance = __webpack_exports__.getI18nInstance;
116
94
  exports.getI18nWrapperI18nextInstance = __webpack_exports__.getI18nWrapperI18nextInstance;
117
95
  exports.getI18nextInstanceForProvider = __webpack_exports__.getI18nextInstanceForProvider;
118
- exports.getI18nextProvider = __webpack_exports__.getI18nextProvider;
119
- exports.getInitReactI18next = __webpack_exports__.getInitReactI18next;
120
96
  exports.isI18nInstance = __webpack_exports__.isI18nInstance;
121
97
  exports.isI18nWrapperInstance = __webpack_exports__.isI18nWrapperInstance;
122
98
  for(var __rspack_i in __webpack_exports__)if (-1 === [
@@ -124,8 +100,6 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
124
100
  "getI18nInstance",
125
101
  "getI18nWrapperI18nextInstance",
126
102
  "getI18nextInstanceForProvider",
127
- "getI18nextProvider",
128
- "getInitReactI18next",
129
103
  "isI18nInstance",
130
104
  "isI18nWrapperInstance"
131
105
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ getReactI18nextIntegration: ()=>getReactI18nextIntegration
28
+ });
29
+ function getOptionalReactI18nextPackageName() {
30
+ return "react-i18next";
31
+ }
32
+ async function tryImportReactI18next() {
33
+ try {
34
+ return await import(getOptionalReactI18nextPackageName());
35
+ } catch (error) {
36
+ return null;
37
+ }
38
+ }
39
+ async function getReactI18nextIntegration() {
40
+ const reactI18nextModule = await tryImportReactI18next();
41
+ return {
42
+ I18nextProvider: reactI18nextModule?.I18nextProvider ?? null,
43
+ initReactI18next: reactI18nextModule?.initReactI18next ?? null
44
+ };
45
+ }
46
+ exports.getReactI18nextIntegration = __webpack_exports__.getReactI18nextIntegration;
47
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
48
+ "getReactI18nextIntegration"
49
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
50
+ Object.defineProperty(exports, '__esModule', {
51
+ value: true
52
+ });
@@ -54,14 +54,19 @@ const i18nPlugin = (options)=>({
54
54
  const { enabled: backendEnabled = false } = backend || {};
55
55
  let latestI18nInstance;
56
56
  let I18nextProvider;
57
+ const loadReactI18nextIntegration = async ()=>{
58
+ if (!reactI18next) return null;
59
+ const { getReactI18nextIntegration } = await import("./i18n/react-i18next.js");
60
+ return getReactI18nextIntegration();
61
+ };
57
62
  api.onBeforeRender(async (context)=>{
58
63
  let i18nInstance = await (0, index_js_namespaceObject.getI18nInstance)(userI18nInstance);
59
64
  const { i18n: otherConfig } = api.getRuntimeConfig();
60
65
  const { initOptions: otherInitOptions } = otherConfig || {};
61
66
  const userInitOptions = (0, merge_namespaceObject.merge)(otherInitOptions || {}, initOptions || {});
62
- const initReactI18next = reactI18next ? await (0, instance_js_namespaceObject.getInitReactI18next)() : null;
63
- I18nextProvider = reactI18next ? await (0, instance_js_namespaceObject.getI18nextProvider)() : null;
64
- if (initReactI18next) i18nInstance.use(initReactI18next);
67
+ const reactI18nextIntegration = await loadReactI18nextIntegration();
68
+ I18nextProvider = reactI18nextIntegration?.I18nextProvider ?? null;
69
+ if (reactI18nextIntegration?.initReactI18next) i18nInstance.use(reactI18nextIntegration.initReactI18next);
65
70
  const pathname = (0, external_utils_js_namespaceObject.getPathname)(context);
66
71
  if (i18nextDetector) (0, detection_middleware_js_namespaceObject.useI18nextLanguageDetector)(i18nInstance);
67
72
  const mergedDetection = (0, detection_index_js_namespaceObject.mergeDetectionOptions)(i18nextDetector, detection, localePathRedirect, userInitOptions);
@@ -40,16 +40,6 @@ async function createI18nextInstance() {
40
40
  return null;
41
41
  }
42
42
  }
43
- function getOptionalReactI18nextPackageName() {
44
- return "react-i18next";
45
- }
46
- async function tryImportReactI18next() {
47
- try {
48
- return await import(getOptionalReactI18nextPackageName());
49
- } catch (error) {
50
- return null;
51
- }
52
- }
53
43
  function getI18nextInstanceForProvider(instance) {
54
44
  if (isI18nWrapperInstance(instance)) {
55
45
  const i18nextInstance = getI18nWrapperI18nextInstance(instance);
@@ -66,14 +56,4 @@ async function getI18nInstance(userInstance) {
66
56
  if (i18nextInstance) return i18nextInstance;
67
57
  throw new Error('No i18n instance found');
68
58
  }
69
- async function getInitReactI18next() {
70
- const reactI18nextModule = await tryImportReactI18next();
71
- if (reactI18nextModule) return reactI18nextModule.initReactI18next;
72
- return null;
73
- }
74
- async function getI18nextProvider() {
75
- const reactI18nextModule = await tryImportReactI18next();
76
- if (reactI18nextModule) return reactI18nextModule.I18nextProvider;
77
- return null;
78
- }
79
- export { getActualI18nextInstance, getI18nInstance, getI18nWrapperI18nextInstance, getI18nextInstanceForProvider, getI18nextProvider, getInitReactI18next, isI18nInstance, isI18nWrapperInstance };
59
+ export { getActualI18nextInstance, getI18nInstance, getI18nWrapperI18nextInstance, getI18nextInstanceForProvider, isI18nInstance, isI18nWrapperInstance };
@@ -0,0 +1,18 @@
1
+ function getOptionalReactI18nextPackageName() {
2
+ return "react-i18next";
3
+ }
4
+ async function tryImportReactI18next() {
5
+ try {
6
+ return await import(getOptionalReactI18nextPackageName());
7
+ } catch (error) {
8
+ return null;
9
+ }
10
+ }
11
+ async function getReactI18nextIntegration() {
12
+ const reactI18nextModule = await tryImportReactI18next();
13
+ return {
14
+ I18nextProvider: reactI18nextModule?.I18nextProvider ?? null,
15
+ initReactI18next: reactI18nextModule?.initReactI18next ?? null
16
+ };
17
+ }
18
+ export { getReactI18nextIntegration };
@@ -10,7 +10,7 @@ import { mergeBackendOptions } from "./i18n/backend/index.mjs";
10
10
  import { useI18nextBackend } from "./i18n/backend/middleware.mjs";
11
11
  import { detectLanguageWithPriority, exportServerLngToWindow, mergeDetectionOptions } from "./i18n/detection/index.mjs";
12
12
  import { useI18nextLanguageDetector } from "./i18n/detection/middleware.mjs";
13
- import { getI18nextInstanceForProvider, getI18nextProvider, getInitReactI18next } from "./i18n/instance.mjs";
13
+ import { getI18nextInstanceForProvider } from "./i18n/instance.mjs";
14
14
  import { changeI18nLanguage, ensureLanguageMatch, initializeI18nInstance, setupClonedInstance } from "./i18n/utils.mjs";
15
15
  import { getPathname } from "./utils.mjs";
16
16
  import "./types.mjs";
@@ -22,14 +22,19 @@ const i18nPlugin = (options)=>({
22
22
  const { enabled: backendEnabled = false } = backend || {};
23
23
  let latestI18nInstance;
24
24
  let I18nextProvider;
25
+ const loadReactI18nextIntegration = async ()=>{
26
+ if (!reactI18next) return null;
27
+ const { getReactI18nextIntegration } = await import("./i18n/react-i18next.mjs");
28
+ return getReactI18nextIntegration();
29
+ };
25
30
  api.onBeforeRender(async (context)=>{
26
31
  let i18nInstance = await getI18nInstance(userI18nInstance);
27
32
  const { i18n: otherConfig } = api.getRuntimeConfig();
28
33
  const { initOptions: otherInitOptions } = otherConfig || {};
29
34
  const userInitOptions = merge(otherInitOptions || {}, initOptions || {});
30
- const initReactI18next = reactI18next ? await getInitReactI18next() : null;
31
- I18nextProvider = reactI18next ? await getI18nextProvider() : null;
32
- if (initReactI18next) i18nInstance.use(initReactI18next);
35
+ const reactI18nextIntegration = await loadReactI18nextIntegration();
36
+ I18nextProvider = reactI18nextIntegration?.I18nextProvider ?? null;
37
+ if (reactI18nextIntegration?.initReactI18next) i18nInstance.use(reactI18nextIntegration.initReactI18next);
33
38
  const pathname = getPathname(context);
34
39
  if (i18nextDetector) useI18nextLanguageDetector(i18nInstance);
35
40
  const mergedDetection = mergeDetectionOptions(i18nextDetector, detection, localePathRedirect, userInitOptions);
@@ -41,16 +41,6 @@ async function createI18nextInstance() {
41
41
  return null;
42
42
  }
43
43
  }
44
- function getOptionalReactI18nextPackageName() {
45
- return "react-i18next";
46
- }
47
- async function tryImportReactI18next() {
48
- try {
49
- return await import(getOptionalReactI18nextPackageName());
50
- } catch (error) {
51
- return null;
52
- }
53
- }
54
44
  function getI18nextInstanceForProvider(instance) {
55
45
  if (isI18nWrapperInstance(instance)) {
56
46
  const i18nextInstance = getI18nWrapperI18nextInstance(instance);
@@ -67,14 +57,4 @@ async function getI18nInstance(userInstance) {
67
57
  if (i18nextInstance) return i18nextInstance;
68
58
  throw new Error('No i18n instance found');
69
59
  }
70
- async function getInitReactI18next() {
71
- const reactI18nextModule = await tryImportReactI18next();
72
- if (reactI18nextModule) return reactI18nextModule.initReactI18next;
73
- return null;
74
- }
75
- async function getI18nextProvider() {
76
- const reactI18nextModule = await tryImportReactI18next();
77
- if (reactI18nextModule) return reactI18nextModule.I18nextProvider;
78
- return null;
79
- }
80
- export { getActualI18nextInstance, getI18nInstance, getI18nWrapperI18nextInstance, getI18nextInstanceForProvider, getI18nextProvider, getInitReactI18next, isI18nInstance, isI18nWrapperInstance };
60
+ export { getActualI18nextInstance, getI18nInstance, getI18nWrapperI18nextInstance, getI18nextInstanceForProvider, isI18nInstance, isI18nWrapperInstance };
@@ -0,0 +1,19 @@
1
+ import "node:module";
2
+ function getOptionalReactI18nextPackageName() {
3
+ return "react-i18next";
4
+ }
5
+ async function tryImportReactI18next() {
6
+ try {
7
+ return await import(getOptionalReactI18nextPackageName());
8
+ } catch (error) {
9
+ return null;
10
+ }
11
+ }
12
+ async function getReactI18nextIntegration() {
13
+ const reactI18nextModule = await tryImportReactI18next();
14
+ return {
15
+ I18nextProvider: reactI18nextModule?.I18nextProvider ?? null,
16
+ initReactI18next: reactI18nextModule?.initReactI18next ?? null
17
+ };
18
+ }
19
+ export { getReactI18nextIntegration };
@@ -11,7 +11,7 @@ import { mergeBackendOptions } from "./i18n/backend/index.mjs";
11
11
  import { useI18nextBackend } from "./i18n/backend/middleware.mjs";
12
12
  import { detectLanguageWithPriority, exportServerLngToWindow, mergeDetectionOptions } from "./i18n/detection/index.mjs";
13
13
  import { useI18nextLanguageDetector } from "./i18n/detection/middleware.mjs";
14
- import { getI18nextInstanceForProvider, getI18nextProvider, getInitReactI18next } from "./i18n/instance.mjs";
14
+ import { getI18nextInstanceForProvider } from "./i18n/instance.mjs";
15
15
  import { changeI18nLanguage, ensureLanguageMatch, initializeI18nInstance, setupClonedInstance } from "./i18n/utils.mjs";
16
16
  import { getPathname } from "./utils.mjs";
17
17
  import "./types.mjs";
@@ -23,14 +23,19 @@ const i18nPlugin = (options)=>({
23
23
  const { enabled: backendEnabled = false } = backend || {};
24
24
  let latestI18nInstance;
25
25
  let I18nextProvider;
26
+ const loadReactI18nextIntegration = async ()=>{
27
+ if (!reactI18next) return null;
28
+ const { getReactI18nextIntegration } = await import("./i18n/react-i18next.mjs");
29
+ return getReactI18nextIntegration();
30
+ };
26
31
  api.onBeforeRender(async (context)=>{
27
32
  let i18nInstance = await getI18nInstance(userI18nInstance);
28
33
  const { i18n: otherConfig } = api.getRuntimeConfig();
29
34
  const { initOptions: otherInitOptions } = otherConfig || {};
30
35
  const userInitOptions = merge(otherInitOptions || {}, initOptions || {});
31
- const initReactI18next = reactI18next ? await getInitReactI18next() : null;
32
- I18nextProvider = reactI18next ? await getI18nextProvider() : null;
33
- if (initReactI18next) i18nInstance.use(initReactI18next);
36
+ const reactI18nextIntegration = await loadReactI18nextIntegration();
37
+ I18nextProvider = reactI18nextIntegration?.I18nextProvider ?? null;
38
+ if (reactI18nextIntegration?.initReactI18next) i18nInstance.use(reactI18nextIntegration.initReactI18next);
34
39
  const pathname = getPathname(context);
35
40
  if (i18nextDetector) useI18nextLanguageDetector(i18nInstance);
36
41
  const mergedDetection = mergeDetectionOptions(i18nextDetector, detection, localePathRedirect, userInitOptions);
@@ -1,7 +1,4 @@
1
1
  import type { BaseBackendOptions } from '../../shared/type';
2
- type ReactI18nextModule = typeof import('react-i18next');
3
- type InitReactI18next = ReactI18nextModule['initReactI18next'];
4
- type I18nextProviderComponent = ReactI18nextModule['I18nextProvider'];
5
2
  export interface I18nResourceStore {
6
3
  data?: {
7
4
  [language: string]: {
@@ -91,6 +88,4 @@ export type I18nInitOptions = {
91
88
  export declare function isI18nInstance(obj: any): obj is I18nInstance;
92
89
  export declare function getI18nextInstanceForProvider(instance: I18nInstance | any): any;
93
90
  export declare function getI18nInstance(userInstance?: I18nInstance | any): Promise<I18nInstance>;
94
- export declare function getInitReactI18next(): Promise<InitReactI18next | null>;
95
- export declare function getI18nextProvider(): Promise<I18nextProviderComponent | null>;
96
91
  export {};
@@ -0,0 +1,7 @@
1
+ import type React from 'react';
2
+ interface ReactI18nextIntegration {
3
+ I18nextProvider: React.ComponentType<any> | null;
4
+ initReactI18next: any | null;
5
+ }
6
+ export declare function getReactI18nextIntegration(): Promise<ReactI18nextIntegration>;
7
+ export {};
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "modern",
18
18
  "modern.js"
19
19
  ],
20
- "version": "3.2.0-ultramodern.30",
20
+ "version": "3.2.0-ultramodern.35",
21
21
  "engines": {
22
22
  "node": ">=20"
23
23
  },
@@ -87,15 +87,15 @@
87
87
  "i18next-fs-backend": "^2.6.6",
88
88
  "i18next-http-backend": "^4.0.0",
89
89
  "i18next-http-middleware": "^3.9.7",
90
- "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.2.0-ultramodern.30",
91
- "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.2.0-ultramodern.30",
92
- "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.2.0-ultramodern.30",
93
- "@modern-js/server-runtime": "npm:@bleedingdev/modern-js-server-runtime@3.2.0-ultramodern.30",
94
- "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.2.0-ultramodern.30",
95
- "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.2.0-ultramodern.30"
90
+ "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.2.0-ultramodern.35",
91
+ "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.2.0-ultramodern.35",
92
+ "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.2.0-ultramodern.35",
93
+ "@modern-js/server-runtime": "npm:@bleedingdev/modern-js-server-runtime@3.2.0-ultramodern.35",
94
+ "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.2.0-ultramodern.35",
95
+ "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.2.0-ultramodern.35"
96
96
  },
97
97
  "peerDependencies": {
98
- "@modern-js/runtime": "3.2.0-ultramodern.30",
98
+ "@modern-js/runtime": "3.2.0-ultramodern.35",
99
99
  "i18next": ">=25.7.4",
100
100
  "react": "^19.2.6",
101
101
  "react-dom": "^19.2.6",
@@ -120,8 +120,8 @@
120
120
  "react-dom": "^19.2.6",
121
121
  "react-i18next": "17.0.8",
122
122
  "ts-jest": "^29.4.11",
123
- "@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.2.0-ultramodern.30",
124
- "@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.2.0-ultramodern.30"
123
+ "@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.2.0-ultramodern.35",
124
+ "@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.2.0-ultramodern.35"
125
125
  },
126
126
  "sideEffects": false,
127
127
  "publishConfig": {
@@ -1,9 +1,5 @@
1
1
  import type { BaseBackendOptions } from '../../shared/type';
2
2
 
3
- type ReactI18nextModule = typeof import('react-i18next');
4
- type InitReactI18next = ReactI18nextModule['initReactI18next'];
5
- type I18nextProviderComponent = ReactI18nextModule['I18nextProvider'];
6
-
7
3
  export interface I18nResourceStore {
8
4
  data?: {
9
5
  [language: string]: {
@@ -171,20 +167,6 @@ async function createI18nextInstance(): Promise<I18nInstance | null> {
171
167
  }
172
168
  }
173
169
 
174
- function getOptionalReactI18nextPackageName(): string {
175
- return ['react', 'i18next'].join('-');
176
- }
177
-
178
- async function tryImportReactI18next(): Promise<ReactI18nextModule | null> {
179
- try {
180
- return (await import(
181
- getOptionalReactI18nextPackageName()
182
- )) as ReactI18nextModule;
183
- } catch (error) {
184
- return null;
185
- }
186
- }
187
-
188
170
  export function getI18nextInstanceForProvider(
189
171
  instance: I18nInstance | any,
190
172
  ): any {
@@ -218,19 +200,3 @@ export async function getI18nInstance(
218
200
 
219
201
  throw new Error('No i18n instance found');
220
202
  }
221
-
222
- export async function getInitReactI18next(): Promise<InitReactI18next | null> {
223
- const reactI18nextModule = await tryImportReactI18next();
224
- if (reactI18nextModule) {
225
- return reactI18nextModule.initReactI18next;
226
- }
227
- return null;
228
- }
229
-
230
- export async function getI18nextProvider(): Promise<I18nextProviderComponent | null> {
231
- const reactI18nextModule = await tryImportReactI18next();
232
- if (reactI18nextModule) {
233
- return reactI18nextModule.I18nextProvider;
234
- }
235
- return null;
236
- }
@@ -0,0 +1,31 @@
1
+ import type React from 'react';
2
+
3
+ type ReactI18nextModule = typeof import('react-i18next');
4
+
5
+ interface ReactI18nextIntegration {
6
+ I18nextProvider: React.ComponentType<any> | null;
7
+ initReactI18next: any | null;
8
+ }
9
+
10
+ function getOptionalReactI18nextPackageName(): string {
11
+ return ['react', 'i18next'].join('-');
12
+ }
13
+
14
+ async function tryImportReactI18next(): Promise<ReactI18nextModule | null> {
15
+ try {
16
+ return (await import(
17
+ getOptionalReactI18nextPackageName()
18
+ )) as ReactI18nextModule;
19
+ } catch (error) {
20
+ return null;
21
+ }
22
+ }
23
+
24
+ export async function getReactI18nextIntegration(): Promise<ReactI18nextIntegration> {
25
+ const reactI18nextModule = await tryImportReactI18next();
26
+
27
+ return {
28
+ I18nextProvider: reactI18nextModule?.I18nextProvider ?? null,
29
+ initReactI18next: reactI18nextModule?.initReactI18next ?? null,
30
+ };
31
+ }
@@ -29,11 +29,7 @@ import {
29
29
  mergeDetectionOptions,
30
30
  } from './i18n/detection';
31
31
  import { useI18nextLanguageDetector } from './i18n/detection/middleware';
32
- import {
33
- getI18nextInstanceForProvider,
34
- getI18nextProvider,
35
- getInitReactI18next,
36
- } from './i18n/instance';
32
+ import { getI18nextInstanceForProvider } from './i18n/instance';
37
33
  import {
38
34
  changeI18nLanguage,
39
35
  ensureLanguageMatch,
@@ -88,17 +84,25 @@ export const i18nPlugin = (options: I18nPluginOptions): RuntimePlugin => ({
88
84
  let latestI18nInstance: I18nInstance | undefined;
89
85
  let I18nextProvider: React.FunctionComponent<any> | null;
90
86
 
87
+ const loadReactI18nextIntegration = async () => {
88
+ if (!reactI18next) {
89
+ return null;
90
+ }
91
+ const { getReactI18nextIntegration } = await import(
92
+ './i18n/react-i18next'
93
+ );
94
+ return getReactI18nextIntegration();
95
+ };
96
+
91
97
  api.onBeforeRender(async context => {
92
98
  let i18nInstance = await getI18nInstance(userI18nInstance);
93
99
  const { i18n: otherConfig } = api.getRuntimeConfig();
94
100
  const { initOptions: otherInitOptions } = otherConfig || {};
95
101
  const userInitOptions = merge(otherInitOptions || {}, initOptions || {});
96
- const initReactI18next = reactI18next
97
- ? await getInitReactI18next()
98
- : null;
99
- I18nextProvider = reactI18next ? await getI18nextProvider() : null;
100
- if (initReactI18next) {
101
- i18nInstance.use(initReactI18next);
102
+ const reactI18nextIntegration = await loadReactI18nextIntegration();
103
+ I18nextProvider = reactI18nextIntegration?.I18nextProvider ?? null;
104
+ if (reactI18nextIntegration?.initReactI18next) {
105
+ i18nInstance.use(reactI18nextIntegration.initReactI18next);
102
106
  }
103
107
 
104
108
  const pathname = getPathname(context);
@@ -162,6 +162,40 @@ describe('localisedUrls', () => {
162
162
  ),
163
163
  ).toBe('/products/cervena-bota');
164
164
  });
165
+
166
+ test('resolves nested optional route params with translated ancestors', () => {
167
+ const localisedUrls = {
168
+ '/checkout': {
169
+ en: '/checkout',
170
+ cs: '/pokladna',
171
+ },
172
+ '/checkout/thank-you': {
173
+ en: '/checkout/thank-you',
174
+ cs: '/pokladna/dekujeme',
175
+ },
176
+ '/checkout/thank-you/:orderId?': {
177
+ en: '/checkout/thank-you/:orderId?',
178
+ cs: '/pokladna/dekujeme/:orderId?',
179
+ },
180
+ };
181
+
182
+ expect(
183
+ resolveLocalisedPath(
184
+ '/checkout/thank-you',
185
+ 'cs',
186
+ ['en', 'cs'],
187
+ localisedUrls,
188
+ ),
189
+ ).toBe('/pokladna/dekujeme');
190
+ expect(
191
+ resolveLocalisedPath(
192
+ '/pokladna/dekujeme/ABC-123',
193
+ 'en',
194
+ ['en', 'cs'],
195
+ localisedUrls,
196
+ ),
197
+ ).toBe('/checkout/thank-you/ABC-123');
198
+ });
165
199
  });
166
200
 
167
201
  describe('i18n server API prefix skips', () => {