@bleedingdev/modern-js-plugin-i18n 3.11.3-ultramodern.1 → 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 (64) hide show
  1. package/dist/cjs/runtime/context.js +5 -5
  2. package/dist/cjs/runtime/contextHelpers.js +2 -10
  3. package/dist/cjs/runtime/hooks.js +1 -16
  4. package/dist/cjs/runtime/i18n/backend/defaults.js +3 -4
  5. package/dist/cjs/runtime/i18n/backend/sdk-event.js +5 -6
  6. package/dist/cjs/runtime/i18n/instance.js +9 -22
  7. package/dist/cjs/runtime/i18n/react-i18next.js +2 -2
  8. package/dist/cjs/runtime/i18n/utils.js +1 -1
  9. package/dist/cjs/runtime/providerComposition.js +3 -3
  10. package/dist/cjs/shared/deepMerge.js +2 -2
  11. package/dist/cjs/shared/utils.js +3 -3
  12. package/dist/esm/runtime/context.mjs +6 -6
  13. package/dist/esm/runtime/contextHelpers.mjs +1 -6
  14. package/dist/esm/runtime/hooks.mjs +1 -16
  15. package/dist/esm/runtime/i18n/instance.mjs +3 -16
  16. package/dist/esm/runtime/i18n/utils.mjs +1 -1
  17. package/dist/esm/runtime/navigation.mjs +1 -1
  18. package/dist/esm/runtime/providerComposition.mjs +3 -3
  19. package/dist/esm/server/index.mjs +1 -1
  20. package/dist/esm-node/runtime/context.mjs +6 -6
  21. package/dist/esm-node/runtime/contextHelpers.mjs +1 -6
  22. package/dist/esm-node/runtime/hooks.mjs +1 -16
  23. package/dist/esm-node/runtime/i18n/instance.mjs +3 -16
  24. package/dist/esm-node/runtime/i18n/utils.mjs +1 -1
  25. package/dist/esm-node/runtime/navigation.mjs +1 -1
  26. package/dist/esm-node/runtime/providerComposition.mjs +3 -3
  27. package/dist/esm-node/server/index.mjs +1 -1
  28. package/dist/types/runtime/context.d.ts +16 -14
  29. package/dist/types/runtime/contextHelpers.d.ts +5 -6
  30. package/dist/types/runtime/core.d.ts +3 -3
  31. package/dist/types/runtime/hooks.d.ts +6 -6
  32. package/dist/types/runtime/i18n/backend/middleware.common.d.ts +2 -2
  33. package/dist/types/runtime/i18n/backend/middleware.d.ts +2 -2
  34. package/dist/types/runtime/i18n/backend/middleware.node.d.ts +2 -2
  35. package/dist/types/runtime/i18n/detection/cache.d.ts +5 -5
  36. package/dist/types/runtime/i18n/detection/detector.d.ts +2 -2
  37. package/dist/types/runtime/i18n/detection/middleware.d.ts +4 -4
  38. package/dist/types/runtime/i18n/detection/middleware.node.d.ts +4 -4
  39. package/dist/types/runtime/i18n/detection/priority.d.ts +2 -2
  40. package/dist/types/runtime/i18n/index.d.ts +1 -1
  41. package/dist/types/runtime/i18n/instance.d.ts +28 -11
  42. package/dist/types/runtime/i18n/utils.d.ts +7 -7
  43. package/dist/types/runtime/pluginSetup.d.ts +4 -4
  44. package/dist/types/runtime/providerComposition.d.ts +3 -3
  45. package/dist/types/runtime/types.d.ts +3 -3
  46. package/package.json +24 -23
  47. package/src/runtime/context.tsx +26 -24
  48. package/src/runtime/contextHelpers.ts +5 -26
  49. package/src/runtime/core.tsx +5 -3
  50. package/src/runtime/hooks.ts +7 -27
  51. package/src/runtime/i18n/backend/middleware.common.ts +3 -3
  52. package/src/runtime/i18n/backend/middleware.node.ts +2 -2
  53. package/src/runtime/i18n/backend/middleware.ts +2 -2
  54. package/src/runtime/i18n/detection/cache.ts +8 -8
  55. package/src/runtime/i18n/detection/detector.ts +5 -5
  56. package/src/runtime/i18n/detection/middleware.node.ts +7 -5
  57. package/src/runtime/i18n/detection/middleware.ts +6 -4
  58. package/src/runtime/i18n/detection/priority.ts +2 -2
  59. package/src/runtime/i18n/index.ts +2 -0
  60. package/src/runtime/i18n/instance.ts +50 -49
  61. package/src/runtime/i18n/utils.ts +14 -10
  62. package/src/runtime/pluginSetup.ts +4 -4
  63. package/src/runtime/providerComposition.tsx +31 -21
  64. package/src/runtime/types.ts +3 -3
