@bleedingdev/modern-js-plugin-i18n 3.2.0-ultramodern.5 → 3.2.0-ultramodern.50

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.
Files changed (90) hide show
  1. package/dist/cjs/cli/index.js +22 -0
  2. package/dist/cjs/runtime/I18nLink.js +4 -12
  3. package/dist/cjs/runtime/context.js +32 -5
  4. package/dist/cjs/runtime/hooks.js +8 -5
  5. package/dist/cjs/runtime/i18n/backend/defaults.js +1 -1
  6. package/dist/cjs/runtime/i18n/backend/middleware.node.js +4 -4
  7. package/dist/cjs/runtime/i18n/instance.js +0 -24
  8. package/dist/cjs/runtime/i18n/react-i18next.js +52 -0
  9. package/dist/cjs/runtime/index.js +13 -7
  10. package/dist/cjs/runtime/routerAdapter.js +163 -0
  11. package/dist/cjs/runtime/utils.js +63 -94
  12. package/dist/cjs/server/index.js +60 -8
  13. package/dist/cjs/shared/localisedUrls.js +237 -0
  14. package/dist/esm/cli/index.mjs +22 -0
  15. package/dist/esm/runtime/I18nLink.mjs +4 -12
  16. package/dist/esm/runtime/context.mjs +34 -7
  17. package/dist/esm/runtime/hooks.mjs +9 -6
  18. package/dist/esm/runtime/i18n/backend/defaults.mjs +1 -1
  19. package/dist/esm/runtime/i18n/backend/middleware.node.mjs +3 -3
  20. package/dist/esm/runtime/i18n/instance.mjs +1 -19
  21. package/dist/esm/runtime/i18n/react-i18next.mjs +18 -0
  22. package/dist/esm/runtime/index.mjs +14 -8
  23. package/dist/esm/runtime/routerAdapter.mjs +129 -0
  24. package/dist/esm/runtime/utils.mjs +11 -30
  25. package/dist/esm/server/index.mjs +53 -7
  26. package/dist/esm/shared/localisedUrls.mjs +191 -0
  27. package/dist/esm-node/cli/index.mjs +22 -0
  28. package/dist/esm-node/runtime/I18nLink.mjs +4 -12
  29. package/dist/esm-node/runtime/context.mjs +34 -7
  30. package/dist/esm-node/runtime/hooks.mjs +9 -6
  31. package/dist/esm-node/runtime/i18n/backend/defaults.mjs +1 -1
  32. package/dist/esm-node/runtime/i18n/backend/middleware.node.mjs +3 -3
  33. package/dist/esm-node/runtime/i18n/instance.mjs +1 -19
  34. package/dist/esm-node/runtime/i18n/react-i18next.mjs +19 -0
  35. package/dist/esm-node/runtime/index.mjs +14 -8
  36. package/dist/esm-node/runtime/routerAdapter.mjs +130 -0
  37. package/dist/esm-node/runtime/utils.mjs +11 -30
  38. package/dist/esm-node/server/index.mjs +53 -7
  39. package/dist/esm-node/shared/localisedUrls.mjs +192 -0
  40. package/dist/types/cli/index.d.ts +21 -0
  41. package/dist/types/runtime/I18nLink.d.ts +23 -0
  42. package/dist/types/runtime/context.d.ts +41 -0
  43. package/dist/types/runtime/hooks.d.ts +30 -0
  44. package/dist/types/runtime/i18n/backend/config.d.ts +2 -0
  45. package/dist/types/runtime/i18n/backend/defaults.d.ts +13 -0
  46. package/dist/types/runtime/i18n/backend/defaults.node.d.ts +8 -0
  47. package/dist/types/runtime/i18n/backend/index.d.ts +3 -0
  48. package/dist/types/runtime/i18n/backend/middleware.common.d.ts +14 -0
  49. package/dist/types/runtime/i18n/backend/middleware.d.ts +12 -0
  50. package/dist/types/runtime/i18n/backend/middleware.node.d.ts +13 -0
  51. package/dist/types/runtime/i18n/backend/sdk-backend.d.ts +53 -0
  52. package/dist/types/runtime/i18n/backend/sdk-event.d.ts +9 -0
  53. package/dist/types/runtime/i18n/detection/config.d.ts +11 -0
  54. package/dist/types/runtime/i18n/detection/index.d.ts +50 -0
  55. package/dist/types/runtime/i18n/detection/middleware.d.ts +24 -0
  56. package/dist/types/runtime/i18n/detection/middleware.node.d.ts +17 -0
  57. package/dist/types/runtime/i18n/index.d.ts +3 -0
  58. package/dist/types/runtime/i18n/instance.d.ts +91 -0
  59. package/dist/types/runtime/i18n/react-i18next.d.ts +7 -0
  60. package/dist/types/runtime/i18n/utils.d.ts +29 -0
  61. package/dist/types/runtime/index.d.ts +21 -0
  62. package/dist/types/runtime/routerAdapter.d.ts +26 -0
  63. package/dist/types/runtime/types.d.ts +15 -0
  64. package/dist/types/runtime/utils.d.ts +28 -0
  65. package/dist/types/server/index.d.ts +14 -0
  66. package/dist/types/shared/deepMerge.d.ts +1 -0
  67. package/dist/types/shared/detection.d.ts +11 -0
  68. package/dist/types/shared/localisedUrls.d.ts +13 -0
  69. package/dist/types/shared/type.d.ts +168 -0
  70. package/dist/types/shared/utils.d.ts +5 -0
  71. package/package.json +15 -15
  72. package/rstest.config.mts +39 -0
  73. package/src/cli/index.ts +43 -1
  74. package/src/runtime/I18nLink.tsx +10 -16
  75. package/src/runtime/context.tsx +45 -7
  76. package/src/runtime/hooks.ts +13 -4
  77. package/src/runtime/i18n/backend/defaults.ts +3 -1
  78. package/src/runtime/i18n/backend/middleware.node.ts +1 -1
  79. package/src/runtime/i18n/instance.ts +0 -25
  80. package/src/runtime/i18n/react-i18next.ts +31 -0
  81. package/src/runtime/index.tsx +21 -9
  82. package/src/runtime/routerAdapter.tsx +333 -0
  83. package/src/runtime/utils.ts +22 -34
  84. package/src/server/index.ts +117 -10
  85. package/src/shared/localisedUrls.ts +393 -0
  86. package/src/shared/type.ts +12 -0
  87. package/tests/localisedUrls.test.ts +312 -0
  88. package/tests/routerAdapter.test.tsx +278 -0
  89. package/dist/esm/rslib-runtime.mjs +0 -18
  90. package/dist/esm-node/rslib-runtime.mjs +0 -19
