@bleedingdev/modern-js-plugin-i18n 3.5.0-ultramodern.32 → 3.5.0-ultramodern.33

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.
@@ -77,7 +77,21 @@ const createI18nRootWrapper = (options)=>(App)=>(props)=>{
77
77
  forceUpdate
78
78
  ]);
79
79
  const children = props.children;
80
- const appContent = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
80
+ let appContent = App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
81
+ ...props,
82
+ children: children
83
+ }) : children;
84
+ if (i18nInstance) {
85
+ const I18nextProvider = getI18nextProvider();
86
+ if (I18nextProvider) {
87
+ const i18nextInstanceForProvider = (0, instance_js_namespaceObject.getI18nextInstanceForProvider)(i18nInstance);
88
+ appContent = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(I18nextProvider, {
89
+ i18n: i18nextInstanceForProvider,
90
+ children: appContent
91
+ });
92
+ }
93
+ }
94
+ return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
81
95
  children: [
82
96
  Boolean(htmlLangAttr) && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(head_namespaceObject.Helmet, {
83
97
  htmlAttributes: {
@@ -86,23 +100,10 @@ const createI18nRootWrapper = (options)=>(App)=>(props)=>{
86
100
  }),
87
101
  /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_context_js_namespaceObject.ModernI18nProvider, {
88
102
  value: contextValue,
89
- children: App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
90
- ...props,
91
- children: children
92
- }) : children
103
+ children: appContent
93
104
  })
94
105
  ]
95
106
  });
96
- if (!i18nInstance) return appContent;
97
- const I18nextProvider = getI18nextProvider();
98
- if (I18nextProvider) {
99
- const i18nextInstanceForProvider = (0, instance_js_namespaceObject.getI18nextInstanceForProvider)(i18nInstance);
100
- return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(I18nextProvider, {
101
- i18n: i18nextInstanceForProvider,
102
- children: appContent
103
- });
104
- }
105
- return appContent;
106
107
  };
107
108
  exports.createI18nRootWrapper = __webpack_exports__.createI18nRootWrapper;
