@bleedingdev/modern-js-plugin-i18n 3.9.3-ultramodern.9 → 3.11.3-ultramodern.10

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 (72) hide show
  1. package/dist/cjs/cli/index.js +10 -0
  2. package/dist/cjs/runtime/context.js +5 -5
  3. package/dist/cjs/runtime/contextHelpers.js +2 -10
  4. package/dist/cjs/runtime/hooks.js +1 -16
  5. package/dist/cjs/runtime/i18n/backend/defaults.js +3 -4
  6. package/dist/cjs/runtime/i18n/backend/sdk-event.js +5 -6
  7. package/dist/cjs/runtime/i18n/instance.js +9 -22
  8. package/dist/cjs/runtime/i18n/react-i18next.js +2 -2
  9. package/dist/cjs/runtime/i18n/utils.js +1 -1
  10. package/dist/cjs/runtime/pluginSetup.js +9 -5
  11. package/dist/cjs/runtime/providerComposition.js +3 -3
  12. package/dist/cjs/shared/deepMerge.js +2 -2
  13. package/dist/cjs/shared/utils.js +3 -3
  14. package/dist/esm/cli/index.mjs +10 -0
  15. package/dist/esm/runtime/context.mjs +6 -6
  16. package/dist/esm/runtime/contextHelpers.mjs +1 -6
  17. package/dist/esm/runtime/hooks.mjs +1 -16
  18. package/dist/esm/runtime/i18n/instance.mjs +3 -16
  19. package/dist/esm/runtime/i18n/utils.mjs +1 -1
  20. package/dist/esm/runtime/navigation.mjs +1 -1
  21. package/dist/esm/runtime/pluginSetup.mjs +6 -2
  22. package/dist/esm/runtime/providerComposition.mjs +3 -3
  23. package/dist/esm/server/index.mjs +1 -1
  24. package/dist/esm-node/cli/index.mjs +10 -0
  25. package/dist/esm-node/runtime/context.mjs +6 -6
  26. package/dist/esm-node/runtime/contextHelpers.mjs +1 -6
  27. package/dist/esm-node/runtime/hooks.mjs +1 -16
  28. package/dist/esm-node/runtime/i18n/instance.mjs +3 -16
  29. package/dist/esm-node/runtime/i18n/utils.mjs +1 -1
  30. package/dist/esm-node/runtime/navigation.mjs +1 -1
  31. package/dist/esm-node/runtime/pluginSetup.mjs +6 -2
  32. package/dist/esm-node/runtime/providerComposition.mjs +3 -3
  33. package/dist/esm-node/server/index.mjs +1 -1
  34. package/dist/types/runtime/context.d.ts +16 -14
  35. package/dist/types/runtime/contextHelpers.d.ts +5 -6
  36. package/dist/types/runtime/core.d.ts +3 -3
  37. package/dist/types/runtime/hooks.d.ts +6 -6
  38. package/dist/types/runtime/i18n/backend/middleware.common.d.ts +2 -2
  39. package/dist/types/runtime/i18n/backend/middleware.d.ts +2 -2
  40. package/dist/types/runtime/i18n/backend/middleware.node.d.ts +2 -2
  41. package/dist/types/runtime/i18n/detection/cache.d.ts +5 -5
  42. package/dist/types/runtime/i18n/detection/detector.d.ts +2 -2
  43. package/dist/types/runtime/i18n/detection/middleware.d.ts +4 -4
  44. package/dist/types/runtime/i18n/detection/middleware.node.d.ts +4 -4
  45. package/dist/types/runtime/i18n/detection/priority.d.ts +2 -2
  46. package/dist/types/runtime/i18n/index.d.ts +1 -1
  47. package/dist/types/runtime/i18n/instance.d.ts +28 -11
  48. package/dist/types/runtime/i18n/utils.d.ts +7 -7
  49. package/dist/types/runtime/navigation.d.ts +4 -1
  50. package/dist/types/runtime/pluginSetup.d.ts +4 -4
  51. package/dist/types/runtime/providerComposition.d.ts +3 -3
  52. package/dist/types/runtime/types.d.ts +3 -3
  53. package/package.json +25 -24
  54. package/src/cli/index.ts +19 -1
  55. package/src/runtime/context.tsx +26 -24
  56. package/src/runtime/contextHelpers.ts +5 -26
  57. package/src/runtime/core.tsx +5 -3
  58. package/src/runtime/hooks.ts +7 -27
  59. package/src/runtime/i18n/backend/middleware.common.ts +3 -3
  60. package/src/runtime/i18n/backend/middleware.node.ts +2 -2
  61. package/src/runtime/i18n/backend/middleware.ts +2 -2
  62. package/src/runtime/i18n/detection/cache.ts +8 -8
  63. package/src/runtime/i18n/detection/detector.ts +5 -5
  64. package/src/runtime/i18n/detection/middleware.node.ts +7 -5
  65. package/src/runtime/i18n/detection/middleware.ts +6 -4
  66. package/src/runtime/i18n/detection/priority.ts +2 -2
  67. package/src/runtime/i18n/index.ts +2 -0
  68. package/src/runtime/i18n/instance.ts +50 -49
  69. package/src/runtime/i18n/utils.ts +14 -10
  70. package/src/runtime/pluginSetup.ts +12 -6
  71. package/src/runtime/providerComposition.tsx +31 -21
  72. package/src/runtime/types.ts +3 -3
@@ -2,9 +2,9 @@ import "node:module";
2
2
  import { jsx } from "react/jsx-runtime";