package/src/cli/index.ts CHANGED
@@ -1,8 +1,16 @@
1
1
  import type { AppTools, CliPlugin } from '@modern-js/app-tools';
2
2
  import { getPublicDirRoutePrefixes } from '@modern-js/server-core';
3
- import type { Entrypoint } from '@modern-js/types';
3
+ import type {
4
+ Entrypoint,
5
+ NestedRouteForCli,
6
+ PageRoute,
7
+ } from '@modern-js/types';
4
8
  import fs from 'fs';
5
9
  import path from 'path';
10
+ import {
11
+ applyLocalisedUrlsToRoutes,
12
+ resolveLocalisedUrlsConfig,
13
+ } from '../shared/localisedUrls';
6
14
  import type { BackendOptions, LocaleDetectionOptions } from '../shared/type';
7
15
  import { getBackendOptions, getLocaleDetectionOptions } from '../shared/utils';
8
16
 
@@ -203,6 +211,40 @@ export const i18nPlugin = (
203
211
  };
204
212
  });
205
213
 
214
+ api.modifyFileSystemRoutes(({ entrypoint, routes }) => {
215
+ if (!localeDetection) {
216
+ return { entrypoint, routes };
217
+ }
218
+
219
+ const localeDetectionOptions = getLocaleDetectionOptions(
220
+ entrypoint.entryName,
221
+ localeDetection,
222
+ );
223
+ const {
224
+ localePathRedirect,
225
+ languages = [],
226
+ localisedUrls,
227
+ } = localeDetectionOptions;
228
+
229
+ if (!localePathRedirect || languages.length === 0) {
230
+ return { entrypoint, routes };
231
+ }
232
+
233
+ const localisedUrlsConfig = resolveLocalisedUrlsConfig(localisedUrls);
234
+ if (!localisedUrlsConfig.enabled) {
235
+ return { entrypoint, routes };
236
+ }
237
+
238
+ return {
239
+ entrypoint,
240
+ routes: applyLocalisedUrlsToRoutes(
241
+ routes as (NestedRouteForCli | PageRoute)[],
242
+ languages,
243
+ localisedUrlsConfig.map,
244
+ ),
245
+ };
246
+ });
247
+
206
248
  api._internalServerPlugins(({ plugins }) => {
207
249
  const { serverRoutes, metaName } = api.getAppContext();
208
250
  const normalizedConfig = api.getNormalizedConfig();
@@ -1,12 +1,12 @@
1
- import { Link, useInRouterContext, useParams } from '@modern-js/runtime/router';
2
1
  import type React from 'react';
3
2
  import { useModernI18n } from './context';
3
+ import { useI18nRouterAdapter } from './routerAdapter';
4
4
  import { buildLocalizedUrl } from './utils';
5
5
 
6
6
  export interface I18nLinkProps {
7
7
  to: string;
8
8
  children: React.ReactNode;
9
- [key: string]: any; // Allow other props to be passed through
9
+ [key: string]: any;
10
10
  }
11
11
 
12
12
  /**
@@ -24,30 +24,25 @@ export interface I18nLinkProps {
24
24
  * <I18nLink to="/">Home</I18nLink>
25
25
  * ```
26
26
  */
27
- // Use static imports to avoid breaking router tree-shaking. Detect router context via useInRouterContext.
28
- const useRouterHooks = () => {
29
- const inRouter = useInRouterContext();
30
- return {
31
- Link: inRouter ? Link : null,
32
- params: inRouter ? useParams() : ({} as any),
33
- hasRouter: inRouter,
34
- };
35
- };
36
-
37
27
  export const I18nLink: React.FC<I18nLinkProps> = ({
38
28
  to,
39
29
  children,
40
30
  ...props
41
31
  }) => {
42
- const { Link, params, hasRouter } = useRouterHooks();
43
- const { language, supportedLanguages } = useModernI18n();
32
+ const { Link, params, hasRouter } = useI18nRouterAdapter();
33
+ const { language, supportedLanguages, localisedUrls } = useModernI18n();
44
34
 
45
35
  // Get the current language from context (which reflects the actual current language)
46
36
  // URL params might be stale after language changes, so we prioritize the context language
47
37
  const currentLang = language;
48
38
 
49
39
  // Build the localized URL by adding language prefix
50
- const localizedTo = buildLocalizedUrl(to, currentLang, supportedLanguages);
40
+ const localizedTo = buildLocalizedUrl(
41
+ to,
42
+ currentLang,
43
+ supportedLanguages,
44
+ localisedUrls,
45
+ );
51
46
 
52
47
  // In development mode, warn if used outside of :lang route context
53
48
  if (process.env.NODE_ENV === 'development' && hasRouter && !params.lang) {
@@ -57,7 +52,6 @@ export const I18nLink: React.FC<I18nLinkProps> = ({
57
52
  );
58
53
  }
59
54
 
60
- // If router is not available, render as a regular anchor tag
61
55
  if (!hasRouter || !Link) {
62
56
  return (
63
57
  <a href={localizedTo} {...props}>
@@ -1,15 +1,22 @@
1
1
  import { isBrowser } from '@modern-js/runtime';
2
2
  import type { FC, ReactNode } from 'react';
3
- import { createContext, useCallback, useContext, useMemo } from 'react';
3
+ import {
4
+ createContext,
5
+ useCallback,
6
+ useContext,
7
+ useEffect,
8
+ useMemo,
9
+ } from 'react';
10
+ import type { LocalisedUrlsOption } from '../shared/localisedUrls';
4
11
  import type { I18nInstance } from './i18n';
5
12
  import type { SdkBackend } from './i18n/backend/sdk-backend';
6
13
  import { cacheUserLanguage } from './i18n/detection';
14
+ import { useI18nRouterAdapter } from './routerAdapter';
7
15
  import {
8
16
  buildLocalizedUrl,
9
17
  detectLanguageFromPath,
10
18
  getEntryPath,
11
19
  shouldIgnoreRedirect,
12
- useRouterHooks,
13
20
  } from './utils';
14
21
 
15
22
  export interface ModernI18nContextValue {
@@ -20,6 +27,7 @@ export interface ModernI18nContextValue {
20
27
  languages?: string[];
21
28
  localePathRedirect?: boolean;
22
29
  ignoreRedirectRoutes?: string[] | ((pathname: string) => boolean);
30
+ localisedUrls?: LocalisedUrlsOption;
23
31
  // Callback to update language in context
24
32
  updateLanguage?: (newLang: string) => void;
25
33
  }
@@ -47,6 +55,7 @@ export interface UseModernI18nReturn {
47
55
  changeLanguage: (newLang: string) => Promise<void>;
48
56
  i18nInstance: I18nInstance;
49
57
  supportedLanguages: string[];
58
+ localisedUrls?: LocalisedUrlsOption;
50
59
  isLanguageSupported: (lang: string) => boolean;
51
60
  // Indicates if translation resources for current language are ready to use
52
61
  isResourcesReady: boolean;
@@ -77,15 +86,40 @@ export const useModernI18n = (): UseModernI18nReturn => {
77
86
  languages,
78
87
  localePathRedirect,
79
88
  ignoreRedirectRoutes,
89
+ localisedUrls,
80
90
  updateLanguage,
81
91
  } = context;
82
92
 
83
- // Get router hooks safely
84
- const { navigate, location, hasRouter } = useRouterHooks();
93
+ const { navigate, location, hasRouter } = useI18nRouterAdapter();
94
+
95
+ const pathLanguage = useMemo(() => {
96
+ if (!localePathRedirect || !location?.pathname) {
97
+ return undefined;
98
+ }
99
+ const detected = detectLanguageFromPath(
100
+ location.pathname,
101
+ languages || [],
102
+ localePathRedirect,
103
+ );
104
+ return detected.detected ? detected.language : undefined;
105
+ }, [languages, localePathRedirect, location?.pathname]);
106
+
107
+ const currentLanguage = pathLanguage || contextLanguage;
85
108
 
86
- // Get current language from context (which reflects the actual current language)
87
- // URL params might be stale after language changes, so we prioritize the context language
88
- const currentLanguage = contextLanguage;
109
+ useEffect(() => {
110
+ if (!pathLanguage || pathLanguage === contextLanguage) {
111
+ return;
112
+ }
113
+
114
+ updateLanguage?.(pathLanguage);
115
+ i18nInstance?.setLang?.(pathLanguage);
116
+ void i18nInstance?.changeLanguage?.(pathLanguage);
117
+
118
+ if (isBrowser()) {
119
+ const detectionOptions = i18nInstance.options?.detection;
120
+ cacheUserLanguage(i18nInstance, pathLanguage, detectionOptions);
121
+ }
122
+ }, [contextLanguage, i18nInstance, pathLanguage, updateLanguage]);
89
123
 
90
124
  /**
91
125
  * Changes the current language and updates the URL accordingly.
@@ -147,6 +181,7 @@ export const useModernI18n = (): UseModernI18nReturn => {
147
181
  relativePath,
148
182
  newLang,
149
183
  languages || [],
184
+ localisedUrls,
150
185
  );
151
186
  const newUrl =
152
187
  entryPath + newPath + location.search + location.hash;
@@ -181,6 +216,7 @@ export const useModernI18n = (): UseModernI18nReturn => {
181
216
  relativePath,
182
217
  newLang,
183
218
  languages || [],
219
+ localisedUrls,
184
220
  );
185
221
  const newUrl =
186
222
  entryPath +
@@ -206,6 +242,7 @@ export const useModernI18n = (): UseModernI18nReturn => {
206
242
  updateLanguage,
207
243
  localePathRedirect,
208
244
  ignoreRedirectRoutes,
245
+ localisedUrls,
209
246
  languages,
210
247
  hasRouter,
211
248
  navigate,
@@ -275,6 +312,7 @@ export const useModernI18n = (): UseModernI18nReturn => {
275
312
  changeLanguage,
276
313
  i18nInstance,
277
314
  supportedLanguages: languages || [],
315
+ localisedUrls,
278
316
  isLanguageSupported,
279
317
  isResourcesReady,
280
318
  };
@@ -2,6 +2,7 @@ import type { TRuntimeContext } from '@modern-js/runtime';
2
2
  import { isBrowser } from '@modern-js/runtime';
3
3
  import type React from 'react';
4
4
  import { useEffect, useRef } from 'react';
5
+ import type { LocalisedUrlsOption } from '../shared/localisedUrls';
5
6
  import type { I18nInstance } from './i18n';
6
7
  import {
7
8
  getI18nSdkBackendId,
@@ -9,13 +10,13 @@ import {
9
10
  type I18nSdkResourcesLoadedEventDetail,
10
11
  } from './i18n/backend/sdk-event';
11
12
  import { cacheUserLanguage } from './i18n/detection';
13
+ import { useI18nRouterAdapter } from './routerAdapter';
12
14
  import {
13
15
  buildLocalizedUrl,
14
16
  detectLanguageFromPath,
15
17
  getEntryPath,
16
18
  getPathname,
17
19
  shouldIgnoreRedirect,
18
- useRouterHooks,
19
20
  } from './utils';
20
21
 
21
22
  interface RuntimeContextWithI18n extends TRuntimeContext {
@@ -41,6 +42,7 @@ export function createContextValue(
41
42
  languages: string[],
42
43
  localePathRedirect: boolean,
43
44
  ignoreRedirectRoutes: string[] | ((pathname: string) => boolean) | undefined,
45
+ localisedUrls: LocalisedUrlsOption | undefined,
44
46
  setLang: (lang: string) => void,
45
47
  ) {
46
48
  const instance = i18nInstance || createMinimalI18nInstance(lang);
@@ -51,6 +53,7 @@ export function createContextValue(
51
53
  languages,
52
54
  localePathRedirect,
53
55
  ignoreRedirectRoutes,
56
+ localisedUrls,
54
57
  updateLanguage: setLang,
55
58
  };
56
59
  }
@@ -162,10 +165,10 @@ export function useClientSideRedirect(
162
165
  languages: string[],
163
166
  fallbackLanguage: string,
164
167
  ignoreRedirectRoutes?: string[] | ((pathname: string) => boolean),
168
+ localisedUrls?: LocalisedUrlsOption,
165
169
  ) {
166
170
  const hasRedirectedRef = useRef(false);
167
- // Get router hooks safely
168
- const { navigate, location, hasRouter } = useRouterHooks();
171
+ const { navigate, location, hasRouter } = useI18nRouterAdapter();
169
172
 
170
173
  useEffect(() => {
171
174
  if (process.env.MODERN_TARGET !== 'browser') {
@@ -220,7 +223,12 @@ export function useClientSideRedirect(
220
223
  const targetLanguage =
221
224
  i18nInstance.language || fallbackLanguage || languages[0] || 'en';
222
225
 
223
- const newPath = buildLocalizedUrl(relativePath, targetLanguage, languages);
226
+ const newPath = buildLocalizedUrl(
227
+ relativePath,
228
+ targetLanguage,
229
+ languages,
230
+ localisedUrls,
231
+ );
224
232
  const newUrl = entryPath + newPath + currentSearch + currentHash;
225
233
 
226
234
  if (newUrl !== currentPathname + currentSearch + currentHash) {
@@ -244,6 +252,7 @@ export function useClientSideRedirect(
244
252
  languages,
245
253
  fallbackLanguage,
246
254
  ignoreRedirectRoutes,
255
+ localisedUrls,
247
256
  ]);
248
257
  }
249
258
 
@@ -15,7 +15,9 @@ function convertPath(path: string | undefined): string | undefined {
15
15
  }
16
16
  // If it's an absolute path (starts with /), convert to relative path
17
17
  if (path.startsWith('/')) {
18
- return `${window.__assetPrefix__ || ''}${path}`;
18
+ return typeof window === 'undefined'
19
+ ? path
20
+ : `${window.__assetPrefix__ || ''}${path}`;
19
21
  }
20
22
  return path;
21
23
  }
@@ -1,4 +1,4 @@
1
- import Backend from 'i18next-fs-backend';
1
+ import Backend from 'i18next-fs-backend/cjs';
2
2
  import type { ExtendedBackendOptions } from '../../../shared/type';
3
3
  import type { I18nInstance } from '../instance';
4
4
  import { useI18nextBackendCommon } from './middleware.common';
@@ -167,15 +167,6 @@ async function createI18nextInstance(): Promise<I18nInstance | null> {
167
167
  }
168
168
  }
169
169
 
170
- async function tryImportReactI18next() {
171
- try {
172
- const reactI18next = await import('react-i18next');
173
- return reactI18next;
174
- } catch (error) {
175
- return null;
176
- }
177
- }
178
-
179
170
  export function getI18nextInstanceForProvider(
180
171
  instance: I18nInstance | any,
181
172
  ): any {
@@ -209,19 +200,3 @@ export async function getI18nInstance(
209
200
 
210
201
  throw new Error('No i18n instance found');
211
202
  }
212
-
213
- export async function getInitReactI18next() {
214
- const reactI18nextModule = await tryImportReactI18next();
215
- if (reactI18nextModule) {
216
- return reactI18nextModule.initReactI18next;
217
- }
218
- return null;
219
- }
220
-
221
- export async function getI18nextProvider() {
222
- const reactI18nextModule = await tryImportReactI18next();
223
- if (reactI18nextModule) {
224
- return reactI18nextModule.I18nextProvider;
225
- }
226
- return null;
227
- }
@@ -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,
@@ -54,6 +50,7 @@ export interface I18nPluginOptions {
54
50
  changeLanguage?: (lang: string) => void;
55
51
  initOptions?: I18nInitOptions;
56
52
  htmlLangAttr?: boolean;
53
+ reactI18next?: boolean;
57
54
  [key: string]: any;
58
55
  }
59
56
 
@@ -72,6 +69,7 @@ export const i18nPlugin = (options: I18nPluginOptions): RuntimePlugin => ({
72
69
  localeDetection,
73
70
  backend,
74
71
  htmlLangAttr = false,
72
+ reactI18next = true,
75
73
  } = options;
76
74
  const {
77
75
  localePathRedirect = false,
@@ -80,20 +78,31 @@ export const i18nPlugin = (options: I18nPluginOptions): RuntimePlugin => ({
80
78
  fallbackLanguage = 'en',
81
79
  detection,
82
80
  ignoreRedirectRoutes,
81
+ localisedUrls,
83
82
  } = localeDetection || {};
84
83
  const { enabled: backendEnabled = false } = backend || {};
85
84
  let latestI18nInstance: I18nInstance | undefined;
86
85
  let I18nextProvider: React.FunctionComponent<any> | null;
87
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
+
88
97
  api.onBeforeRender(async context => {
89
98
  let i18nInstance = await getI18nInstance(userI18nInstance);
90
99
  const { i18n: otherConfig } = api.getRuntimeConfig();
91
100
  const { initOptions: otherInitOptions } = otherConfig || {};
92
101
  const userInitOptions = merge(otherInitOptions || {}, initOptions || {});
93
- const initReactI18next = await getInitReactI18next();
94
- I18nextProvider = await getI18nextProvider();
95
- if (initReactI18next) {
96
- i18nInstance.use(initReactI18next);
102
+ const reactI18nextIntegration = await loadReactI18nextIntegration();
103
+ I18nextProvider = reactI18nextIntegration?.I18nextProvider ?? null;
104
+ if (reactI18nextIntegration?.initReactI18next) {
105
+ i18nInstance.use(reactI18nextIntegration.initReactI18next);
97
106
  }
98
107
 
99
108
  const pathname = getPathname(context);
@@ -227,6 +236,7 @@ export const i18nPlugin = (options: I18nPluginOptions): RuntimePlugin => ({
227
236
  languages,
228
237
  fallbackLanguage,
229
238
  ignoreRedirectRoutes,
239
+ localisedUrls,
230
240
  );
231
241
 
232
242
  const contextValue = useMemo(
@@ -238,6 +248,7 @@ export const i18nPlugin = (options: I18nPluginOptions): RuntimePlugin => ({
238
248
  languages,
239
249
  localePathRedirect,
240
250
  ignoreRedirectRoutes,
251
+ localisedUrls,
241
252
  setLang,
242
253
  ),
243
254
  [
@@ -247,6 +258,7 @@ export const i18nPlugin = (options: I18nPluginOptions): RuntimePlugin => ({
247
258
  languages,
248
259
  localePathRedirect,
249
260
  ignoreRedirectRoutes,
261
+ localisedUrls,
250
262
  forceUpdate,
251
263
  ],
252
264
  );