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

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
@@ -39,9 +39,9 @@ const jsx_runtime_namespaceObject = require("react/jsx-runtime");
39
39
  const context_namespaceObject = require("@modern-js/runtime/context");
40
40
  const external_react_namespaceObject = require("react");
41
41
  const external_contextHelpers_js_namespaceObject = require("./contextHelpers.js");
42
+ const instance_js_namespaceObject = require("./i18n/instance.js");
42
43
  const external_routerAdapter_js_namespaceObject = require("./routerAdapter.js");
43
44
  const external_sharedContexts_js_namespaceObject = require("./sharedContexts.js");
44
- const instance_js_namespaceObject = require("./i18n/instance.js");
45
45
  const ModernI18nProvider = ({ children, i18nextProvider, value })=>{
46
46
  const content = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_sharedContexts_js_namespaceObject.ModernI18nContext.Provider, {
47
47
  value: value,
@@ -65,7 +65,7 @@ const FederatedI18nBoundary = (props)=>{
65
65
  ...props
66
66
  });
67
67
  };
68
- const useModernI18n = ()=>{
68
+ function useModernI18n() {
69
69
  const context = (0, external_react_namespaceObject.useContext)(external_sharedContexts_js_namespaceObject.ModernI18nContext);
70
70
  if (!context) throw new Error('useModernI18n must be used within ModernI18nProvider');
71
71
  const { language: contextLanguage, i18nInstance, languages, localePathRedirect, ignoreRedirectRoutes, urlStrategy, updateLanguage, synchronizeLanguage } = context;
@@ -103,7 +103,7 @@ const useModernI18n = ()=>{
103
103
  navigate,
104
104
  location
105
105
  ]);
106
- const t = (0, external_react_namespaceObject.useCallback)((key, ...args)=>(0, external_contextHelpers_js_namespaceObject.translateI18n)(i18nInstance, key, ...args), [
106
+ const t = (0, external_react_namespaceObject.useMemo)(()=>i18nInstance.t.bind(i18nInstance), [
107
107
  currentLanguage,
108
108
  i18nInstance
109
109
  ]);
@@ -118,13 +118,13 @@ const useModernI18n = ()=>{
118
118
  language: currentLanguage,
119
119
  changeLanguage,
120
120
  t,
121
- i18nInstance: i18nInstance,
121
+ i18nInstance,
122
122
  supportedLanguages: languages || [],
123
123
  urlStrategy,
124
124
  isLanguageSupported,
125
125
  isResourcesReady
126
126
  };
127
- };
127
+ }
128
128
  exports.FederatedI18nBoundary = __webpack_exports__.FederatedI18nBoundary;
129
129
  exports.ModernI18nContext = __webpack_exports__.ModernI18nContext;
130
130
  exports.ModernI18nProvider = __webpack_exports__.ModernI18nProvider;
@@ -33,8 +33,7 @@ __webpack_require__.d(__webpack_exports__, {
33
33
  changeModernI18nLanguage: ()=>changeModernI18nLanguage,
34
34
  getPathLanguage: ()=>getPathLanguage,
35
35
  isI18nLanguageSupported: ()=>isI18nLanguageSupported,
36
- isI18nResourcesReady: ()=>isI18nResourcesReady,
37
- translateI18n: ()=>translateI18n
36
+ isI18nResourcesReady: ()=>isI18nResourcesReady
38
37
  });
39
38
  const runtime_namespaceObject = require("@modern-js/runtime");
40
39
  const index_js_namespaceObject = require("./i18n/detection/index.js");
@@ -91,11 +90,6 @@ async function changeModernI18nLanguage(newLang, options) {
91
90
  throw error;
92
91
  }
93
92
  }
94
- function translateI18n(i18nInstance, key, ...args) {
95
- if ('function' != typeof i18nInstance.t) throw new Error('i18nInstance.t required');
96
- const translate = i18nInstance.t;
97
- return translate.call(i18nInstance, key, ...args);
98
- }
99
93
  function isI18nLanguageSupported(languages, lang) {
100
94
  return languages?.includes(lang) || false;
101
95
  }