3
3
  import { RuntimeComponentResolverContext } from "@modern-js/runtime/context";
4
4
  import { useCallback, useContext, useEffect, useMemo } from "react";
5
- import { changeModernI18nLanguage, getPathLanguage, isI18nLanguageSupported, isI18nResourcesReady, translateI18n } from "./contextHelpers.mjs";
6
- import { useI18nRouterAdapter } from "./routerAdapter.mjs";
5
+ import { changeModernI18nLanguage, getPathLanguage, isI18nLanguageSupported, isI18nResourcesReady } from "./contextHelpers.mjs";
7
6
  import { ModernI18nContext, ReactI18nextProviderContext } from "./sharedContexts.mjs";
7
+ import { useI18nRouterAdapter } from "./routerAdapter.mjs";
8
8
  const ModernI18nProvider = ({ children, i18nextProvider, value })=>{
9
9
  const content = /*#__PURE__*/ jsx(ModernI18nContext.Provider, {
10
10
  value: value,
@@ -28,7 +28,7 @@ const FederatedI18nBoundary = (props)=>{
28
28
  ...props
29
29
  });
30
30
  };
31
- const useModernI18n = ()=>{
31
+ function useModernI18n() {
32
32
  const context = useContext(ModernI18nContext);
33
33
  if (!context) throw new Error('useModernI18n must be used within ModernI18nProvider');
34
34
  const { language: contextLanguage, i18nInstance, languages, localePathRedirect, ignoreRedirectRoutes, urlStrategy, updateLanguage, synchronizeLanguage } = context;
@@ -66,7 +66,7 @@ const useModernI18n = ()=>{
66
66
  navigate,
67
67
  location
68
68
  ]);
69
- const t = useCallback((key, ...args)=>translateI18n(i18nInstance, key, ...args), [
69
+ const t = useMemo(()=>i18nInstance.t.bind(i18nInstance), [
70
70
  currentLanguage,
71
71
  i18nInstance
72
72
  ]);
@@ -81,12 +81,12 @@ const useModernI18n = ()=>{
81
81
  language: currentLanguage,
82
82
  changeLanguage,
83
83
  t,
84
- i18nInstance: i18nInstance,
84
+ i18nInstance,
85
85
  supportedLanguages: languages || [],
86
86
  urlStrategy,
87
87
  isLanguageSupported,
88
88
  isResourcesReady
89
89
  };
90
- };
90
+ }
91
91
  export { getActualI18nextInstance } from "./i18n/instance.mjs";
92
92
  export { FederatedI18nBoundary, ModernI18nContext, ModernI18nProvider, ReactI18nextProviderContext, useModernI18n };
@@ -54,11 +54,6 @@ async function changeModernI18nLanguage(newLang, options) {
54
54
  throw error;
55
55
  }
56
56
  }
57
- function translateI18n(i18nInstance, key, ...args) {
58
- if ('function' != typeof i18nInstance.t) throw new Error('i18nInstance.t required');
59
- const translate = i18nInstance.t;
60
- return translate.call(i18nInstance, key, ...args);
61
- }
62
57
  function isI18nLanguageSupported(languages, lang) {
63
58
  return languages?.includes(lang) || false;
64
59
  }
@@ -86,4 +81,4 @@ function isI18nResourcesReady(i18nInstance, currentLanguage) {
86
81
  return nsData && 'object' == typeof nsData && Object.keys(nsData).length > 0;
87
82
  });
88
83
  }
89
- export { cacheI18nLanguage, changeI18nInstanceLanguage, changeModernI18nLanguage, getPathLanguage, isI18nLanguageSupported, isI18nResourcesReady, translateI18n };
84
+ export { cacheI18nLanguage, changeI18nInstanceLanguage, changeModernI18nLanguage, getPathLanguage, isI18nLanguageSupported, isI18nResourcesReady };
@@ -5,25 +5,10 @@ import { cacheI18nLanguage, changeI18nInstanceLanguage } from "./contextHelpers.
5
5
  import { I18N_SDK_RESOURCES_LOADED_EVENT, getI18nSdkBackendId } from "./i18n/backend/sdk-event.mjs";
6
6
  import { useI18nRouterAdapter } from "./routerAdapter.mjs";
7
7
  import { buildLocalizedUrl, detectLanguageFromPath, getEntryPath, shouldIgnoreRedirect } from "./utils.mjs";
8
- function createMinimalI18nInstance(language) {
9
- const minimalInstance = {
10
- language,
11
- isInitialized: false,
12
- init: ()=>Promise.resolve(void 0),
13
- t: ()=>{
14
- throw new Error('i18nInstance.t required');
15
- },
16
- use: ()=>{},
17
- createInstance: ()=>minimalInstance,
18
- services: {}
19
- };
20
- return minimalInstance;
21
- }
22
8
  function createContextValue(lang, i18nInstance, entryName, languages, localePathRedirect, ignoreRedirectRoutes, setLang, urlStrategy) {
23
- const instance = i18nInstance || createMinimalI18nInstance(lang);
24
9
  return {
25
10
  language: lang,
26
- i18nInstance: instance,
11
+ i18nInstance,
27
12
  entryName,
28
13
  languages,
29
14
  localePathRedirect,
@@ -8,16 +8,8 @@ function isI18nWrapperInstance(obj) {
8
8
  if ('function' != typeof candidate.init || 'function' != typeof candidate.use) return false;
9
9
  return true;
10
10
  }
11
- function getI18nWrapperI18nextInstance(wrapperInstance) {
12
- if (isI18nWrapperInstance(wrapperInstance)) return wrapperInstance.i18nInstance?.instance;
13
- return null;
14
- }
15
11
  function getActualI18nextInstance(instance) {
16
- if (isI18nWrapperInstance(instance)) {
17
- const i18nextInstance = getI18nWrapperI18nextInstance(instance);
18
- return i18nextInstance || instance;
19
- }
20
- return instance;
12
+ return isI18nWrapperInstance(instance) ? instance.i18nInstance.instance : instance;
21
13
  }
22
14
  function isI18nInstance(obj) {
23
15
  if (!obj || 'object' != typeof obj) return false;
@@ -39,17 +31,13 @@ async function createI18nextInstance() {
39
31
  if (!i18next) return null;
40
32
  return i18next.createInstance?.({
41
33
  initImmediate: false
42
- });
34
+ }) ?? null;
43
35
  } catch (error) {
44
36
  return null;
45
37
  }
46
38
  }