108
109
  for(var __rspack_i in __webpack_exports__)if (-1 === [
@@ -45,7 +45,21 @@ const createI18nRootWrapper = (options)=>(App)=>(props)=>{
45
45
  forceUpdate
46
46
  ]);
47
47
  const children = props.children;
48
- const appContent = /*#__PURE__*/ jsxs(Fragment, {
48
+ let appContent = App ? /*#__PURE__*/ jsx(App, {
49
+ ...props,
50
+ children: children
51
+ }) : children;
52
+ if (i18nInstance) {
53
+ const I18nextProvider = getI18nextProvider();
54
+ if (I18nextProvider) {
55
+ const i18nextInstanceForProvider = getI18nextInstanceForProvider(i18nInstance);
56
+ appContent = /*#__PURE__*/ jsx(I18nextProvider, {
57
+ i18n: i18nextInstanceForProvider,
58
+ children: appContent
59
+ });
60
+ }
61
+ }
62
+ return /*#__PURE__*/ jsxs(Fragment, {
49
63
  children: [
50
64
  Boolean(htmlLangAttr) && /*#__PURE__*/ jsx(Helmet, {
51
65
  htmlAttributes: {
@@ -54,22 +68,9 @@ const createI18nRootWrapper = (options)=>(App)=>(props)=>{
54
68
  }),
55
69
  /*#__PURE__*/ jsx(ModernI18nProvider, {
56
70
  value: contextValue,
57
- children: App ? /*#__PURE__*/ jsx(App, {
58
- ...props,
59
- children: children
60
- }) : children
71
+ children: appContent
61
72
  })
62
73
  ]
63
74
  });
64
- if (!i18nInstance) return appContent;
65
- const I18nextProvider = getI18nextProvider();
66
- if (I18nextProvider) {
67
- const i18nextInstanceForProvider = getI18nextInstanceForProvider(i18nInstance);
68
- return /*#__PURE__*/ jsx(I18nextProvider, {
69
- i18n: i18nextInstanceForProvider,
70
- children: appContent
71
- });
72
- }
73
- return appContent;
74
75
  };
75
76
  export { createI18nRootWrapper };
@@ -46,7 +46,21 @@ const createI18nRootWrapper = (options)=>(App)=>(props)=>{
46
46
  forceUpdate
47
47
  ]);
48
48
  const children = props.children;
49
- const appContent = /*#__PURE__*/ jsxs(Fragment, {
49
+ let appContent = App ? /*#__PURE__*/ jsx(App, {
50
+ ...props,
51
+ children: children
52
+ }) : children;
53
+ if (i18nInstance) {
54
+ const I18nextProvider = getI18nextProvider();
55
+ if (I18nextProvider) {
56
+ const i18nextInstanceForProvider = getI18nextInstanceForProvider(i18nInstance);
57
+ appContent = /*#__PURE__*/ jsx(I18nextProvider, {
58
+ i18n: i18nextInstanceForProvider,
59
+ children: appContent
60
+ });
61
+ }
62
+ }
63
+ return /*#__PURE__*/ jsxs(Fragment, {
50
64
  children: [
51
65
  Boolean(htmlLangAttr) && /*#__PURE__*/ jsx(Helmet, {
52
66
  htmlAttributes: {
@@ -55,22 +69,9 @@ const createI18nRootWrapper = (options)=>(App)=>(props)=>{
55
69
  }),
56
70
  /*#__PURE__*/ jsx(ModernI18nProvider, {
57
71
  value: contextValue,
58
- children: App ? /*#__PURE__*/ jsx(App, {
59
- ...props,
60
- children: children
61
- }) : children
72
+ children: appContent
62
73
  })
63
74
  ]
64
75
  });
65
- if (!i18nInstance) return appContent;
66
- const I18nextProvider = getI18nextProvider();
67
- if (I18nextProvider) {
68
- const i18nextInstanceForProvider = getI18nextInstanceForProvider(i18nInstance);
69
- return /*#__PURE__*/ jsx(I18nextProvider, {
70
- i18n: i18nextInstanceForProvider,
71
- children: appContent
72
- });
73
- }
74
- return appContent;
75
76
  };
76
77
  export { createI18nRootWrapper };
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "modern",
18
18
  "modern.js"
19
19
  ],
20
- "version": "3.5.0-ultramodern.32",
20
+ "version": "3.5.0-ultramodern.33",
21
21
  "engines": {
22
22
  "node": ">=20"
23
23
  },
@@ -97,15 +97,15 @@
97
97
  "i18next-fs-backend": "^2.6.6",
98
98
  "i18next-http-backend": "^4.0.0",
99
99
  "i18next-http-middleware": "^3.9.7",
100
- "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.5.0-ultramodern.32",
101
- "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.5.0-ultramodern.32",
102
- "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.5.0-ultramodern.32",
103
- "@modern-js/server-runtime": "npm:@bleedingdev/modern-js-server-runtime@3.5.0-ultramodern.32",
104
- "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.5.0-ultramodern.32",
105
- "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.5.0-ultramodern.32"
100
+ "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.5.0-ultramodern.33",
101
+ "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.5.0-ultramodern.33",
102
+ "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.5.0-ultramodern.33",
103
+ "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.5.0-ultramodern.33",
104
+ "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.5.0-ultramodern.33",
105
+ "@modern-js/server-runtime": "npm:@bleedingdev/modern-js-server-runtime@3.5.0-ultramodern.33"
106
106
  },
107
107
  "peerDependencies": {
108
- "@modern-js/runtime": "3.5.0-ultramodern.32",
108
+ "@modern-js/runtime": "3.5.0-ultramodern.33",
109
109
  "i18next": ">=26.3.1",
110
110
  "react": "^19.2.7",
111
111
  "react-dom": "^19.2.7",
@@ -129,8 +129,8 @@
129
129
  "react-i18next": "17.0.8",
130
130
  "ts-node": "^10.9.2",
131
131
  "typescript": "^6.0.3",
132
- "@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.5.0-ultramodern.32",
133
- "@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.5.0-ultramodern.32"
132
+ "@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.5.0-ultramodern.33",
133
+ "@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.5.0-ultramodern.33"
134
134
  },
135
135
  "sideEffects": false,
136
136
  "publishConfig": {
@@ -113,30 +113,32 @@ export const createI18nRootWrapper =
113
113
  );
114
114
 
115
115
  const children = (props as React.PropsWithChildren).children;
116
- const appContent = (
116
+ let appContent: React.ReactNode = App ? (
117
+ <App {...props}>{children}</App>
118
+ ) : (
119
+ children
120
+ );
121
+
122
+ if (i18nInstance) {
123
+ const I18nextProvider = getI18nextProvider();
124
+ if (I18nextProvider) {
125
+ const i18nextInstanceForProvider =
126
+ getI18nextInstanceForProvider(i18nInstance);
127
+ appContent = (
128
+ <I18nextProvider i18n={i18nextInstanceForProvider}>
129
+ {appContent}
130
+ </I18nextProvider>
131
+ );
132
+ }
133
+ }
134
+
135
+ return (
117
136
  <>
118
137
  {Boolean(htmlLangAttr) && <Helmet htmlAttributes={{ lang }} />}
119
138
  <ModernI18nProvider value={contextValue}>
120
- {App ? <App {...props}>{children}</App> : children}
139
+ {appContent}
121
140
  </ModernI18nProvider>
122
141
  </>
123
142
  );
124
-
125
- if (!i18nInstance) {
126
- return appContent;
127
- }
128
-
129
- const I18nextProvider = getI18nextProvider();
130
- if (I18nextProvider) {
131
- const i18nextInstanceForProvider =
132
- getI18nextInstanceForProvider(i18nInstance);
133
- return (
134
- <I18nextProvider i18n={i18nextInstanceForProvider}>
135
- {appContent}
136
- </I18nextProvider>
137
- );
138
- }
139
-
140
- return appContent;
141
143
  };
142
144
  };
@@ -12,6 +12,7 @@ import { ModernI18nProvider, useModernI18n } from '../src/runtime/context';
12
12
  import { I18nLink } from '../src/runtime/I18nLink';
13
13
  import type { I18nInstance } from '../src/runtime/i18n';
14
14
  import { getReactI18nextIntegration } from '../src/runtime/i18n/react-i18next';
15
+ import { createI18nRootWrapper } from '../src/runtime/providerComposition';
15
16
 
16
17
  (
17
18
  globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }
@@ -228,6 +229,34 @@ describe('i18n runtime wrapRoot', () => {
228
229
  ).toBe('root');
229
230
  expect(rendered.container.textContent).toContain('router content');
230
231
  });
232
+
233
+ test('keeps the optional i18next provider inside Modern i18n context', async () => {
234
+ const i18nInstance = createI18nInstance('cs');
235
+ const observedLanguages: string[] = [];
236
+ const I18nextProvider = ({
237
+ children,
238
+ i18n,
239
+ }: PropsWithChildren<{ i18n: I18nInstance }>) => {
240
+ const { language } = useModernI18n();
241
+ observedLanguages.push(`${language}:${i18n.language}`);
242
+
243
+ return <section data-testid="i18next-provider">{children}</section>;
244
+ };
245
+ const App = () => <main>router content</main>;
246
+ const I18nRoot = createI18nRootWrapper({
247
+ htmlLangAttr: false,
248
+ localePathRedirect: false,
249
+ languages: ['en', 'cs'],
250
+ fallbackLanguage: 'en',
251
+ getLatestI18nInstance: () => i18nInstance,
252
+ getI18nextProvider: () => I18nextProvider,
253
+ })(App);
254
+
255
+ rendered = await renderI18nRoot(<I18nRoot />);
256
+
257
+ expect(observedLanguages).toEqual(['cs:cs']);
258
+ expect(rendered.container.textContent).toContain('router content');
259
+ });
231
260
  });
232
261
 
233
262
  describe('i18n react-i18next integration', () => {