@@ -129,15 +123,13 @@ exports.changeModernI18nLanguage = __webpack_exports__.changeModernI18nLanguage;
129
123
  exports.getPathLanguage = __webpack_exports__.getPathLanguage;
130
124
  exports.isI18nLanguageSupported = __webpack_exports__.isI18nLanguageSupported;
131
125
  exports.isI18nResourcesReady = __webpack_exports__.isI18nResourcesReady;
132
- exports.translateI18n = __webpack_exports__.translateI18n;
133
126
  for(var __rspack_i in __webpack_exports__)if (-1 === [
134
127
  "cacheI18nLanguage",
135
128
  "changeI18nInstanceLanguage",
136
129
  "changeModernI18nLanguage",
137
130
  "getPathLanguage",
138
131
  "isI18nLanguageSupported",
139
- "isI18nResourcesReady",
140
- "translateI18n"
132
+ "isI18nResourcesReady"
141
133
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
142
134
  Object.defineProperty(exports, '__esModule', {
143
135
  value: true
@@ -39,25 +39,10 @@ const external_contextHelpers_js_namespaceObject = require("./contextHelpers.js"
39
39
  const sdk_event_js_namespaceObject = require("./i18n/backend/sdk-event.js");
40
40
  const external_routerAdapter_js_namespaceObject = require("./routerAdapter.js");
41
41
  const external_utils_js_namespaceObject = require("./utils.js");
42
- function createMinimalI18nInstance(language) {
43
- const minimalInstance = {
44
- language,
45
- isInitialized: false,
46
- init: ()=>Promise.resolve(void 0),
47
- t: ()=>{
48
- throw new Error('i18nInstance.t required');
49
- },
50
- use: ()=>{},
51
- createInstance: ()=>minimalInstance,
52
- services: {}
53
- };
54
- return minimalInstance;
55
- }
56
42
  function createContextValue(lang, i18nInstance, entryName, languages, localePathRedirect, ignoreRedirectRoutes, setLang, urlStrategy) {
57
- const instance = i18nInstance || createMinimalI18nInstance(lang);
58
43
  return {
59
44
  language: lang,
60
- i18nInstance: instance,
45
+ i18nInstance,
61
46
  entryName,
62
47
  languages,
63
48
  localePathRedirect,
@@ -49,10 +49,9 @@ function convertBackendOptions(options) {
49
49
  if (converted.addPath) converted.addPath = convertPath(converted.addPath);
50
50
  return converted;
51
51
  }
52
- __webpack_require__.d(__webpack_exports__, {
53
- convertBackendOptions: ()=>convertBackendOptions
54
- }, {
55
- DEFAULT_I18NEXT_BACKEND_OPTIONS: DEFAULT_I18NEXT_BACKEND_OPTIONS
52
+ __webpack_require__.d(__webpack_exports__, {}, {
53
+ DEFAULT_I18NEXT_BACKEND_OPTIONS: DEFAULT_I18NEXT_BACKEND_OPTIONS,
54
+ convertBackendOptions: convertBackendOptions
56
55
  });
57
56
  exports.DEFAULT_I18NEXT_BACKEND_OPTIONS = __webpack_exports__.DEFAULT_I18NEXT_BACKEND_OPTIONS;
58
57
  exports.convertBackendOptions = __webpack_exports__.convertBackendOptions;
@@ -47,12 +47,11 @@ function getI18nSdkBackendId(target) {
47
47
  if (!target || 'object' != typeof target) return;
48
48
  return target[I18N_SDK_BACKEND_ID_KEY];
49
49
  }
50
- __webpack_require__.d(__webpack_exports__, {
51
- createI18nSdkBackendId: ()=>createI18nSdkBackendId,
52
- getI18nSdkBackendId: ()=>getI18nSdkBackendId,
53
- setI18nSdkBackendId: ()=>setI18nSdkBackendId
54
- }, {
55
- I18N_SDK_RESOURCES_LOADED_EVENT: I18N_SDK_RESOURCES_LOADED_EVENT
50
+ __webpack_require__.d(__webpack_exports__, {}, {
51
+ I18N_SDK_RESOURCES_LOADED_EVENT: I18N_SDK_RESOURCES_LOADED_EVENT,
52
+ createI18nSdkBackendId: createI18nSdkBackendId,
53
+ getI18nSdkBackendId: getI18nSdkBackendId,
54
+ setI18nSdkBackendId: setI18nSdkBackendId
56
55
  });
57
56
  exports.I18N_SDK_RESOURCES_LOADED_EVENT = __webpack_exports__.I18N_SDK_RESOURCES_LOADED_EVENT;
58
57
  exports.createI18nSdkBackendId = __webpack_exports__.createI18nSdkBackendId;
@@ -36,16 +36,8 @@ function isI18nWrapperInstance(obj) {
36
36
  if ('function' != typeof candidate.init || 'function' != typeof candidate.use) return false;
37
37
  return true;
38
38
  }
39
- function getI18nWrapperI18nextInstance(wrapperInstance) {
40
- if (isI18nWrapperInstance(wrapperInstance)) return wrapperInstance.i18nInstance?.instance;
41
- return null;
42
- }
43
39
  function getActualI18nextInstance(instance) {
44
- if (isI18nWrapperInstance(instance)) {
45
- const i18nextInstance = getI18nWrapperI18nextInstance(instance);
46
- return i18nextInstance || instance;
47
- }
48
- return instance;
40
+ return isI18nWrapperInstance(instance) ? instance.i18nInstance.instance : instance;
49
41
  }
50
42
  function isI18nInstance(obj) {
51
43
  if (!obj || 'object' != typeof obj) return false;
@@ -67,17 +59,13 @@ async function createI18nextInstance() {
67
59
  if (!i18next) return null;
68
60
  return i18next.createInstance?.({
69
61
  initImmediate: false
70
- });
62
+ }) ?? null;
71
63
  } catch (error) {
72
64
  return null;
73
65
  }
74
66
  }
75
67
  function getI18nextInstanceForProvider(instance, language) {
76
- let providerInstance = instance;
77
- if (isI18nWrapperInstance(instance)) {
78
- const i18nextInstance = getI18nWrapperI18nextInstance(instance);
79
- if (i18nextInstance) providerInstance = i18nextInstance;
80
- }
68
+ const providerInstance = getActualI18nextInstance(instance);
81
69
  if (!language || "u" < typeof Proxy) return providerInstance;
82
70
  return new Proxy(providerInstance, {
83
71
  get (target, property, receiver) {
@@ -105,19 +93,18 @@ function getI18nextInstanceForProvider(instance, language) {
105
93
  }
106
94
  async function getI18nInstance(userInstance) {
107
95
  if (userInstance) {
108
- if (isI18nWrapperInstance(userInstance)) return userInstance;
109
96
  if (isI18nInstance(userInstance)) return userInstance;
110
97
  }
111
98
  const i18nextInstance = await createI18nextInstance();
112
99
  if (i18nextInstance) return i18nextInstance;
113
100
  throw new Error('No i18n instance found');
114
101
  }
115
- __webpack_require__.d(__webpack_exports__, {
116
- getActualI18nextInstance: ()=>getActualI18nextInstance,
117
- getI18nInstance: ()=>getI18nInstance,
118
- getI18nextInstanceForProvider: ()=>getI18nextInstanceForProvider,
119
- isI18nInstance: ()=>isI18nInstance,
120
- isI18nWrapperInstance: ()=>isI18nWrapperInstance
102
+ __webpack_require__.d(__webpack_exports__, {}, {
103
+ getActualI18nextInstance: getActualI18nextInstance,
104
+ getI18nInstance: getI18nInstance,
105
+ getI18nextInstanceForProvider: getI18nextInstanceForProvider,
106
+ isI18nInstance: isI18nInstance,
107
+ isI18nWrapperInstance: isI18nWrapperInstance
121
108
  });
122
109
  exports.getActualI18nextInstance = __webpack_exports__.getActualI18nextInstance;
123
110
  exports.getI18nInstance = __webpack_exports__.getI18nInstance;
@@ -41,8 +41,8 @@ async function getReactI18nextIntegration() {
41
41
  initReactI18next: reactI18nextModule?.initReactI18next ?? null
42
42
  };
43
43
  }
44
- __webpack_require__.d(__webpack_exports__, {
45
- getReactI18nextIntegration: ()=>getReactI18nextIntegration
44
+ __webpack_require__.d(__webpack_exports__, {}, {
45
+ getReactI18nextIntegration: getReactI18nextIntegration
46
46
  });
47
47
  exports.getReactI18nextIntegration = __webpack_exports__.getReactI18nextIntegration;
48
48
  for(var __rspack_i in __webpack_exports__)if (-1 === [
@@ -42,7 +42,7 @@ const sdk_backend_js_namespaceObject = require("./backend/sdk-backend.js");
42
42
  const external_detection_index_js_namespaceObject = require("./detection/index.js");
43
43
  const external_instance_js_namespaceObject = require("./instance.js");
44
44
  function assertI18nInstance(obj) {
45
- if (!(0, external_instance_js_namespaceObject.isI18nInstance)(obj)) throw new Error('Object does not implement I18nInstance interface');
45
+ if (!(0, external_instance_js_namespaceObject.isI18nInstance)(obj)) throw new Error('Object does not implement I18nRuntimeInstance interface');
46
46
  }
47
47
  const buildInitOptions = async (finalLanguage, fallbackLanguage, languages, mergedDetection, mergedBackend, userInitOptions, useSuspense, i18nInstance)=>{
48
48
  const defaultUseSuspense = void 0 !== useSuspense ? useSuspense : (0, runtime_namespaceObject.isBrowser)() ? userInitOptions?.react?.useSuspense ?? true : false;
@@ -71,7 +71,7 @@ const createI18nRootWrapper = (options)=>(App)=>{
71
71
  ]);
72
72
  (0, external_hooks_js_namespaceObject.useSdkResourcesLoader)(i18nInstance, setForceUpdate);
73
73
  (0, external_hooks_js_namespaceObject.useClientSideRedirect)(i18nInstance, localePathRedirect, languages, fallbackLanguage, ignoreRedirectRoutes, urlStrategy);
74
- const contextValue = (0, external_react_namespaceObject.useMemo)(()=>(0, external_hooks_js_namespaceObject.createContextValue)(lang, i18nInstance, entryName, languages, localePathRedirect, ignoreRedirectRoutes, setLang, urlStrategy), [
74
+ const contextValue = (0, external_react_namespaceObject.useMemo)(()=>i18nInstance ? (0, external_hooks_js_namespaceObject.createContextValue)(lang, i18nInstance, entryName, languages, localePathRedirect, ignoreRedirectRoutes, setLang, urlStrategy) : void 0, [
75
75
  lang,
76
76
  i18nInstance,
77
77
  entryName,
@@ -109,14 +109,14 @@ const createI18nRootWrapper = (options)=>(App)=>{
109
109
  pathname: location?.pathname,
110
110
  prevLangRef: prevLangRef,
111
111
  setLang: setLang,
112
- children: (synchronizeLanguage)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_context_js_namespaceObject.ModernI18nProvider, {
112
+ children: (synchronizeLanguage)=>contextValue ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_context_js_namespaceObject.ModernI18nProvider, {
113
113
  i18nextProvider: I18nextProvider,
114
114
  value: {
115
115
  ...contextValue,
116
116
  synchronizeLanguage
117
117
  },
118
118
  children: appContent
119
- })
119
+ }) : appContent
120
120
  })
121
121
  ]
122
122
  });
@@ -46,8 +46,8 @@ function deepMerge(defaultOptions, userOptions) {
46
46
  }
47
47
  return merged;
48
48
  }
49
- __webpack_require__.d(__webpack_exports__, {
50
- deepMerge: ()=>deepMerge
49
+ __webpack_require__.d(__webpack_exports__, {}, {
50
+ deepMerge: deepMerge
51
51
  });
52
52
  exports.deepMerge = __webpack_exports__.deepMerge;
53
53
  for(var __rspack_i in __webpack_exports__)if (-1 === [
@@ -61,9 +61,9 @@ function getBackendOptions(entryName, backend) {
61
61
  if ('backendOptionsByEntry' in fullConfig) return removeEntryConfigKey(fullConfig, 'backendOptionsByEntry');
62
62
  return backend;
63
63
  }
64
- __webpack_require__.d(__webpack_exports__, {
65
- getBackendOptions: ()=>getBackendOptions,
66
- getLocaleDetectionOptions: ()=>getLocaleDetectionOptions
64
+ __webpack_require__.d(__webpack_exports__, {}, {
65
+ getBackendOptions: getBackendOptions,
66
+ getLocaleDetectionOptions: getLocaleDetectionOptions
67
67
  });
68
68
  exports.getBackendOptions = __webpack_exports__.getBackendOptions;
69
69
  exports.getLocaleDetectionOptions = __webpack_exports__.getLocaleDetectionOptions;
@@ -1,9 +1,9 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { RuntimeComponentResolverContext } from "@modern-js/runtime/context";
3
3
  import { useCallback, useContext, useEffect, useMemo } from "react";
4
- import { changeModernI18nLanguage, getPathLanguage, isI18nLanguageSupported, isI18nResourcesReady, translateI18n } from "./contextHelpers.mjs";
5
- import { useI18nRouterAdapter } from "./routerAdapter.mjs";
4
+ import { changeModernI18nLanguage, getPathLanguage, isI18nLanguageSupported, isI18nResourcesReady } from "./contextHelpers.mjs";
6
5
  import { ModernI18nContext, ReactI18nextProviderContext } from "./sharedContexts.mjs";
6
+ import { useI18nRouterAdapter } from "./routerAdapter.mjs";
7
7
  const ModernI18nProvider = ({ children, i18nextProvider, value })=>{
8
8
  const content = /*#__PURE__*/ jsx(ModernI18nContext.Provider, {
9
9
  value: value,
@@ -27,7 +27,7 @@ const FederatedI18nBoundary = (props)=>{
27
27
  ...props
28
28
  });
29
29
  };
30
- const useModernI18n = ()=>{
30
+ function useModernI18n() {
31
31
  const context = useContext(ModernI18nContext);
32
32
  if (!context) throw new Error('useModernI18n must be used within ModernI18nProvider');
33
33
  const { language: contextLanguage, i18nInstance, languages, localePathRedirect, ignoreRedirectRoutes, urlStrategy, updateLanguage, synchronizeLanguage } = context;
@@ -65,7 +65,7 @@ const useModernI18n = ()=>{
65
65
  navigate,
66
66
  location
67
67
  ]);
68
- const t = useCallback((key, ...args)=>translateI18n(i18nInstance, key, ...args), [
68
+ const t = useMemo(()=>i18nInstance.t.bind(i18nInstance), [
69
69
  currentLanguage,
70
70
  i18nInstance
71
71
  ]);
@@ -80,12 +80,12 @@ const useModernI18n = ()=>{
80
80
  language: currentLanguage,
81
81
  changeLanguage,
82
82
  t,
83
- i18nInstance: i18nInstance,
83
+ i18nInstance,
84
84
  supportedLanguages: languages || [],
85
85
  urlStrategy,
86
86
  isLanguageSupported,
87
87
  isResourcesReady
88
88
  };
89
- };
89
+ }
90
90
  export { getActualI18nextInstance } from "./i18n/instance.mjs";
91
91
  export { FederatedI18nBoundary, ModernI18nContext, ModernI18nProvider, ReactI18nextProviderContext, useModernI18n };
@@ -53,11 +53,6 @@ async function changeModernI18nLanguage(newLang, options) {
53
53
  throw error;
54
54
  }
55
55
  }
56
- function translateI18n(i18nInstance, key, ...args) {
57
- if ('function' != typeof i18nInstance.t) throw new Error('i18nInstance.t required');
58
- const translate = i18nInstance.t;
59
- return translate.call(i18nInstance, key, ...args);
60
- }
61
56
  function isI18nLanguageSupported(languages, lang) {
62
57
  return languages?.includes(lang) || false;
63
58
  }
@@ -85,4 +80,4 @@ function isI18nResourcesReady(i18nInstance, currentLanguage) {
85
80
  return nsData && 'object' == typeof nsData && Object.keys(nsData).length > 0;
86
81
  });
87
82
  }
88
- export { cacheI18nLanguage, changeI18nInstanceLanguage, changeModernI18nLanguage, getPathLanguage, isI18nLanguageSupported, isI18nResourcesReady, translateI18n };
83
+ export { cacheI18nLanguage, changeI18nInstanceLanguage, changeModernI18nLanguage, getPathLanguage, isI18nLanguageSupported, isI18nResourcesReady };
@@ -4,25 +4,10 @@ import { cacheI18nLanguage, changeI18nInstanceLanguage } from "./contextHelpers.
4
4
  import { I18N_SDK_RESOURCES_LOADED_EVENT, getI18nSdkBackendId } from "./i18n/backend/sdk-event.mjs";
5
5
  import { useI18nRouterAdapter } from "./routerAdapter.mjs";
6
6
  import { buildLocalizedUrl, detectLanguageFromPath, getEntryPath, shouldIgnoreRedirect } from "./utils.mjs";
7
- function createMinimalI18nInstance(language) {
8
- const minimalInstance = {
9
- language,
10
- isInitialized: false,
11
- init: ()=>Promise.resolve(void 0),
12
- t: ()=>{
13
- throw new Error('i18nInstance.t required');
14
- },
15
- use: ()=>{},
16
- createInstance: ()=>minimalInstance,
17
- services: {}
18
- };
19
- return minimalInstance;
20
- }
21
7
  function createContextValue(lang, i18nInstance, entryName, languages, localePathRedirect, ignoreRedirectRoutes, setLang, urlStrategy) {
22
- const instance = i18nInstance || createMinimalI18nInstance(lang);
23
8
  return {
24
9
  language: lang,
25
- i18nInstance: instance,
10
+ i18nInstance,
26
11
  entryName,
27
12
  languages,
28
13
  localePathRedirect,
@@ -7,16 +7,8 @@ function isI18nWrapperInstance(obj) {
7
7
  if ('function' != typeof candidate.init || 'function' != typeof candidate.use) return false;
8
8
  return true;
9
9
  }
10
- function getI18nWrapperI18nextInstance(wrapperInstance) {
11
- if (isI18nWrapperInstance(wrapperInstance)) return wrapperInstance.i18nInstance?.instance;
12
- return null;
13
- }
14
10
  function getActualI18nextInstance(instance) {
15
- if (isI18nWrapperInstance(instance)) {
16
- const i18nextInstance = getI18nWrapperI18nextInstance(instance);
17
- return i18nextInstance || instance;
18
- }
19
- return instance;
11
+ return isI18nWrapperInstance(instance) ? instance.i18nInstance.instance : instance;
20
12
  }
21
13
  function isI18nInstance(obj) {
22
14
  if (!obj || 'object' != typeof obj) return false;
@@ -38,17 +30,13 @@ async function createI18nextInstance() {
38
30
  if (!i18next) return null;
39
31
  return i18next.createInstance?.({
40
32
  initImmediate: false
41
- });
33
+ }) ?? null;
42
34
  } catch (error) {
43
35
  return null;
44
36
  }
45
37
  }
46
38
  function getI18nextInstanceForProvider(instance, language) {
47
- let providerInstance = instance;
48
- if (isI18nWrapperInstance(instance)) {
49
- const i18nextInstance = getI18nWrapperI18nextInstance(instance);
50
- if (i18nextInstance) providerInstance = i18nextInstance;
51
- }
39
+ const providerInstance = getActualI18nextInstance(instance);
52
40
  if (!language || "u" < typeof Proxy) return providerInstance;
53
41
  return new Proxy(providerInstance, {
54
42
  get (target, property, receiver) {
@@ -76,7 +64,6 @@ function getI18nextInstanceForProvider(instance, language) {
76
64
  }
77
65
  async function getI18nInstance(userInstance) {
78
66
  if (userInstance) {
79
- if (isI18nWrapperInstance(userInstance)) return userInstance;
80
67
  if (isI18nInstance(userInstance)) return userInstance;
81
68
  }
82
69
  const i18nextInstance = await createI18nextInstance();
@@ -5,7 +5,7 @@ import { SdkBackend } from "./backend/sdk-backend.mjs";
5
5
  import { cacheUserLanguage, mergeDetectionOptions } from "./detection/index.mjs";
6
6
  import { getActualI18nextInstance, isI18nInstance, isI18nWrapperInstance } from "./instance.mjs";
7
7
  function assertI18nInstance(obj) {
8
- if (!isI18nInstance(obj)) throw new Error('Object does not implement I18nInstance interface');
8
+ if (!isI18nInstance(obj)) throw new Error('Object does not implement I18nRuntimeInstance interface');
9
9
  }
10
10
  const buildInitOptions = async (finalLanguage, fallbackLanguage, languages, mergedDetection, mergedBackend, userInitOptions, useSuspense, i18nInstance)=>{
11
11
  const defaultUseSuspense = void 0 !== useSuspense ? useSuspense : isBrowser() ? userInitOptions?.react?.useSuspense ?? true : false;
@@ -1,6 +1,6 @@
1
1
  import { createI18nRouterNavigation } from "@modern-js/i18n-runtime-extensions/router-navigation";
2
2
  import { I18nNavigationProvider, useNativeI18nRouterAdapter } from "./routerAdapter.mjs";
3
- const { I18nRouterNavigationProvider: I18nRouterNavigationProvider, useIntegratedRouterAdapter: useIntegratedRouterAdapter } = createI18nRouterNavigation({
3
+ const { I18nRouterNavigationProvider, useIntegratedRouterAdapter } = createI18nRouterNavigation({
4
4
  I18nNavigationProvider: I18nNavigationProvider,
5
5
  useNativeI18nRouterAdapter: useNativeI18nRouterAdapter
6
6
  });
@@ -39,7 +39,7 @@ const createI18nRootWrapper = (options)=>(App)=>{
39
39
  ]);
40
40
  useSdkResourcesLoader(i18nInstance, setForceUpdate);
41
41
  useClientSideRedirect(i18nInstance, localePathRedirect, languages, fallbackLanguage, ignoreRedirectRoutes, urlStrategy);
42
- const contextValue = useMemo(()=>createContextValue(lang, i18nInstance, entryName, languages, localePathRedirect, ignoreRedirectRoutes, setLang, urlStrategy), [
42
+ const contextValue = useMemo(()=>i18nInstance ? createContextValue(lang, i18nInstance, entryName, languages, localePathRedirect, ignoreRedirectRoutes, setLang, urlStrategy) : void 0, [
43
43
  lang,
44
44
  i18nInstance,
45
45
  entryName,
@@ -77,14 +77,14 @@ const createI18nRootWrapper = (options)=>(App)=>{
77
77
  pathname: location?.pathname,
78
78
  prevLangRef: prevLangRef,
79
79
  setLang: setLang,
80
- children: (synchronizeLanguage)=>/*#__PURE__*/ jsx(ModernI18nProvider, {
80
+ children: (synchronizeLanguage)=>contextValue ? /*#__PURE__*/ jsx(ModernI18nProvider, {
81
81
  i18nextProvider: I18nextProvider,
82
82
  value: {
83
83
  ...contextValue,
84
84
  synchronizeLanguage
85
85
  },
86
86
  children: appContent
87
- })
87
+ }) : appContent
88
88
  })
89
89
  ]
90
90
  });
@@ -5,7 +5,7 @@ import { resolveDefaultUrlStrategy } from "./defaultUrlStrategy.mjs";
5
5
  import { convertToHonoLanguageDetectorOptions } from "./detectorOptions.mjs";
6
6
  import { buildLocalizedUrl, createLocaleRedirectResponse, getLanguageFromPath, isStaticResourceRequest, shouldIgnoreRedirect } from "./redirectPolicy.mjs";
7
7
  import * as __rspack_external__modern_js_server_core_hono_0af3baa7 from "@modern-js/server-core/hono";
8
- const { languageDetector: languageDetector } = __rspack_external__modern_js_server_core_hono_0af3baa7;
8
+ const { languageDetector } = __rspack_external__modern_js_server_core_hono_0af3baa7;
9
9
  const i18nServerPlugin = (options)=>({
10
10
  name: '@modern-js/plugin-i18n/server',
11
11
  setup: (api)=>{
@@ -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
  });