47
39
  function getI18nextInstanceForProvider(instance, language) {
48
- let providerInstance = instance;
49
- if (isI18nWrapperInstance(instance)) {
50
- const i18nextInstance = getI18nWrapperI18nextInstance(instance);
51
- if (i18nextInstance) providerInstance = i18nextInstance;
52
- }
40
+ const providerInstance = getActualI18nextInstance(instance);
53
41
  if (!language || "u" < typeof Proxy) return providerInstance;
54
42
  return new Proxy(providerInstance, {
55
43
  get (target, property, receiver) {
@@ -77,7 +65,6 @@ function getI18nextInstanceForProvider(instance, language) {
77
65
  }
78
66
  async function getI18nInstance(userInstance) {
79
67
  if (userInstance) {
80
- if (isI18nWrapperInstance(userInstance)) return userInstance;
81
68
  if (isI18nInstance(userInstance)) return userInstance;
82
69
  }
83
70
  const i18nextInstance = await createI18nextInstance();
@@ -6,7 +6,7 @@ import { SdkBackend } from "./backend/sdk-backend.mjs";
6
6
  import { cacheUserLanguage, mergeDetectionOptions } from "./detection/index.mjs";
7
7
  import { getActualI18nextInstance, isI18nInstance, isI18nWrapperInstance } from "./instance.mjs";
8
8
  function assertI18nInstance(obj) {
9
- if (!isI18nInstance(obj)) throw new Error('Object does not implement I18nInstance interface');
9
+ if (!isI18nInstance(obj)) throw new Error('Object does not implement I18nRuntimeInstance interface');
10
10
  }
11
11
  const buildInitOptions = async (finalLanguage, fallbackLanguage, languages, mergedDetection, mergedBackend, userInitOptions, useSuspense, i18nInstance)=>{
12
12
  const defaultUseSuspense = void 0 !== useSuspense ? useSuspense : isBrowser() ? userInitOptions?.react?.useSuspense ?? true : false;
@@ -1,7 +1,7 @@
1
1
  import "node:module";
2
2
  import { createI18nRouterNavigation } from "@modern-js/i18n-runtime-extensions/router-navigation";
3
3
  import { I18nNavigationProvider, useNativeI18nRouterAdapter } from "./routerAdapter.mjs";
4
- const { I18nRouterNavigationProvider: I18nRouterNavigationProvider, useIntegratedRouterAdapter: useIntegratedRouterAdapter } = createI18nRouterNavigation({
4
+ const { I18nRouterNavigationProvider, useIntegratedRouterAdapter } = createI18nRouterNavigation({
5
5
  I18nNavigationProvider: I18nNavigationProvider,
6
6
  useNativeI18nRouterAdapter: useNativeI18nRouterAdapter
7
7
  });
@@ -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);
@@ -40,7 +40,7 @@ const createI18nRootWrapper = (options)=>(App)=>{
40
40
  ]);
41
41
  useSdkResourcesLoader(i18nInstance, setForceUpdate);
42
42
  useClientSideRedirect(i18nInstance, localePathRedirect, languages, fallbackLanguage, ignoreRedirectRoutes, urlStrategy);
43
- const contextValue = useMemo(()=>createContextValue(lang, i18nInstance, entryName, languages, localePathRedirect, ignoreRedirectRoutes, setLang, urlStrategy), [
43
+ const contextValue = useMemo(()=>i18nInstance ? createContextValue(lang, i18nInstance, entryName, languages, localePathRedirect, ignoreRedirectRoutes, setLang, urlStrategy) : void 0, [
44
44
  lang,
45
45
  i18nInstance,
46
46
  entryName,
@@ -78,14 +78,14 @@ const createI18nRootWrapper = (options)=>(App)=>{
78
78
  pathname: location?.pathname,
79
79
  prevLangRef: prevLangRef,
80
80
  setLang: setLang,
81
- children: (synchronizeLanguage)=>/*#__PURE__*/ jsx(ModernI18nProvider, {
81
+ children: (synchronizeLanguage)=>contextValue ? /*#__PURE__*/ jsx(ModernI18nProvider, {
82
82
  i18nextProvider: I18nextProvider,
83
83
  value: {
84
84
  ...contextValue,
85
85
  synchronizeLanguage
86
86
  },
87
87
  children: appContent
88
- })
88
+ }) : appContent
89
89
  })
90
90
  ]
91
91
  });
@@ -6,7 +6,7 @@ import { resolveDefaultUrlStrategy } from "./defaultUrlStrategy.mjs";
6
6
  import { convertToHonoLanguageDetectorOptions } from "./detectorOptions.mjs";
7
7
  import { buildLocalizedUrl, createLocaleRedirectResponse, getLanguageFromPath, isStaticResourceRequest, shouldIgnoreRedirect } from "./redirectPolicy.mjs";
8
8
  import * as __rspack_external__modern_js_server_core_hono_0af3baa7 from "@modern-js/server-core/hono";
9
- const { languageDetector: languageDetector } = __rspack_external__modern_js_server_core_hono_0af3baa7;
9
+ const { languageDetector } = __rspack_external__modern_js_server_core_hono_0af3baa7;
10
10
  const i18nServerPlugin = (options)=>({
11
11
  name: '@modern-js/plugin-i18n/server',
12
12
  setup: (api)=>{
@@ -1,12 +1,12 @@
1
1
  import type { ComponentType, FC, ReactNode } from 'react';
2
2
  import type { I18nUrlStrategy } from '../shared/urlStrategy.js';
3
- import type { I18nInstance } from './i18n/index.js';
4
- import type { Resources } from './i18n/instance.js';
3
+ import type { I18nInstance, I18nRuntimeInstance } from './i18n/index.js';
4
+ import { getActualI18nextInstance, type Resources } from './i18n/instance.js';
5
5
  import { ModernI18nContext, ReactI18nextProviderContext } from './sharedContexts.js';
6
- export { getActualI18nextInstance } from './i18n/instance.js';
6
+ export { getActualI18nextInstance };
7
7
  export interface ModernI18nContextValue {
8
8
  language: string;
9
- i18nInstance: I18nInstance;
9
+ i18nInstance: I18nRuntimeInstance;
10
10
  entryName?: string;
11
11
  languages?: string[];
12
12
  localePathRedirect?: boolean;
@@ -30,10 +30,14 @@ export interface FederatedI18nBoundaryProps {
30
30
  supportedLanguages?: string[];
31
31
  }
32
32
  export declare const FederatedI18nBoundary: FC<FederatedI18nBoundaryProps>;
33
- export interface UseModernI18nReturn<TInstance extends I18nInstance = I18nInstance> {
33
+ export interface UseModernI18nReturn<TInstance extends I18nRuntimeInstance = I18nInstance> {
34
34
  language: string;
35
35
  changeLanguage: (newLang: string) => Promise<void>;
36
- t: (key: string | string[], ...args: any[]) => string;
36
+ /**
37
+ * The configured instance's own `t`, bound to it: i18next's `t` for an
38
+ * i18next instance, the wrapper's translate API for a wrapper.
39
+ */
40
+ t: OmitThisParameter<TInstance['t']>;
37
41
  i18nInstance: TInstance;
38
42
  supportedLanguages: string[];
39
43
  urlStrategy?: I18nUrlStrategy;
@@ -50,13 +54,11 @@ export interface UseModernI18nReturn<TInstance extends I18nInstance = I18nInstan
50
54
  * - List of supported languages
51
55
  * - Helper function to check if language is supported
52
56
  *
53
- * @typeParam TInstance - The concrete shape of the i18n instance held by the
54
- * provider (e.g. i18next's `i18n`, or a wrapper type). Constrained to
55
- * `I18nInstance`, so a nonsense argument is rejected; within that constraint it
56
- * is still a caller assertion — the provider stores the base type and the
57
- * narrowing is not verified at runtime. Pass it only when you know which
58
- * instance the provider was given.
59
- * @param options - Optional configuration to override context settings
57
+ * Without a type argument, `i18nInstance` and `t` are typed for an i18next
58
+ * instance, so `t` keeps i18next's keys, options and selectors. An app that
59
+ * configures a wrapper passes its type (e.g. `useModernI18n<MyWrapper>()`).
60
+ * Either way the type is a caller assertion that the overload records; it is
61
+ * not verified at runtime.
60
62
  * @returns Object containing i18n functionality and utilities
61
63
  */
62
- export declare const useModernI18n: <TInstance extends I18nInstance = I18nInstance>() => UseModernI18nReturn<TInstance>;
64
+ export declare function useModernI18n<TInstance extends I18nRuntimeInstance = I18nInstance>(): UseModernI18nReturn<TInstance>;
@@ -1,5 +1,5 @@
1
1
  import type { I18nUrlStrategy } from '../shared/urlStrategy.js';
2
- import type { I18nInstance } from './i18n/index.js';
2
+ import type { I18nRuntimeInstance } from './i18n/index.js';
3
3
  type Navigate = (url: string, options?: {
4
4
  replace?: boolean;
5
5
  }) => Promise<void> | void;
@@ -9,10 +9,10 @@ type LocationLike = {
9
9
  hash: string;
10
10
  };
11
11
  export declare function getPathLanguage(pathname: string | undefined, languages: string[] | undefined, localePathRedirect: boolean | undefined): string | undefined;
12
- export declare function cacheI18nLanguage(i18nInstance: I18nInstance, language: string): void;
13
- export declare function changeI18nInstanceLanguage(i18nInstance: I18nInstance, language: string): Promise<void>;
12
+ export declare function cacheI18nLanguage(i18nInstance: I18nRuntimeInstance, language: string): void;
13
+ export declare function changeI18nInstanceLanguage(i18nInstance: I18nRuntimeInstance, language: string): Promise<void>;
14
14
  interface ChangeModernI18nLanguageOptions {
15
- i18nInstance: I18nInstance;
15
+ i18nInstance: I18nRuntimeInstance;
16
16
  updateLanguage?: (newLang: string) => void;
17
17
  localePathRedirect?: boolean;
18
18
  ignoreRedirectRoutes?: string[] | ((pathname: string) => boolean);
@@ -23,7 +23,6 @@ interface ChangeModernI18nLanguageOptions {
23
23
  location?: LocationLike | null;
24
24
  }
25
25
  export declare function changeModernI18nLanguage(newLang: string, options: ChangeModernI18nLanguageOptions): Promise<void>;
26
- export declare function translateI18n(i18nInstance: I18nInstance, key: string | string[], ...args: unknown[]): string;
27
26
  export declare function isI18nLanguageSupported(languages: string[] | undefined, lang: string): boolean;
28
- export declare function isI18nResourcesReady(i18nInstance: I18nInstance, currentLanguage: string): boolean;
27
+ export declare function isI18nResourcesReady(i18nInstance: I18nRuntimeInstance, currentLanguage: string): boolean;
29
28
  export {};
@@ -2,14 +2,14 @@ import type { RuntimePlugin } from '@modern-js/runtime';
2
2
  import type React from 'react';
3
3
  import type { BaseBackendOptions, BaseLocaleDetectionOptions } from '../shared/type.js';
4
4
  import { type I18nUrlStrategy } from '../shared/urlStrategy.js';
5
- import type { I18nInitOptions, I18nInstance } from './i18n/index.js';
5
+ import type { I18nInitOptions, I18nRuntimeInstance } from './i18n/index.js';
6
6
  import { type I18nLanguageSynchronizationProps } from './providerComposition.js';
7
7
  export type { I18nLanguageSynchronizationProps } from './providerComposition.js';
8
8
  import { type LoadReactI18nextIntegration } from './reactI18next.js';
9
9
  import './types.js';
10
10
  export type { I18nSdkLoader, I18nSdkLoadOptions } from '../shared/type.js';
11
11
  export type { I18nUrlStrategy } from '../shared/urlStrategy.js';
12
- export type { I18nInitOptions, I18nInstance, Resources, TranslateFn, } from './i18n/instance.js';
12
+ export type { I18nInitOptions, I18nInstance, I18nRuntimeInstance, I18nWrapperInstance, Resources, TranslateFn, } from './i18n/instance.js';
13
13
  export { I18nRouterNavigationProvider, useIntegratedRouterAdapter, } from './navigation.js';
14
14
  export type { LoadReactI18nextIntegration, ReactI18nextIntegration, } from './reactI18next.js';
15
15
  export { I18nNavigationProvider, type I18nRouterAdapter, type I18nRouterLinkTarget, useI18nRouterAdapter, useNativeI18nRouterAdapter, } from './routerAdapter.js';
@@ -17,7 +17,7 @@ export interface I18nPluginOptions {
17
17
  entryName?: string;
18
18
  localeDetection?: BaseLocaleDetectionOptions;
19
19
  backend?: BaseBackendOptions;
20
- i18nInstance?: I18nInstance;
20
+ i18nInstance?: I18nRuntimeInstance;
21
21
  changeLanguage?: (lang: string) => void;
22
22
  initOptions?: I18nInitOptions;
23
23
  htmlLangAttr?: boolean;
@@ -1,9 +1,9 @@
1
1
  import type React from 'react';
2
2
  import type { I18nUrlStrategy } from '../shared/urlStrategy.js';
3
- import type { I18nInstance } from './i18n/index.js';
4
- export declare function createContextValue(lang: string, i18nInstance: I18nInstance | undefined, entryName: string | undefined, languages: string[], localePathRedirect: boolean, ignoreRedirectRoutes: string[] | ((pathname: string) => boolean) | undefined, setLang: (lang: string) => void, urlStrategy?: I18nUrlStrategy): {
3
+ import type { I18nRuntimeInstance } from './i18n/index.js';
4
+ export declare function createContextValue(lang: string, i18nInstance: I18nRuntimeInstance, entryName: string | undefined, languages: string[], localePathRedirect: boolean, ignoreRedirectRoutes: string[] | ((pathname: string) => boolean) | undefined, setLang: (lang: string) => void, urlStrategy?: I18nUrlStrategy): {
5
5
  language: string;
6
- i18nInstance: I18nInstance;
6
+ i18nInstance: I18nRuntimeInstance;
7
7
  entryName: string | undefined;
8
8
  languages: string[];
9
9
  localePathRedirect: boolean;
@@ -11,7 +11,7 @@ export declare function createContextValue(lang: string, i18nInstance: I18nInsta
11
11
  urlStrategy: I18nUrlStrategy | undefined;
12
12
  updateLanguage: (lang: string) => void;
13
13
  };
14
- export declare function useSdkResourcesLoader(i18nInstance: I18nInstance | undefined, setForceUpdate: React.Dispatch<React.SetStateAction<number>>): void;
14
+ export declare function useSdkResourcesLoader(i18nInstance: I18nRuntimeInstance | undefined, setForceUpdate: React.Dispatch<React.SetStateAction<number>>): void;
15
15
  /**
16
16
  * Hook to handle client-side redirect for locale path redirect in static deployments
17
17
  * This ensures that when users access paths without language prefix, they are redirected
@@ -21,5 +21,5 @@ export declare function useSdkResourcesLoader(i18nInstance: I18nInstance | undef
21
21
  * In SSR/SSG scenarios, server-side middleware handles redirects, so this hook is skipped.
22
22
  * We use process.env.MODERN_TARGET to ensure this code is only included in browser bundles.
23
23
  */
24
- export declare function useClientSideRedirect(i18nInstance: I18nInstance | undefined, localePathRedirect: boolean, languages: string[], fallbackLanguage: string, ignoreRedirectRoutes?: string[] | ((pathname: string) => boolean), urlStrategy?: I18nUrlStrategy): void;
25
- export declare function useLanguageSync(i18nInstance: I18nInstance | undefined, localePathRedirect: boolean, languages: string[], pathname: string | undefined, prevLangRef: React.MutableRefObject<string>, setLang: (lang: string) => void): (currentLang: string) => void;
24
+ export declare function useClientSideRedirect(i18nInstance: I18nRuntimeInstance | undefined, localePathRedirect: boolean, languages: string[], fallbackLanguage: string, ignoreRedirectRoutes?: string[] | ((pathname: string) => boolean), urlStrategy?: I18nUrlStrategy): void;
25
+ export declare function useLanguageSync(i18nInstance: I18nRuntimeInstance | undefined, localePathRedirect: boolean, languages: string[], pathname: string | undefined, prevLangRef: React.MutableRefObject<string>, setLang: (lang: string) => void): (currentLang: string) => void;
@@ -1,5 +1,5 @@
1
1
  import type { BaseBackendOptions, ChainedBackendConfig } from '../../../shared/type.js';
2
- import type { I18nInstance } from '../instance.js';
2
+ import type { I18nRuntimeInstance } from '../instance.js';
3
3
  type BackendConfigWithChained = BaseBackendOptions & Partial<ChainedBackendConfig>;
4
4
  type BackendConstructor = new (...args: never[]) => unknown;
5
5
  /**
@@ -11,5 +11,5 @@ type BackendConstructor = new (...args: never[]) => unknown;
11
11
  * @param BackendBase - The base backend class (for non-chained use)
12
12
  * @param backend - Optional backend configuration
13
13
  */
14
- export declare function useI18nextBackendCommon(i18nInstance: I18nInstance, BackendWithSave: BackendConstructor, BackendBase: BackendConstructor, backend?: BackendConfigWithChained): unknown;
14
+ export declare function useI18nextBackendCommon(i18nInstance: I18nRuntimeInstance, BackendWithSave: BackendConstructor, BackendBase: BackendConstructor, backend?: BackendConfigWithChained): unknown;
15
15
  export {};
@@ -1,6 +1,6 @@
1
1
  import Backend from 'i18next-http-backend';
2
2
  import type { ExtendedBackendOptions } from '../../../shared/type.js';
3
- import type { I18nInstance } from '../instance.js';
3
+ import type { I18nRuntimeInstance } from '../instance.js';
4
4
  /**
5
5
  * Wrapper for HTTP backend to add a no-op save method
6
6
  * This is required for i18next-chained-backend to trigger refresh logic
@@ -9,4 +9,4 @@ import type { I18nInstance } from '../instance.js';
9
9
  export declare class HttpBackendWithSave extends Backend {
10
10
  save(_language: string, _namespace: string, _data: unknown): void;
11
11
  }
12
- export declare const useI18nextBackend: (i18nInstance: I18nInstance, backend?: ExtendedBackendOptions) => unknown;
12
+ export declare const useI18nextBackend: (i18nInstance: I18nRuntimeInstance, backend?: ExtendedBackendOptions) => unknown;
@@ -1,5 +1,5 @@
1
1
  import type { ExtendedBackendOptions } from '../../../shared/type.js';
2
- import type { I18nInstance } from '../instance.js';
2
+ import type { I18nRuntimeInstance } from '../instance.js';
3
3
  type BackendConstructor = new (...args: any[]) => any;
4
4
  export declare const resolveFsBackendConstructor: (backendModule: unknown) => BackendConstructor;
5
5
  declare const Backend: BackendConstructor;
@@ -12,5 +12,5 @@ export declare class FsBackendWithSave extends Backend {
12
12
  save(_language: string, _namespace: string, _data: unknown): void;
13
13
  }
14
14
  export declare const HttpBackendWithSave: typeof FsBackendWithSave;
15
- export declare const useI18nextBackend: (i18nInstance: I18nInstance, backend?: ExtendedBackendOptions) => unknown;
15
+ export declare const useI18nextBackend: (i18nInstance: I18nRuntimeInstance, backend?: ExtendedBackendOptions) => unknown;
16
16
  export {};
@@ -1,14 +1,14 @@
1
- import type { I18nInitOptions, I18nInstance, LanguageDetectorOptions } from '../instance.js';
1
+ import type { I18nInitOptions, I18nRuntimeInstance, LanguageDetectorOptions } from '../instance.js';
2
2
  interface DetectorCacheEntry {
3
- instance: I18nInstance;
3
+ instance: I18nRuntimeInstance;
4
4
  isTemporary: boolean;
5
5
  configKey: string;
6
6
  }
7
- export declare const detectorInstanceCache: WeakMap<I18nInstance, DetectorCacheEntry>;
7
+ export declare const detectorInstanceCache: WeakMap<I18nRuntimeInstance, DetectorCacheEntry>;
8
8
  export declare const buildDetectorConfigKey: (languages: string[], fallbackLanguage: string, mergedDetection: LanguageDetectorOptions) => string;
9
9
  export declare const pickSafeDetectionOptions: (userInitOptions?: I18nInitOptions) => Partial<I18nInitOptions> & Record<string, unknown>;
10
- export declare const createDetectorInstance: (baseInstance: I18nInstance, configKey: string) => {
11
- instance: I18nInstance;
10
+ export declare const createDetectorInstance: (baseInstance: I18nRuntimeInstance, configKey: string) => {
11
+ instance: I18nRuntimeInstance;
12
12
  isTemporary: boolean;
13
13
  };
14
14
  export {};
@@ -1,8 +1,8 @@
1
- import type { I18nInstance } from '../instance.js';
1
+ import type { I18nRuntimeInstance } from '../instance.js';
2
2
  import type { BaseLanguageDetectionOptions, LanguageDetectionSsrContext } from './types.js';
3
3
  /**
4
4
  * Priority 3: Detect language using i18next detector
5
5
  */
6
- export declare const detectLanguageFromI18nextDetector: (i18nInstance: I18nInstance, options: BaseLanguageDetectionOptions & {
6
+ export declare const detectLanguageFromI18nextDetector: (i18nInstance: I18nRuntimeInstance, options: BaseLanguageDetectionOptions & {
7
7
  ssrContext?: LanguageDetectionSsrContext;
8
8
  }) => Promise<string | undefined>;
@@ -1,10 +1,10 @@
1
- import type { I18nInstance, LanguageDetectorOptions } from '../instance.js';
1
+ import type { I18nRuntimeInstance, LanguageDetectorOptions } from '../instance.js';
2
2
  /**
3
3
  * Register LanguageDetector plugin to i18n instance
4
4
  * Must be called before init() to properly register the detector
5
5
  * For wrapper instances, ensure detector is registered on the underlying i18next instance
6
6
  */
7
- export declare const useI18nextLanguageDetector: (i18nInstance: I18nInstance) => unknown;
7
+ export declare const useI18nextLanguageDetector: (i18nInstance: I18nRuntimeInstance) => unknown;
8
8
  /**
9
9
  * Read language directly from localStorage/cookie
10
10
  * Fallback when detector is not available in services
@@ -15,10 +15,10 @@ export declare const readLanguageFromStorage: (detectionOptions?: LanguageDetect
15
15
  * For initialized instances without detector in services, manually create a detector instance
16
16
  * For wrapper instances, access the underlying i18next instance's services
17
17
  */
18
- export declare const detectLanguage: (i18nInstance: I18nInstance, _request?: unknown, detectionOptions?: LanguageDetectorOptions) => string | undefined;
18
+ export declare const detectLanguage: (i18nInstance: I18nRuntimeInstance, _request?: unknown, detectionOptions?: LanguageDetectorOptions) => string | undefined;
19
19
  /**
20
20
  * Cache user language to localStorage/cookie
21
21
  * Uses LanguageDetector's cacheUserLanguage method when available
22
22
  * For wrapper instances, access the underlying i18next instance's services
23
23
  */
24
- export declare const cacheUserLanguage: (i18nInstance: I18nInstance, language: string, detectionOptions?: unknown) => void;
24
+ export declare const cacheUserLanguage: (i18nInstance: I18nRuntimeInstance, language: string, detectionOptions?: unknown) => void;
@@ -1,13 +1,13 @@
1
- import type { I18nInstance, LanguageDetectorOptions } from '../instance.js';
2
- export declare const cacheUserLanguage: (_i18nInstance: I18nInstance, _language: string, _detectionOptions?: unknown) => void;
1
+ import type { I18nRuntimeInstance, LanguageDetectorOptions } from '../instance.js';
2
+ export declare const cacheUserLanguage: (_i18nInstance: I18nRuntimeInstance, _language: string, _detectionOptions?: unknown) => void;
3
3
  export declare const readLanguageFromStorage: (detectionOptions?: LanguageDetectorOptions, request?: unknown, languages?: string[]) => string | undefined;
4
4
  /**
5
5
  * Register LanguageDetector plugin to i18n instance
6
6
  * Must be called before init() to properly register the detector
7
7
  */
8
- export declare const useI18nextLanguageDetector: (i18nInstance: I18nInstance) => unknown;
8
+ export declare const useI18nextLanguageDetector: (i18nInstance: I18nRuntimeInstance) => unknown;
9
9
  /**
10
10
  * Detect language using i18next-http-middleware LanguageDetector
11
11
  * For initialized instances without detector in services, manually create a detector instance
12
12
  */
13
- export declare const detectLanguage: (i18nInstance: I18nInstance, request?: unknown, detectionOptions?: LanguageDetectorOptions) => string | undefined;
13
+ export declare const detectLanguage: (i18nInstance: I18nRuntimeInstance, request?: unknown, detectionOptions?: LanguageDetectorOptions) => string | undefined;
@@ -1,4 +1,4 @@
1
- import { type I18nInstance } from '../instance.js';
1
+ import { type I18nRuntimeInstance } from '../instance.js';
2
2
  import type { LanguageDetectionOptions, LanguageDetectionResult } from './types.js';
3
3
  /**
4
4
  * Detect language with priority:
@@ -7,4 +7,4 @@ import type { LanguageDetectionOptions, LanguageDetectionResult } from './types.
7
7
  * Priority 3: i18next detector (reads from cookie/localStorage)
8
8
  * Priority 4: User config language or fallback
9
9
  */
10
- export declare const detectLanguageWithPriority: (i18nInstance: I18nInstance, options: LanguageDetectionOptions) => Promise<LanguageDetectionResult>;
10
+ export declare const detectLanguageWithPriority: (i18nInstance: I18nRuntimeInstance, options: LanguageDetectionOptions) => Promise<LanguageDetectionResult>;
@@ -1,3 +1,3 @@
1
- export type { I18nInitOptions, I18nInstance, } from './instance.js';
1
+ export type { I18nInitOptions, I18nInstance, I18nRuntimeInstance, I18nWrapperInstance, } from './instance.js';
2
2
  export { getI18nInstance, isI18nInstance } from './instance.js';
3
3
  export { assertI18nInstance } from './utils.js';
@@ -1,3 +1,4 @@
1
+ import type { CloneOptions, InitOptions, i18n } from 'i18next';
1
2
  import type { BaseBackendOptions } from '../../shared/type.js';
2
3
  interface I18nResourceStore {
3
4
  data?: {
@@ -7,14 +8,10 @@ interface I18nResourceStore {
7
8
  };
8
9
  addResourceBundle?: (language: string, namespace: string, resources: Record<string, string>, deep?: boolean, overwrite?: boolean) => void;
9
10
  }
10
- type I18nWrapperInstance = I18nInstance & {
11
- i18nInstance: {
12
- instance: I18nInstance;
13
- };
14
- };
15
11
  export declare function isI18nWrapperInstance(obj: unknown): obj is I18nWrapperInstance;
16
- export declare function getActualI18nextInstance(instance: I18nInstance): I18nInstance;
17
- export type TranslateFn = (key: string | string[], options?: Record<string, unknown>) => string;
12
+ /** The i18next instance that owns resources, detection and translation. */
13
+ export declare function getActualI18nextInstance(instance: I18nRuntimeInstance): I18nInstance;
14
+ export type TranslateFn = i18n['t'];
18
15
  export interface I18nInstance {
19
16
  language: string;
20
17
  isInitialized?: boolean;
@@ -24,7 +21,7 @@ export interface I18nInstance {
24
21
  use(plugin: any): unknown;
25
22
  t: TranslateFn;
26
23
  exists?: (key: string | string[], options?: Record<string, unknown>) => boolean;
27
- getFixedT?: (lng: string | readonly string[] | null, ns?: string | readonly string[] | null, keyPrefix?: string) => TranslateFn;
24
+ getFixedT?: i18n['getFixedT'];
28
25
  hasLoadedNamespace?: (ns: string | readonly string[], options?: Record<string, unknown>) => boolean;
29
26
  dir?: (lng?: string) => string;
30
27
  format?: (value: unknown, format?: string, lng?: string, options?: Record<string, unknown>) => string;
@@ -38,6 +35,8 @@ export interface I18nInstance {
38
35
  createInstance?(options?: any, callback?: any): I18nInstance;
39
36
  cloneInstance?(options?: any, callback?: any): I18nInstance;
40
37
  store?: I18nResourceStore;
38
+ on?: i18n['on'];
39
+ off?: i18n['off'];
41
40
  emit?(event: string, ...args: any[]): unknown;
42
41
  reloadResources?(language?: any, namespace?: any, callback?: any): Promise<void>;
43
42
  removeResourceBundle?(language: string, namespace: string): I18nInstance;
@@ -54,6 +53,24 @@ export interface I18nInstance {
54
53
  defaultNS?: any;
55
54
  };
56
55
  }
56
+ /**
57
+ * A custom instance owning a native i18next one at `i18nInstance.instance`.
58
+ * The plugin initialises, switches and clones the wrapper, whose own `t` is
59
+ * `useModernI18n<Wrapper>().t`; resources and detection use the native one.
60
+ */
61
+ export interface I18nWrapperInstance extends Omit<I18nInstance, 't' | 'on' | 'off' | 'cloneInstance' | 'createInstance'> {
62
+ i18nInstance: {
63
+ instance: I18nInstance;
64
+ };
65
+ /** The wrapper's own translate API; it may differ from i18next's `t`. */
66
+ t(key: string): string;
67
+ on?(...args: Parameters<i18n['on']>): unknown;
68
+ off?(...args: Parameters<i18n['off']>): unknown;
69
+ createInstance?(options?: InitOptions): I18nWrapperInstance;
70
+ cloneInstance?(options?: CloneOptions): I18nWrapperInstance;
71
+ }
72
+ /** The instance a Modern app configures: i18next itself, or a wrapper of it. */
73
+ export type I18nRuntimeInstance = I18nInstance | I18nWrapperInstance;
57
74
  type LanguageDetectorOrder = string[];
58
75
  type LanguageDetectorCaches = boolean | string[];
59
76
  export interface LanguageDetectorOptions {
@@ -101,7 +118,7 @@ export type I18nInitOptions = {
101
118
  };
102
119
  forkResourceStore?: boolean;
103
120
  };
104
- export declare function isI18nInstance(obj: unknown): obj is I18nInstance;
105
- export declare function getI18nextInstanceForProvider(instance: I18nInstance, language?: string): I18nInstance;
106
- export declare function getI18nInstance(userInstance?: unknown): Promise<I18nInstance>;
121
+ export declare function isI18nInstance(obj: unknown): obj is I18nRuntimeInstance;
122
+ export declare function getI18nextInstanceForProvider(instance: I18nRuntimeInstance, language?: string): I18nInstance;
123
+ export declare function getI18nInstance(userInstance?: unknown): Promise<I18nRuntimeInstance>;
107
124
  export {};