@bleedingdev/modern-js-plugin-i18n 3.9.3-ultramodern.8 → 3.11.3-ultramodern.1

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.
@@ -38,10 +38,20 @@ const utils_js_namespaceObject = require("../shared/utils.js");
38
38
  const external_locales_js_namespaceObject = require("./locales.js");
39
39
  const external_localisedRoutes_js_namespaceObject = require("./localisedRoutes.js");
40
40
  require("../runtime/types.js");
41
+ const eagerReactI18next = (chain)=>{
42
+ chain.module.rule('plugin-i18n-react-i18next').test(/[\\/]plugin-i18n[\\/]dist[\\/][^\\/]+[\\/]runtime[\\/]i18n[\\/]react-i18next\.m?js$/).parser({
43
+ dynamicImportMode: 'eager'
44
+ });
45
+ };
41
46
  const i18nPlugin = (options = {})=>({
42
47
  name: '@modern-js/plugin-i18n',
43
48
  setup: (api)=>{
44
49
  const { localeDetection, backend, transformRuntimeConfig, customPlugin, ...restOptions } = options;
50
+ api.config(()=>({
51
+ tools: {
52
+ bundlerChain: eagerReactI18next
53
+ }
54
+ }));
45
55
  api._internalRuntimePlugins(({ entrypoint, plugins })=>{
46
56
  const localeDetectionOptions = localeDetection ? (0, utils_js_namespaceObject.getLocaleDetectionOptions)(entrypoint.entryName, localeDetection) : void 0;
47
57
  let backendOptions;
@@ -32,10 +32,10 @@ __webpack_require__.d(__webpack_exports__, {
32
32
  });
33
33
  const runtime_namespaceObject = require("@modern-js/runtime");
34
34
  const merge_namespaceObject = require("@modern-js/runtime-utils/merge");
35
- const index_js_namespaceObject = require("./i18n/index.js");
36
- const backend_index_js_namespaceObject = require("./i18n/backend/index.js");
35
+ const index_js_namespaceObject = require("./i18n/backend/index.js");
37
36
  const detection_index_js_namespaceObject = require("./i18n/detection/index.js");
38
37
  const middleware_js_namespaceObject = require("./i18n/detection/middleware.js");
38
+ const instance_js_namespaceObject = require("./i18n/instance.js");
39
39
  const external_utils_js_namespaceObject = require("./utils.js");
40
40
  let i18nLifecycleHelpersPromise;
41
41
  function loadI18nLifecycleHelpers() {
@@ -51,20 +51,24 @@ function loadI18nLifecycleHelpers() {
51
51
  }));
52
52
  return i18nLifecycleHelpersPromise;
53
53
  }
54
+ const reactI18nextInstances = new WeakSet();
54
55
  async function setupI18nBeforeRender(context, options) {
55
56
  const { api, userI18nInstance, initOptions, backend, backendEnabled, i18nextDetector, detection, localePathRedirect, languages, fallbackLanguage, resolveReactI18nextIntegration, setI18nextProvider } = options;
56
57
  const { useI18nextBackend, changeI18nLanguage, ensureLanguageMatch, initializeI18nInstance, setupClonedInstance } = await loadI18nLifecycleHelpers();
57
- let i18nInstance = await (0, index_js_namespaceObject.getI18nInstance)(userI18nInstance);
58
+ let i18nInstance = await (0, instance_js_namespaceObject.getI18nInstance)(userI18nInstance);
58
59
  const { i18n: otherConfig } = api.getRuntimeConfig();
59
60
  const { initOptions: otherInitOptions } = otherConfig || {};
60
61
  const userInitOptions = (0, merge_namespaceObject.merge)(otherInitOptions || {}, initOptions || {});
61
62
  const reactI18nextIntegration = await resolveReactI18nextIntegration();
62
63
  setI18nextProvider(reactI18nextIntegration?.I18nextProvider ?? null);
63
- if (reactI18nextIntegration?.initReactI18next) i18nInstance.use(reactI18nextIntegration.initReactI18next);
64
+ if (reactI18nextIntegration?.initReactI18next && !reactI18nextInstances.has(i18nInstance)) {
65
+ i18nInstance.use(reactI18nextIntegration.initReactI18next);
66
+ reactI18nextInstances.add(i18nInstance);
67
+ }
64
68
  const pathname = (0, external_utils_js_namespaceObject.getPathname)(context);
65
69
  if (i18nextDetector) (0, middleware_js_namespaceObject.useI18nextLanguageDetector)(i18nInstance);
66
70
  const mergedDetection = (0, detection_index_js_namespaceObject.mergeDetectionOptions)(i18nextDetector, detection, localePathRedirect, userInitOptions);
67
- const mergedBackend = (0, backend_index_js_namespaceObject.mergeBackendOptions)(backend, userInitOptions);
71
+ const mergedBackend = (0, index_js_namespaceObject.mergeBackendOptions)(backend, userInitOptions);
68
72
  const hasSdkConfig = 'function' == typeof userInitOptions?.backend?.sdk || mergedBackend?.sdk && 'function' == typeof mergedBackend.sdk;
69
73
  if (mergedBackend && (backendEnabled || hasSdkConfig)) useI18nextBackend(i18nInstance, mergedBackend);
70
74
  const { finalLanguage } = await (0, detection_index_js_namespaceObject.detectLanguageWithPriority)(i18nInstance, {
@@ -5,10 +5,20 @@ import { getBackendOptions, getLocaleDetectionOptions } from "../shared/utils.mj
5
5
  import { applyDetectedBackendPaths, detectLocalesDirectory } from "./locales.mjs";
6
6
  import { applyLocalisedRoutes } from "./localisedRoutes.mjs";
7
7
  import "../runtime/types.mjs";
8
+ const eagerReactI18next = (chain)=>{
9
+ chain.module.rule('plugin-i18n-react-i18next').test(/[\\/]plugin-i18n[\\/]dist[\\/][^\\/]+[\\/]runtime[\\/]i18n[\\/]react-i18next\.m?js$/).parser({
10
+ dynamicImportMode: 'eager'
11
+ });
12
+ };
8
13
  const i18nPlugin = (options = {})=>({
9
14
  name: '@modern-js/plugin-i18n',
10
15
  setup: (api)=>{
11
16
  const { localeDetection, backend, transformRuntimeConfig, customPlugin, ...restOptions } = options;
17
+ api.config(()=>({
18
+ tools: {
19
+ bundlerChain: eagerReactI18next
20
+ }
21
+ }));
12
22
  api._internalRuntimePlugins(({ entrypoint, plugins })=>{
13
23
  const localeDetectionOptions = localeDetection ? getLocaleDetectionOptions(entrypoint.entryName, localeDetection) : void 0;
14
24
  let backendOptions;
@@ -1,9 +1,9 @@
1
1
  import { isBrowser } from "@modern-js/runtime";
2
2
  import { merge } from "@modern-js/runtime-utils/merge";
3
- import { getI18nInstance } from "./i18n/index.mjs";
4
3
  import { mergeBackendOptions } from "./i18n/backend/index.mjs";
5
4
  import { detectLanguageWithPriority, exportServerLngToWindow, mergeDetectionOptions } from "./i18n/detection/index.mjs";
6
5
  import { useI18nextLanguageDetector } from "./i18n/detection/middleware.mjs";
6
+ import { getI18nInstance } from "./i18n/instance.mjs";
7
7
  import { getPathname } from "./utils.mjs";
8
8
  let i18nLifecycleHelpersPromise;
9
9
  function loadI18nLifecycleHelpers() {
@@ -19,6 +19,7 @@ function loadI18nLifecycleHelpers() {
19
19
  }));
20
20
  return i18nLifecycleHelpersPromise;
21
21
  }
22
+ const reactI18nextInstances = new WeakSet();
22
23
  async function setupI18nBeforeRender(context, options) {
23
24
  const { api, userI18nInstance, initOptions, backend, backendEnabled, i18nextDetector, detection, localePathRedirect, languages, fallbackLanguage, resolveReactI18nextIntegration, setI18nextProvider } = options;
24
25
  const { useI18nextBackend, changeI18nLanguage, ensureLanguageMatch, initializeI18nInstance, setupClonedInstance } = await loadI18nLifecycleHelpers();
@@ -28,7 +29,10 @@ async function setupI18nBeforeRender(context, options) {
28
29
  const userInitOptions = merge(otherInitOptions || {}, initOptions || {});
29
30
  const reactI18nextIntegration = await resolveReactI18nextIntegration();
30
31
  setI18nextProvider(reactI18nextIntegration?.I18nextProvider ?? null);
31
- if (reactI18nextIntegration?.initReactI18next) i18nInstance.use(reactI18nextIntegration.initReactI18next);
32
+ if (reactI18nextIntegration?.initReactI18next && !reactI18nextInstances.has(i18nInstance)) {
33
+ i18nInstance.use(reactI18nextIntegration.initReactI18next);
34
+ reactI18nextInstances.add(i18nInstance);
35
+ }
32
36
  const pathname = getPathname(context);
33
37
  if (i18nextDetector) useI18nextLanguageDetector(i18nInstance);
34
38
  const mergedDetection = mergeDetectionOptions(i18nextDetector, detection, localePathRedirect, userInitOptions);
@@ -6,10 +6,20 @@ import { getBackendOptions, getLocaleDetectionOptions } from "../shared/utils.mj
6
6
  import { applyDetectedBackendPaths, detectLocalesDirectory } from "./locales.mjs";
7
7
  import { applyLocalisedRoutes } from "./localisedRoutes.mjs";
8
8
  import "../runtime/types.mjs";
9
+ const eagerReactI18next = (chain)=>{
10
+ chain.module.rule('plugin-i18n-react-i18next').test(/[\\/]plugin-i18n[\\/]dist[\\/][^\\/]+[\\/]runtime[\\/]i18n[\\/]react-i18next\.m?js$/).parser({
11
+ dynamicImportMode: 'eager'
12
+ });
13
+ };
9
14
  const i18nPlugin = (options = {})=>({
10
15
  name: '@modern-js/plugin-i18n',
11
16
  setup: (api)=>{
12
17
  const { localeDetection, backend, transformRuntimeConfig, customPlugin, ...restOptions } = options;
18
+ api.config(()=>({
19
+ tools: {
20
+ bundlerChain: eagerReactI18next
21
+ }
22
+ }));
13
23
  api._internalRuntimePlugins(({ entrypoint, plugins })=>{
14
24
  const localeDetectionOptions = localeDetection ? getLocaleDetectionOptions(entrypoint.entryName, localeDetection) : void 0;
15
25
  let backendOptions;
@@ -1,10 +1,10 @@
1
1
  import "node:module";
2
2
  import { isBrowser } from "@modern-js/runtime";
3
3
  import { merge } from "@modern-js/runtime-utils/merge";
4
- import { getI18nInstance } from "./i18n/index.mjs";
5
4
  import { mergeBackendOptions } from "./i18n/backend/index.mjs";
6
5
  import { detectLanguageWithPriority, exportServerLngToWindow, mergeDetectionOptions } from "./i18n/detection/index.mjs";
7
6
  import { useI18nextLanguageDetector } from "./i18n/detection/middleware.mjs";
7
+ import { getI18nInstance } from "./i18n/instance.mjs";
8
8
  import { getPathname } from "./utils.mjs";
9
9
  let i18nLifecycleHelpersPromise;
10
10
  function loadI18nLifecycleHelpers() {
@@ -20,6 +20,7 @@ function loadI18nLifecycleHelpers() {
20
20
  }));
21
21
  return i18nLifecycleHelpersPromise;
22
22
  }
23
+ const reactI18nextInstances = new WeakSet();
23
24
  async function setupI18nBeforeRender(context, options) {
24
25
  const { api, userI18nInstance, initOptions, backend, backendEnabled, i18nextDetector, detection, localePathRedirect, languages, fallbackLanguage, resolveReactI18nextIntegration, setI18nextProvider } = options;
25
26
  const { useI18nextBackend, changeI18nLanguage, ensureLanguageMatch, initializeI18nInstance, setupClonedInstance } = await loadI18nLifecycleHelpers();
@@ -29,7 +30,10 @@ async function setupI18nBeforeRender(context, options) {
29
30
  const userInitOptions = merge(otherInitOptions || {}, initOptions || {});
30
31
  const reactI18nextIntegration = await resolveReactI18nextIntegration();
31
32
  setI18nextProvider(reactI18nextIntegration?.I18nextProvider ?? null);
32
- if (reactI18nextIntegration?.initReactI18next) i18nInstance.use(reactI18nextIntegration.initReactI18next);
33
+ if (reactI18nextIntegration?.initReactI18next && !reactI18nextInstances.has(i18nInstance)) {
34
+ i18nInstance.use(reactI18nextIntegration.initReactI18next);
35
+ reactI18nextInstances.add(i18nInstance);
36
+ }
33
37
  const pathname = getPathname(context);
34
38
  if (i18nextDetector) useI18nextLanguageDetector(i18nInstance);
35
39
  const mergedDetection = mergeDetectionOptions(i18nextDetector, detection, localePathRedirect, userInitOptions);
@@ -7,4 +7,7 @@ import { type I18nRouterAdapter } from './routerAdapter.js';
7
7
  * factory takes this package's own primitives as arguments, so the fork
8
8
  * package never imports back into it and the dependency stays one-way.
9
9
  */
10
- export declare const I18nRouterNavigationProvider: ({ children, }: React.PropsWithChildren) => React.JSX.Element, useIntegratedRouterAdapter: () => I18nRouterAdapter;
10
+ export declare const { I18nRouterNavigationProvider, useIntegratedRouterAdapter }: {
11
+ useIntegratedRouterAdapter: () => I18nRouterAdapter;
12
+ I18nRouterNavigationProvider: ({ children }: React.PropsWithChildren) => React.JSX.Element;
13
+ };
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "modern",
18
18
  "modern.js"
19
19
  ],
20
- "version": "3.9.3-ultramodern.8",
20
+ "version": "3.11.3-ultramodern.1",
21
21
  "engines": {
22
22
  "node": ">=20"
23
23
  },
@@ -132,22 +132,22 @@
132
132
  }
133
133
  },
134
134
  "dependencies": {
135
- "@modern-js/i18n-runtime-extensions": "npm:@bleedingdev/modern-js-i18n-runtime-extensions@3.9.3-ultramodern.8",
136
- "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.9.3-ultramodern.8",
137
- "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.9.3-ultramodern.8",
138
- "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.9.3-ultramodern.8",
139
- "@modern-js/server-runtime": "npm:@bleedingdev/modern-js-server-runtime@3.9.3-ultramodern.8",
140
- "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.9.3-ultramodern.8",
141
- "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.9.3-ultramodern.8",
135
+ "@modern-js/i18n-runtime-extensions": "npm:@bleedingdev/modern-js-i18n-runtime-extensions@3.11.3-ultramodern.1",
136
+ "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.11.3-ultramodern.1",
137
+ "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.11.3-ultramodern.1",
138
+ "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.11.3-ultramodern.1",
139
+ "@modern-js/server-runtime": "npm:@bleedingdev/modern-js-server-runtime@3.11.3-ultramodern.1",
140
+ "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.11.3-ultramodern.1",
141
+ "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.11.3-ultramodern.1",
142
142
  "@swc/helpers": "^0.5.23",
143
- "i18next-browser-languagedetector": "^8.2.1",
143
+ "i18next-browser-languagedetector": "^8.3.0",
144
144
  "i18next-chained-backend": "^5.0.6",
145
145
  "i18next-fs-backend": "^2.6.9",
146
- "i18next-http-backend": "^4.0.3",
147
- "i18next-http-middleware": "^3.9.9"
146
+ "i18next-http-backend": "^4.0.9",
147
+ "i18next-http-middleware": "^3.10.0"
148
148
  },
149
149
  "peerDependencies": {
150
- "@modern-js/runtime": "3.9.3-ultramodern.8",
150
+ "@modern-js/runtime": "3.11.3-ultramodern.1",
151
151
  "i18next": ">=25.10.10",
152
152
  "react": "^19.3.1",
153
153
  "react-dom": "^19.3.1",
@@ -162,11 +162,11 @@
162
162
  }
163
163
  },
164
164
  "devDependencies": {
165
- "@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.9.3-ultramodern.8",
166
- "@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.9.3-ultramodern.8",
167
- "@modern-js/runtime-extensions": "npm:@bleedingdev/modern-js-runtime-extensions@3.9.3-ultramodern.8",
165
+ "@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.11.3-ultramodern.1",
166
+ "@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.11.3-ultramodern.1",
167
+ "@modern-js/runtime-extensions": "npm:@bleedingdev/modern-js-runtime-extensions@3.11.3-ultramodern.1",
168
168
  "@rslib/core": "1.0.3",
169
- "@scripts/rstest-config": "2.66.0",
169
+ "@scripts/rstest-config": "2.66.7",
170
170
  "@types/node": "^26.6.5",
171
171
  "esbuild": "^0.28.2",
172
172
  "i18next": "26.4.6",
package/src/cli/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
- import type { AppTools, CliPlugin } from '@modern-js/app-tools';
3
+ import type { AppTools, AppUserConfig, CliPlugin } from '@modern-js/app-tools';
4
4
  import { getPublicDirRoutePrefixes } from '@modern-js/server-core';
5
5
  import type { Entrypoint } from '@modern-js/types';
6
6
  import { logger } from '@modern-js/utils';
@@ -11,6 +11,22 @@ import { applyDetectedBackendPaths, detectLocalesDirectory } from './locales';
11
11
  import { applyLocalisedRoutes } from './localisedRoutes';
12
12
  import '../runtime/types';
13
13
 
14
+ type BundlerChain = NonNullable<AppUserConfig['tools']>['bundlerChain'];
15
+
16
+ // Before the first render the runtime loads react-i18next with a dynamic import.
17
+ // Bundle that module eagerly so it doesn't become an extra async request. Only
18
+ // runtime/i18n/react-i18next is matched: the i18next fallback import in
19
+ // runtime/i18n/instance stays lazy, so apps that pass their own instance don't
20
+ // get an unused copy of i18next in the initial chunk.
21
+ const eagerReactI18next: BundlerChain = chain => {
22
+ chain.module
23
+ .rule('plugin-i18n-react-i18next')
24
+ .test(
25
+ /[\\/]plugin-i18n[\\/]dist[\\/][^\\/]+[\\/]runtime[\\/]i18n[\\/]react-i18next\.m?js$/,
26
+ )
27
+ .parser({ dynamicImportMode: 'eager' });
28
+ };
29
+
14
30
  export type TransformRuntimeConfigFn = (
15
31
  extendedConfig: Record<string, any>,
16
32
  entrypoint: Entrypoint,
@@ -45,6 +61,8 @@ export const i18nPlugin = (
45
61
  ...restOptions
46
62
  } = options;
47
63
 
64
+ api.config(() => ({ tools: { bundlerChain: eagerReactI18next } }));
65
+
48
66
  api._internalRuntimePlugins(({ entrypoint, plugins }) => {
49
67
  const localeDetectionOptions = localeDetection
50
68
  ? getLocaleDetectionOptions(entrypoint.entryName, localeDetection)
@@ -6,7 +6,6 @@ import type {
6
6
  BaseLocaleDetectionOptions,
7
7
  } from '../shared/type';
8
8
  import type { I18nInitOptions, I18nInstance } from './i18n';
9
- import { getI18nInstance } from './i18n';
10
9
  import { mergeBackendOptions } from './i18n/backend';
11
10
  import {
12
11
  detectLanguageWithPriority,
@@ -14,6 +13,7 @@ import {
14
13
  mergeDetectionOptions,
15
14
  } from './i18n/detection';
16
15
  import { useI18nextLanguageDetector } from './i18n/detection/middleware';
16
+ import { getI18nInstance } from './i18n/instance';
17
17
  import type { ReactI18nextIntegration } from './reactI18next';
18
18
  import { getPathname } from './utils';
19
19
 
@@ -74,6 +74,8 @@ interface SetupI18nBeforeRenderOptions {
74
74
  ) => void;
75
75
  }
76
76
 
77
+ const reactI18nextInstances = new WeakSet<object>();
78
+
77
79
  export async function setupI18nBeforeRender(
78
80
  context: RuntimeContextWithI18n,
79
81
  options: SetupI18nBeforeRenderOptions,
@@ -106,8 +108,12 @@ export async function setupI18nBeforeRender(
106
108
 
107
109
  const reactI18nextIntegration = await resolveReactI18nextIntegration();
108
110
  setI18nextProvider(reactI18nextIntegration?.I18nextProvider ?? null);
109
- if (reactI18nextIntegration?.initReactI18next) {
111
+ if (
112
+ reactI18nextIntegration?.initReactI18next &&
113
+ !reactI18nextInstances.has(i18nInstance)
114
+ ) {
110
115
  i18nInstance.use(reactI18nextIntegration.initReactI18next);
116
+ reactI18nextInstances.add(i18nInstance);
111
117
  }
112
118
 
113
119
  const pathname = getPathname(context);