@@ -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 {};
@@ -1,5 +1,5 @@
1
1
  import type { BaseBackendOptions } from '../../shared/type.js';
2
- import type { I18nInitOptions, I18nInstance } from './instance.js';
2
+ import type { I18nInitOptions, I18nRuntimeInstance } from './instance.js';
3
3
  type MergedBackendOptions = NonNullable<I18nInitOptions['backend']> & {
4
4
  _useChainedBackend?: boolean;
5
5
  _chainedBackendConfig?: {
@@ -8,15 +8,15 @@ type MergedBackendOptions = NonNullable<I18nInitOptions['backend']> & {
8
8
  backends?: unknown[];
9
9
  backendOptions?: unknown;
10
10
  };
11
- export declare function assertI18nInstance(obj: unknown): asserts obj is I18nInstance;
11
+ export declare function assertI18nInstance(obj: unknown): asserts obj is I18nRuntimeInstance;
12
12
  /**
13
13
  * Build initialization options for i18n instance
14
14
  */
15
- export declare const buildInitOptions: (finalLanguage: string, fallbackLanguage: string, languages: string[], mergedDetection: I18nInitOptions['detection'], mergedBackend: MergedBackendOptions | undefined, userInitOptions?: I18nInitOptions, useSuspense?: boolean, i18nInstance?: I18nInstance) => Promise<I18nInitOptions>;
15
+ export declare const buildInitOptions: (finalLanguage: string, fallbackLanguage: string, languages: string[], mergedDetection: I18nInitOptions['detection'], mergedBackend: MergedBackendOptions | undefined, userInitOptions?: I18nInitOptions, useSuspense?: boolean, i18nInstance?: I18nRuntimeInstance) => Promise<I18nInitOptions>;
16
16
  /**
17
17
  * Ensure i18n instance language matches the final detected language
18
18
  */
19
- export declare const ensureLanguageMatch: (i18nInstance: I18nInstance, finalLanguage: string) => Promise<void>;
19
+ export declare const ensureLanguageMatch: (i18nInstance: I18nRuntimeInstance, finalLanguage: string) => Promise<void>;
20
20
  /**
21
21
  * Change language for i18n instance in onBeforeRender hook
22
22
  * This function can be used by other runtime plugins to change language
@@ -24,15 +24,15 @@ export declare const ensureLanguageMatch: (i18nInstance: I18nInstance, finalLang
24
24
  * @param newLang - The new language code to switch to
25
25
  * @param options - Optional configuration
26
26
  */
27
- export declare const changeI18nLanguage: (i18nInstance: I18nInstance, newLang: string, options?: {
27
+ export declare const changeI18nLanguage: (i18nInstance: I18nRuntimeInstance, newLang: string, options?: {
28
28
  detectionOptions?: I18nInitOptions['detection'];
29
29
  }) => Promise<void>;
30
30
  /**
31
31
  * Initialize i18n instance if not already initialized
32
32
  */
33
- export declare const initializeI18nInstance: (i18nInstance: I18nInstance, finalLanguage: string, fallbackLanguage: string, languages: string[], mergedDetection: I18nInitOptions['detection'], mergedBackend: MergedBackendOptions | undefined, userInitOptions?: I18nInitOptions, useSuspense?: boolean) => Promise<void>;
33
+ export declare const initializeI18nInstance: (i18nInstance: I18nRuntimeInstance, finalLanguage: string, fallbackLanguage: string, languages: string[], mergedDetection: I18nInitOptions['detection'], mergedBackend: MergedBackendOptions | undefined, userInitOptions?: I18nInitOptions, useSuspense?: boolean) => Promise<void>;
34
34
  /**
35
35
  * Setup cloned instance for SSR with backend support
36
36
  */
37
- export declare const setupClonedInstance: (i18nInstance: I18nInstance, finalLanguage: string, fallbackLanguage: string, languages: string[], backendEnabled: boolean, backend: BaseBackendOptions | undefined, i18nextDetector: boolean, detection: I18nInitOptions['detection'], localePathRedirect: boolean, userInitOptions: I18nInitOptions | undefined) => Promise<void>;
37
+ export declare const setupClonedInstance: (i18nInstance: I18nRuntimeInstance, finalLanguage: string, fallbackLanguage: string, languages: string[], backendEnabled: boolean, backend: BaseBackendOptions | undefined, i18nextDetector: boolean, detection: I18nInitOptions['detection'], localePathRedirect: boolean, userInitOptions: I18nInitOptions | undefined) => Promise<void>;
38
38
  export {};
@@ -1,6 +1,6 @@
1
1
  import type { TInternalRuntimeContext } from '@modern-js/runtime/internal';
2
2
  import type { BaseBackendOptions, BaseLocaleDetectionOptions } from '../shared/type.js';
3
- import type { I18nInitOptions, I18nInstance } from './i18n/index.js';
3
+ import type { I18nInitOptions, I18nRuntimeInstance } from './i18n/index.js';
4
4
  import type { ReactI18nextIntegration } from './reactI18next.js';
5
5
  interface RuntimeConfigWithI18n {
6
6
  i18n?: {
@@ -11,12 +11,12 @@ interface I18nRuntimeApi {
11
11
  getRuntimeConfig: () => RuntimeConfigWithI18n;
12
12
  }
13
13
  export interface RuntimeContextWithI18n extends TInternalRuntimeContext {
14
- i18nInstance?: I18nInstance;
14
+ i18nInstance?: I18nRuntimeInstance;
15
15
  changeLanguage?: (lang: string) => Promise<void>;
16
16
  }
17
17
  interface SetupI18nBeforeRenderOptions {
18
18
  api: I18nRuntimeApi;
19
- userI18nInstance?: I18nInstance;
19
+ userI18nInstance?: I18nRuntimeInstance;
20
20
  initOptions?: I18nInitOptions;
21
21
  backend?: BaseBackendOptions;
22
22
  backendEnabled: boolean;
@@ -28,5 +28,5 @@ interface SetupI18nBeforeRenderOptions {
28
28
  resolveReactI18nextIntegration: () => Promise<ReactI18nextIntegration | null>;
29
29
  setI18nextProvider: (provider: ReactI18nextIntegration['I18nextProvider']) => void;
30
30
  }
31
- export declare function setupI18nBeforeRender(context: RuntimeContextWithI18n, options: SetupI18nBeforeRenderOptions): Promise<I18nInstance>;
31
+ export declare function setupI18nBeforeRender(context: RuntimeContextWithI18n, options: SetupI18nBeforeRenderOptions): Promise<I18nRuntimeInstance>;
32
32
  export {};
@@ -1,9 +1,9 @@
1
1
  import type React from 'react';
2
2
  import type { BaseLocaleDetectionOptions } from '../shared/type.js';
3
3
  import type { I18nUrlStrategy } from '../shared/urlStrategy.js';
4
- import type { I18nInstance } from './i18n/index.js';
4
+ import type { I18nRuntimeInstance } from './i18n/index.js';
5
5
  export interface I18nLanguageSynchronizationProps {
6
- i18nInstance: I18nInstance | undefined;
6
+ i18nInstance: I18nRuntimeInstance | undefined;
7
7
  localePathRedirect: boolean;
8
8
  languages: string[];
9
9
  pathname: string | undefined;
@@ -21,7 +21,7 @@ interface I18nRootWrapperOptions {
21
21
  urlStrategy?: I18nUrlStrategy;
22
22
  NavigationProvider?: React.ComponentType<React.PropsWithChildren>;
23
23
  LanguageSynchronization?: React.ComponentType<I18nLanguageSynchronizationProps>;
24
- getLatestI18nInstance: () => I18nInstance | undefined;
24
+ getLatestI18nInstance: () => I18nRuntimeInstance | undefined;
25
25
  getI18nextProvider: () => React.ComponentType<any> | null | undefined;
26
26
  }
27
27
  export declare const createI18nRootWrapper: (options: I18nRootWrapperOptions) => (App: React.ComponentType<any>) => (props: Record<string, unknown>) => React.JSX.Element;
@@ -1,15 +1,15 @@
1
- import type { I18nInitOptions, I18nInstance } from './i18n/index.js';
1
+ import type { I18nInitOptions, I18nRuntimeInstance } from './i18n/index.js';
2
2
  declare module '@modern-js/runtime' {
3
3
  interface RuntimeConfig {
4
4
  i18n?: {
5
- i18nInstance?: I18nInstance;
5
+ i18nInstance?: I18nRuntimeInstance;
6
6
  changeLanguage?: (lang: string) => void;
7
7
  setLang?: (lang: string) => void;
8
8
  initOptions?: I18nInitOptions;
9
9
  };
10
10
  }
11
11
  interface TRuntimeContext {
12
- i18nInstance?: I18nInstance;
12
+ i18nInstance?: I18nRuntimeInstance;
13
13
  changeLanguage?: (lang: string) => Promise<void>;
14
14
  }
15
15
  }
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "modern",
18
18
  "modern.js"
19
19
  ],
20
- "version": "3.11.3-ultramodern.1",
20
+ "version": "3.11.3-ultramodern.10",
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.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
- "@swc/helpers": "^0.5.23",
143
- "i18next-browser-languagedetector": "^8.3.0",
144
- "i18next-chained-backend": "^5.0.6",
145
- "i18next-fs-backend": "^2.6.9",
146
- "i18next-http-backend": "^4.0.9",
147
- "i18next-http-middleware": "^3.10.0"
135
+ "@modern-js/i18n-runtime-extensions": "npm:@bleedingdev/modern-js-i18n-runtime-extensions@3.11.3-ultramodern.10",
136
+ "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.11.3-ultramodern.10",
137
+ "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.11.3-ultramodern.10",
138
+ "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.11.3-ultramodern.10",
139
+ "@modern-js/server-runtime": "npm:@bleedingdev/modern-js-server-runtime@3.11.3-ultramodern.10",
140
+ "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.11.3-ultramodern.10",
141
+ "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.11.3-ultramodern.10",
142
+ "@swc/helpers": "^0.5.24",
143
+ "i18next-browser-languagedetector": "^8.3.1",
144
+ "i18next-chained-backend": "^5.0.8",
145
+ "i18next-fs-backend": "^2.6.12",
146
+ "i18next-http-backend": "^4.0.10",
147
+ "i18next-http-middleware": "^3.10.3"
148
148
  },
149
149
  "peerDependencies": {
150
- "@modern-js/runtime": "3.11.3-ultramodern.1",
150
+ "@modern-js/runtime": "3.11.3-ultramodern.10",
151
151
  "i18next": ">=25.10.10",
152
152
  "react": "^19.3.1",
153
153
  "react-dom": "^19.3.1",
@@ -162,17 +162,17 @@
162
162
  }
163
163
  },
164
164
  "devDependencies": {
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
- "@rslib/core": "1.0.3",
165
+ "@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.11.3-ultramodern.10",
166
+ "@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.11.3-ultramodern.10",
167
+ "@modern-js/runtime-extensions": "npm:@bleedingdev/modern-js-runtime-extensions@3.11.3-ultramodern.10",
168
+ "@rslib/core": "1.0.7",
169
169
  "@scripts/rstest-config": "2.66.7",
170
- "@types/node": "^26.6.5",
170
+ "@types/node": "^26.6.6",
171
171
  "esbuild": "^0.28.2",
172
- "i18next": "26.4.6",
172
+ "i18next": "27.1.5",
173
173
  "react": "^19.3.1",
174
174
  "react-dom": "^19.3.1",
175
- "react-i18next": "17.0.18",
175
+ "react-i18next": "18.0.2",
176
176
  "ts-node": "^10.9.2",
177
177
  "typescript": "7.0.2"
178
178
  },
@@ -187,7 +187,8 @@
187
187
  "scripts": {
188
188
  "dev": "rslib build --watch",
189
189
  "build": "rslib build",
190
- "test": "rstest"
190
+ "test": "rstest",
191
+ "test:types": "node ../../../scripts/with-effect-tsrs.mjs --project tests/types/tsconfig.json && node ../../../scripts/with-effect-tsrs.mjs --project tests/types/selector/tsconfig.json"
191
192
  },
192
193
  "ultramodern": {
193
194
  "sourceName": "@modern-js/plugin-i18n"