@bleedingdev/modern-js-plugin-i18n 3.5.0-ultramodern.4 → 3.5.0-ultramodern.41

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 (214) hide show
  1. package/dist/cjs/cli/index.js +2 -1
  2. package/dist/cjs/cli/locales.js +15 -15
  3. package/dist/cjs/runtime/Link.js +8 -89
  4. package/dist/cjs/runtime/context.js +18 -82
  5. package/dist/cjs/runtime/contextHelpers.js +137 -0
  6. package/dist/cjs/runtime/core.js +29 -132
  7. package/dist/cjs/runtime/i18n/backend/defaults.node.js +7 -7
  8. package/dist/cjs/runtime/i18n/detection/cache.js +150 -0
  9. package/dist/cjs/runtime/i18n/detection/detector.js +100 -0
  10. package/dist/cjs/runtime/i18n/detection/index.js +8 -263
  11. package/dist/cjs/runtime/i18n/detection/initOptions.js +69 -0
  12. package/dist/cjs/runtime/i18n/detection/language.js +62 -0
  13. package/dist/cjs/runtime/i18n/detection/path.js +49 -0
  14. package/dist/cjs/runtime/i18n/detection/priority.js +66 -0
  15. package/dist/cjs/runtime/i18n/detection/ssr.js +70 -0
  16. package/dist/cjs/runtime/i18n/detection/types.js +18 -0
  17. package/dist/cjs/runtime/i18n/instance.js +7 -7
  18. package/dist/cjs/runtime/linkHelpers.js +148 -0
  19. package/dist/cjs/runtime/pluginSetup.js +102 -0
  20. package/dist/cjs/runtime/providerComposition.js +114 -0
  21. package/dist/cjs/runtime/reactI18next.js +43 -0
  22. package/dist/cjs/runtime/utils.js +1 -9
  23. package/dist/cjs/server/apiPrefix.js +72 -0
  24. package/dist/cjs/server/detectorOptions.js +97 -0
  25. package/dist/cjs/server/index.js +17 -144
  26. package/dist/cjs/server/redirectPolicy.js +96 -0
  27. package/dist/cjs/shared/detection.js +2 -104
  28. package/dist/cjs/shared/localisedUrls/config.js +49 -0
  29. package/dist/cjs/shared/localisedUrls/index.js +91 -0
  30. package/dist/cjs/shared/localisedUrls/normalise.js +87 -0
  31. package/dist/cjs/shared/localisedUrls/pathname.js +68 -0
  32. package/dist/cjs/shared/localisedUrls/patterns.js +130 -0
  33. package/dist/cjs/shared/localisedUrls/redirect.js +95 -0
  34. package/dist/cjs/shared/localisedUrls/resolve.js +88 -0
  35. package/dist/cjs/shared/localisedUrls/routes.js +129 -0
  36. package/dist/cjs/shared/localisedUrls/types.js +18 -0
  37. package/dist/cjs/shared/localisedUrls.js +28 -294
  38. package/dist/cjs/shared/utils.js +2 -8
  39. package/dist/esm/cli/index.mjs +2 -1
  40. package/dist/esm/cli/locales.mjs +13 -13
  41. package/dist/esm/runtime/Link.mjs +1 -82
  42. package/dist/esm/runtime/context.mjs +18 -82
  43. package/dist/esm/runtime/contextHelpers.mjs +84 -0
  44. package/dist/esm/runtime/core.mjs +30 -133
  45. package/dist/esm/runtime/i18n/backend/defaults.node.mjs +5 -5
  46. package/dist/esm/runtime/i18n/detection/cache.mjs +103 -0
  47. package/dist/esm/runtime/i18n/detection/detector.mjs +62 -0
  48. package/dist/esm/runtime/i18n/detection/index.mjs +4 -260
  49. package/dist/esm/runtime/i18n/detection/initOptions.mjs +28 -0
  50. package/dist/esm/runtime/i18n/detection/language.mjs +21 -0
  51. package/dist/esm/runtime/i18n/detection/path.mjs +11 -0
  52. package/dist/esm/runtime/i18n/detection/priority.mjs +28 -0
  53. package/dist/esm/runtime/i18n/detection/ssr.mjs +26 -0
  54. package/dist/esm/runtime/i18n/detection/types.mjs +0 -0
  55. package/dist/esm/runtime/i18n/instance.mjs +8 -5
  56. package/dist/esm/runtime/linkHelpers.mjs +98 -0
  57. package/dist/esm/runtime/pluginSetup.mjs +64 -0
  58. package/dist/esm/runtime/providerComposition.mjs +76 -0
  59. package/dist/esm/runtime/reactI18next.mjs +5 -0
  60. package/dist/esm/runtime/utils.mjs +2 -10
  61. package/dist/esm/server/apiPrefix.mjs +31 -0
  62. package/dist/esm/server/detectorOptions.mjs +59 -0
  63. package/dist/esm/server/index.mjs +8 -135
  64. package/dist/esm/server/redirectPolicy.mjs +46 -0
  65. package/dist/esm/shared/detection.mjs +1 -71
  66. package/dist/esm/shared/localisedUrls/config.mjs +11 -0
  67. package/dist/esm/shared/localisedUrls/index.mjs +7 -0
  68. package/dist/esm/shared/localisedUrls/normalise.mjs +37 -0
  69. package/dist/esm/shared/localisedUrls/pathname.mjs +24 -0
  70. package/dist/esm/shared/localisedUrls/patterns.mjs +86 -0
  71. package/dist/esm/shared/localisedUrls/redirect.mjs +48 -0
  72. package/dist/esm/shared/localisedUrls/resolve.mjs +47 -0
  73. package/dist/esm/shared/localisedUrls/routes.mjs +88 -0
  74. package/dist/esm/shared/localisedUrls/types.mjs +0 -0
  75. package/dist/esm/shared/localisedUrls.mjs +1 -283
  76. package/dist/esm/shared/utils.mjs +1 -1
  77. package/dist/esm-node/cli/index.mjs +2 -1
  78. package/dist/esm-node/cli/locales.mjs +13 -13
  79. package/dist/esm-node/runtime/Link.mjs +1 -82
  80. package/dist/esm-node/runtime/context.mjs +18 -82
  81. package/dist/esm-node/runtime/contextHelpers.mjs +85 -0
  82. package/dist/esm-node/runtime/core.mjs +30 -133
  83. package/dist/esm-node/runtime/i18n/backend/defaults.node.mjs +5 -5
  84. package/dist/esm-node/runtime/i18n/detection/cache.mjs +104 -0
  85. package/dist/esm-node/runtime/i18n/detection/detector.mjs +63 -0
  86. package/dist/esm-node/runtime/i18n/detection/index.mjs +4 -260
  87. package/dist/esm-node/runtime/i18n/detection/initOptions.mjs +29 -0
  88. package/dist/esm-node/runtime/i18n/detection/language.mjs +22 -0
  89. package/dist/esm-node/runtime/i18n/detection/path.mjs +12 -0
  90. package/dist/esm-node/runtime/i18n/detection/priority.mjs +29 -0
  91. package/dist/esm-node/runtime/i18n/detection/ssr.mjs +27 -0
  92. package/dist/esm-node/runtime/i18n/detection/types.mjs +1 -0
  93. package/dist/esm-node/runtime/i18n/instance.mjs +8 -5
  94. package/dist/esm-node/runtime/linkHelpers.mjs +99 -0
  95. package/dist/esm-node/runtime/pluginSetup.mjs +65 -0
  96. package/dist/esm-node/runtime/providerComposition.mjs +77 -0
  97. package/dist/esm-node/runtime/reactI18next.mjs +6 -0
  98. package/dist/esm-node/runtime/utils.mjs +2 -10
  99. package/dist/esm-node/server/apiPrefix.mjs +32 -0
  100. package/dist/esm-node/server/detectorOptions.mjs +60 -0
  101. package/dist/esm-node/server/index.mjs +8 -135
  102. package/dist/esm-node/server/redirectPolicy.mjs +47 -0
  103. package/dist/esm-node/shared/detection.mjs +1 -71
  104. package/dist/esm-node/shared/localisedUrls/config.mjs +12 -0
  105. package/dist/esm-node/shared/localisedUrls/index.mjs +8 -0
  106. package/dist/esm-node/shared/localisedUrls/normalise.mjs +38 -0
  107. package/dist/esm-node/shared/localisedUrls/pathname.mjs +25 -0
  108. package/dist/esm-node/shared/localisedUrls/patterns.mjs +87 -0
  109. package/dist/esm-node/shared/localisedUrls/redirect.mjs +49 -0
  110. package/dist/esm-node/shared/localisedUrls/resolve.mjs +48 -0
  111. package/dist/esm-node/shared/localisedUrls/routes.mjs +89 -0
  112. package/dist/esm-node/shared/localisedUrls/types.mjs +1 -0
  113. package/dist/esm-node/shared/localisedUrls.mjs +1 -283
  114. package/dist/esm-node/shared/utils.mjs +1 -1
  115. package/dist/types/cli/locales.d.ts +1 -1
  116. package/dist/types/runtime/Link.d.ts +3 -7
  117. package/dist/types/runtime/context.d.ts +6 -5
  118. package/dist/types/runtime/contextHelpers.d.ts +28 -0
  119. package/dist/types/runtime/core.d.ts +3 -7
  120. package/dist/types/runtime/hooks.d.ts +5 -0
  121. package/dist/types/runtime/i18n/backend/middleware.common.d.ts +2 -1
  122. package/dist/types/runtime/i18n/detection/cache.d.ts +14 -0
  123. package/dist/types/runtime/i18n/detection/detector.d.ts +8 -0
  124. package/dist/types/runtime/i18n/detection/index.d.ts +5 -50
  125. package/dist/types/runtime/i18n/detection/initOptions.d.ts +10 -0
  126. package/dist/types/runtime/i18n/detection/language.d.ts +11 -0
  127. package/dist/types/runtime/i18n/detection/middleware.d.ts +4 -4
  128. package/dist/types/runtime/i18n/detection/middleware.node.d.ts +4 -4
  129. package/dist/types/runtime/i18n/detection/path.d.ts +5 -0
  130. package/dist/types/runtime/i18n/detection/priority.d.ts +10 -0
  131. package/dist/types/runtime/i18n/detection/ssr.d.ts +9 -0
  132. package/dist/types/runtime/i18n/detection/types.d.ts +32 -0
  133. package/dist/types/runtime/i18n/instance.d.ts +28 -26
  134. package/dist/types/runtime/i18n/react-i18next.d.ts +1 -6
  135. package/dist/types/runtime/i18n/utils.d.ts +14 -5
  136. package/dist/types/runtime/linkHelpers.d.ts +17 -0
  137. package/dist/types/runtime/pluginSetup.d.ts +32 -0
  138. package/dist/types/runtime/providerComposition.d.ts +16 -0
  139. package/dist/types/runtime/reactI18next.d.ts +7 -0
  140. package/dist/types/runtime/routerAdapter.d.ts +7 -6
  141. package/dist/types/runtime/utils.d.ts +7 -2
  142. package/dist/types/server/apiPrefix.d.ts +7 -0
  143. package/dist/types/server/detectorOptions.d.ts +21 -0
  144. package/dist/types/server/index.d.ts +1 -6
  145. package/dist/types/server/redirectPolicy.d.ts +22 -0
  146. package/dist/types/shared/detection.d.ts +1 -11
  147. package/dist/types/shared/localisedUrls/config.d.ts +9 -0
  148. package/dist/types/shared/localisedUrls/index.d.ts +9 -0
  149. package/dist/types/shared/localisedUrls/normalise.d.ts +10 -0
  150. package/dist/types/shared/localisedUrls/pathname.d.ts +4 -0
  151. package/dist/types/shared/localisedUrls/patterns.d.ts +5 -0
  152. package/dist/types/shared/localisedUrls/redirect.d.ts +11 -0
  153. package/dist/types/shared/localisedUrls/resolve.d.ts +7 -0
  154. package/dist/types/shared/localisedUrls/routes.d.ts +3 -0
  155. package/dist/types/shared/localisedUrls/types.d.ts +14 -0
  156. package/dist/types/shared/localisedUrls.d.ts +2 -36
  157. package/dist/types/shared/utils.d.ts +0 -2
  158. package/package.json +16 -18
  159. package/rstest.config.mts +1 -0
  160. package/src/cli/index.ts +5 -4
  161. package/src/cli/locales.ts +3 -3
  162. package/src/runtime/Link.tsx +11 -138
  163. package/src/runtime/context.tsx +45 -199
  164. package/src/runtime/contextHelpers.ts +232 -0
  165. package/src/runtime/core.tsx +43 -274
  166. package/src/runtime/hooks.ts +13 -2
  167. package/src/runtime/i18n/backend/defaults.node.ts +2 -2
  168. package/src/runtime/i18n/backend/middleware.common.ts +5 -4
  169. package/src/runtime/i18n/detection/cache.ts +189 -0
  170. package/src/runtime/i18n/detection/detector.ts +166 -0
  171. package/src/runtime/i18n/detection/index.ts +10 -641
  172. package/src/runtime/i18n/detection/initOptions.ts +74 -0
  173. package/src/runtime/i18n/detection/language.ts +64 -0
  174. package/src/runtime/i18n/detection/middleware.node.ts +26 -7
  175. package/src/runtime/i18n/detection/middleware.ts +15 -7
  176. package/src/runtime/i18n/detection/path.ts +41 -0
  177. package/src/runtime/i18n/detection/priority.ts +82 -0
  178. package/src/runtime/i18n/detection/ssr.ts +47 -0
  179. package/src/runtime/i18n/detection/types.ts +41 -0
  180. package/src/runtime/i18n/instance.ts +56 -31
  181. package/src/runtime/i18n/react-i18next.ts +1 -6
  182. package/src/runtime/i18n/utils.ts +18 -9
  183. package/src/runtime/linkHelpers.ts +174 -0
  184. package/src/runtime/pluginSetup.ts +189 -0
  185. package/src/runtime/providerComposition.tsx +144 -0
  186. package/src/runtime/reactI18next.ts +20 -0
  187. package/src/runtime/routerAdapter.tsx +6 -6
  188. package/src/runtime/utils.ts +13 -35
  189. package/src/server/apiPrefix.ts +67 -0
  190. package/src/server/detectorOptions.ts +105 -0
  191. package/src/server/index.ts +14 -319
  192. package/src/server/redirectPolicy.ts +127 -0
  193. package/src/shared/detection.ts +1 -1
  194. package/src/shared/localisedUrls/config.ts +18 -0
  195. package/src/shared/localisedUrls/index.ts +24 -0
  196. package/src/shared/localisedUrls/normalise.ts +67 -0
  197. package/src/shared/localisedUrls/pathname.ts +60 -0
  198. package/src/shared/localisedUrls/patterns.ts +160 -0
  199. package/src/shared/localisedUrls/redirect.ts +91 -0
  200. package/src/shared/localisedUrls/resolve.ts +135 -0
  201. package/src/shared/localisedUrls/routes.ts +226 -0
  202. package/src/shared/localisedUrls/types.ts +18 -0
  203. package/src/shared/localisedUrls.ts +26 -623
  204. package/src/shared/utils.ts +2 -2
  205. package/tests/fixtures/localised-routes.golden.json +156 -0
  206. package/tests/link.test.tsx +111 -0
  207. package/tests/linkTypes.test.ts +15 -4
  208. package/tests/localisedUrlRewriteMatrix.fork.test.ts +147 -0
  209. package/tests/localisedUrls.test.ts +129 -2
  210. package/tests/reactI18nextRuntimeBoundary.test.ts +6 -3
  211. package/tests/redirectPolicy.test.ts +43 -0
  212. package/tests/routerAdapter.test.tsx +85 -0
  213. package/tests/type-fixture/fixture-globals.d.ts +11 -0
  214. package/tests/type-fixture/tsconfig.json +1 -0
@@ -39,37 +39,15 @@ __webpack_require__.d(__webpack_exports__, {
39
39
  useLocalizedPaths: ()=>external_localizedPaths_js_namespaceObject.useLocalizedPaths,
40
40
  useModernI18n: ()=>external_context_js_namespaceObject.useModernI18n
41
41
  });
42
- const jsx_runtime_namespaceObject = require("react/jsx-runtime");
43
- const runtime_namespaceObject = require("@modern-js/runtime");
44
- const head_namespaceObject = require("@modern-js/runtime/head");
45
- const merge_namespaceObject = require("@modern-js/runtime-utils/merge");
46
- const external_react_namespaceObject = require("react");
47
- const external_context_js_namespaceObject = require("./context.js");
48
- const external_hooks_js_namespaceObject = require("./hooks.js");
49
- const index_js_namespaceObject = require("./i18n/index.js");
50
- const backend_index_js_namespaceObject = require("./i18n/backend/index.js");
51
- const detection_index_js_namespaceObject = require("./i18n/detection/index.js");
52
- const middleware_js_namespaceObject = require("./i18n/detection/middleware.js");
53
- const instance_js_namespaceObject = require("./i18n/instance.js");
54
- const external_utils_js_namespaceObject = require("./utils.js");
42
+ const external_pluginSetup_js_namespaceObject = require("./pluginSetup.js");
43
+ const external_providerComposition_js_namespaceObject = require("./providerComposition.js");
44
+ const external_reactI18next_js_namespaceObject = require("./reactI18next.js");
55
45
  require("./types.js");
46
+ const external_context_js_namespaceObject = require("./context.js");
56
47
  const external_I18nLink_js_namespaceObject = require("./I18nLink.js");
57
48
  const external_Link_js_namespaceObject = require("./Link.js");
58
49
  const external_localizedPaths_js_namespaceObject = require("./localizedPaths.js");
59
- let i18nLifecycleHelpersPromise;
60
- function loadI18nLifecycleHelpers() {
61
- i18nLifecycleHelpersPromise ??= Promise.all([
62
- import("./i18n/backend/middleware.js"),
63
- import("./i18n/utils.js")
64
- ]).then(([backendMiddleware, utils])=>({
65
- useI18nextBackend: backendMiddleware.useI18nextBackend,
66
- changeI18nLanguage: utils.changeI18nLanguage,
67
- ensureLanguageMatch: utils.ensureLanguageMatch,
68
- initializeI18nInstance: utils.initializeI18nInstance,
69
- setupClonedInstance: utils.setupClonedInstance
70
- }));
71
- return i18nLifecycleHelpersPromise;
72
- }
50
+ const external_utils_js_namespaceObject = require("./utils.js");
73
51
  const createI18nPlugin = (loadReactI18nextIntegration)=>(options)=>({
74
52
  name: '@modern-js/plugin-i18n',
75
53
  setup: (api)=>{
@@ -78,116 +56,35 @@ const createI18nPlugin = (loadReactI18nextIntegration)=>(options)=>({
78
56
  const { enabled: backendEnabled = false } = backend || {};
79
57
  let latestI18nInstance;
80
58
  let I18nextProvider;
81
- const resolveReactI18nextIntegration = async ()=>{
82
- if (!reactI18next) return null;
83
- return loadReactI18nextIntegration?.() ?? null;
84
- };
85
59
  api.onBeforeRender(async (context)=>{
86
- const { useI18nextBackend, changeI18nLanguage, ensureLanguageMatch, initializeI18nInstance, setupClonedInstance } = await loadI18nLifecycleHelpers();
87
- let i18nInstance = await (0, index_js_namespaceObject.getI18nInstance)(userI18nInstance);
88
- const { i18n: otherConfig } = api.getRuntimeConfig();
89
- const { initOptions: otherInitOptions } = otherConfig || {};
90
- const userInitOptions = (0, merge_namespaceObject.merge)(otherInitOptions || {}, initOptions || {});
91
- const reactI18nextIntegration = await resolveReactI18nextIntegration();
92
- I18nextProvider = reactI18nextIntegration?.I18nextProvider ?? null;
93
- if (reactI18nextIntegration?.initReactI18next) i18nInstance.use(reactI18nextIntegration.initReactI18next);
94
- const pathname = (0, external_utils_js_namespaceObject.getPathname)(context);
95
- if (i18nextDetector) (0, middleware_js_namespaceObject.useI18nextLanguageDetector)(i18nInstance);
96
- const mergedDetection = (0, detection_index_js_namespaceObject.mergeDetectionOptions)(i18nextDetector, detection, localePathRedirect, userInitOptions);
97
- const mergedBackend = (0, backend_index_js_namespaceObject.mergeBackendOptions)(backend, userInitOptions);
98
- const hasSdkConfig = 'function' == typeof userInitOptions?.backend?.sdk || mergedBackend?.sdk && 'function' == typeof mergedBackend.sdk;
99
- if (mergedBackend && (backendEnabled || hasSdkConfig)) useI18nextBackend(i18nInstance, mergedBackend);
100
- const { finalLanguage } = await (0, detection_index_js_namespaceObject.detectLanguageWithPriority)(i18nInstance, {
101
- languages,
102
- fallbackLanguage,
103
- localePathRedirect,
60
+ latestI18nInstance = await (0, external_pluginSetup_js_namespaceObject.setupI18nBeforeRender)(context, {
61
+ api,
62
+ userI18nInstance,
63
+ initOptions,
64
+ backend,
65
+ backendEnabled,
104
66
  i18nextDetector,
105
67
  detection,
106
- userInitOptions,
107
- mergedBackend,
108
- pathname,
109
- ssrContext: context.ssrContext
110
- });
111
- await initializeI18nInstance(i18nInstance, finalLanguage, fallbackLanguage, languages, mergedDetection, mergedBackend, userInitOptions);
112
- if (!(0, runtime_namespaceObject.isBrowser)() && i18nInstance.cloneInstance) {
113
- i18nInstance = i18nInstance.cloneInstance();
114
- await setupClonedInstance(i18nInstance, finalLanguage, fallbackLanguage, languages, backendEnabled, backend, i18nextDetector, detection, localePathRedirect, userInitOptions);
115
- }
116
- if (localePathRedirect) await ensureLanguageMatch(i18nInstance, finalLanguage);
117
- if (!(0, runtime_namespaceObject.isBrowser)()) (0, detection_index_js_namespaceObject.exportServerLngToWindow)(context, finalLanguage);
118
- context.i18nInstance = i18nInstance;
119
- latestI18nInstance = i18nInstance;
120
- context.changeLanguage = async (newLang)=>{
121
- await changeI18nLanguage(i18nInstance, newLang, {
122
- detectionOptions: mergedDetection
123
- });
124
- };
125
- });
126
- api.wrapRoot((App)=>(props)=>{
127
- const runtimeContext = (0, external_react_namespaceObject.useContext)(runtime_namespaceObject.RuntimeContext);
128
- const i18nInstance = runtimeContext.i18nInstance || latestI18nInstance;
129
- const initialLang = (0, external_react_namespaceObject.useMemo)(()=>i18nInstance?.language || (localeDetection?.fallbackLanguage ?? 'en'), [
130
- i18nInstance?.language,
131
- localeDetection?.fallbackLanguage
132
- ]);
133
- const [lang, setLang] = (0, external_react_namespaceObject.useState)(initialLang);
134
- const [forceUpdate, setForceUpdate] = (0, external_react_namespaceObject.useState)(0);
135
- const prevLangRef = (0, external_react_namespaceObject.useRef)(lang);
136
- const runtimeContextRef = (0, external_react_namespaceObject.useRef)(runtimeContext);
137
- runtimeContextRef.current = runtimeContext;
138
- (0, external_react_namespaceObject.useEffect)(()=>{
139
- if (i18nInstance?.language) {
140
- const translator = i18nInstance.translator;
141
- if (translator) translator.language = i18nInstance.language;
142
- }
143
- }, [
144
- i18nInstance?.language
145
- ]);
146
- (0, external_react_namespaceObject.useEffect)(()=>{
147
- prevLangRef.current = lang;
148
- }, [
149
- lang
150
- ]);
151
- (0, external_hooks_js_namespaceObject.useSdkResourcesLoader)(i18nInstance, setForceUpdate);
152
- (0, external_hooks_js_namespaceObject.useLanguageSync)(i18nInstance, localePathRedirect, languages, runtimeContextRef, prevLangRef, setLang);
153
- (0, external_hooks_js_namespaceObject.useClientSideRedirect)(i18nInstance, localePathRedirect, languages, fallbackLanguage, ignoreRedirectRoutes, localisedUrls);
154
- const contextValue = (0, external_react_namespaceObject.useMemo)(()=>(0, external_hooks_js_namespaceObject.createContextValue)(lang, i18nInstance, entryName, languages, localePathRedirect, ignoreRedirectRoutes, localisedUrls, setLang), [
155
- lang,
156
- i18nInstance,
157
- entryName,
158
- languages,
159
- localePathRedirect,
160
- ignoreRedirectRoutes,
161
- localisedUrls,
162
- forceUpdate
163
- ]);
164
- const children = props.children;
165
- const appContent = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
166
- children: [
167
- Boolean(htmlLangAttr) && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(head_namespaceObject.Helmet, {
168
- htmlAttributes: {
169
- lang
170
- }
171
- }),
172
- /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_context_js_namespaceObject.ModernI18nProvider, {
173
- value: contextValue,
174
- children: App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
175
- ...props,
176
- children: children
177
- }) : children
178
- })
179
- ]
180
- });
181
- if (!i18nInstance) return appContent;
182
- if (I18nextProvider) {
183
- const i18nextInstanceForProvider = (0, instance_js_namespaceObject.getI18nextInstanceForProvider)(i18nInstance);
184
- return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(I18nextProvider, {
185
- i18n: i18nextInstanceForProvider,
186
- children: appContent
187
- });
68
+ localePathRedirect,
69
+ languages,
70
+ fallbackLanguage,
71
+ resolveReactI18nextIntegration: ()=>(0, external_reactI18next_js_namespaceObject.resolveReactI18nextIntegration)(reactI18next, loadReactI18nextIntegration),
72
+ setI18nextProvider: (provider)=>{
73
+ I18nextProvider = provider;
188
74
  }
189
- return appContent;
190
75
  });
76
+ });
77
+ api.wrapRoot((0, external_providerComposition_js_namespaceObject.createI18nRootWrapper)({
78
+ entryName,
79
+ htmlLangAttr,
80
+ localePathRedirect,
81
+ languages,
82
+ fallbackLanguage,
83
+ ignoreRedirectRoutes,
84
+ localisedUrls,
85
+ getLatestI18nInstance: ()=>latestI18nInstance,
86
+ getI18nextProvider: ()=>I18nextProvider
87
+ }));
191
88
  }
192
89
  });
193
90
  exports.I18nLink = __webpack_exports__.I18nLink;
@@ -41,23 +41,23 @@ __webpack_require__.d(__webpack_exports__, {
41
41
  convertBackendOptions: ()=>convertBackendOptions,
42
42
  resolveDefaultLocalesDir: ()=>resolveDefaultLocalesDir
43
43
  });
44
- const external_fs_namespaceObject = require("fs");
45
- var external_fs_default = /*#__PURE__*/ __webpack_require__.n(external_fs_namespaceObject);
46
- const external_path_namespaceObject = require("path");
47
- var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
44
+ const external_node_fs_namespaceObject = require("node:fs");
45
+ var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
46
+ const external_node_path_namespaceObject = require("node:path");
47
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
48
48
  const CONVENTIONAL_LOCALES_DIRS = [
49
49
  './locales',
50
50
  './config/public/locales'
51
51
  ];
52
52
  const isDirectory = (dirPath)=>{
53
53
  try {
54
- return external_fs_default().statSync(dirPath).isDirectory();
54
+ return external_node_fs_default().statSync(dirPath).isDirectory();
55
55
  } catch {
56
56
  return false;
57
57
  }
58
58
  };
59
59
  const resolveDefaultLocalesDir = (cwd = process.cwd())=>{
60
- for (const dir of CONVENTIONAL_LOCALES_DIRS)if (isDirectory(external_path_default().resolve(cwd, dir))) return dir;
60
+ for (const dir of CONVENTIONAL_LOCALES_DIRS)if (isDirectory(external_node_path_default().resolve(cwd, dir))) return dir;
61
61
  return CONVENTIONAL_LOCALES_DIRS[0];
62
62
  };
63
63
  const DEFAULT_I18NEXT_BACKEND_OPTIONS = {
@@ -83,7 +83,7 @@ function getResourceBasePath(resourcePath) {
83
83
  }
84
84
  function pathExists(resourcePath) {
85
85
  try {
86
- return external_fs_default().existsSync(getResourceBasePath(resourcePath));
86
+ return external_node_fs_default().existsSync(getResourceBasePath(resourcePath));
87
87
  } catch {
88
88
  return false;
89
89
  }
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ const detectorInstanceCache = new WeakMap();
31
+ const DETECTOR_SAFE_OPTION_KEYS = [
32
+ 'lowerCaseLng',
33
+ 'nonExplicitSupportedLngs',
34
+ 'load',
35
+ 'partialBundledLanguages',
36
+ 'returnNull',
37
+ 'returnEmptyString',
38
+ 'returnObjects',
39
+ 'joinArrays',
40
+ 'keySeparator',
41
+ 'nsSeparator',
42
+ 'pluralSeparator',
43
+ 'contextSeparator',
44
+ 'fallbackNS',
45
+ 'ns',
46
+ 'defaultNS',
47
+ 'debug'
48
+ ];
49
+ const stableStringify = (value)=>{
50
+ if (null == value) return JSON.stringify(value);
51
+ if ('object' != typeof value) return JSON.stringify(value);
52
+ if (Array.isArray(value)) return `[${value.map((item)=>stableStringify(item)).join(',')}]`;
53
+ const record = value;
54
+ const sortedKeys = Object.keys(record).sort();
55
+ const sortedEntries = sortedKeys.map((key)=>{
56
+ const stringifiedValue = stableStringify(record[key]);
57
+ return `${JSON.stringify(key)}:${stringifiedValue}`;
58
+ });
59
+ return `{${sortedEntries.join(',')}}`;
60
+ };
61
+ const buildDetectorConfigKey = (languages, fallbackLanguage, mergedDetection)=>stableStringify({
62
+ languages,
63
+ fallbackLanguage,
64
+ detection: mergedDetection
65
+ });
66
+ const pickSafeDetectionOptions = (userInitOptions)=>{
67
+ if (!userInitOptions) return {};
68
+ const safeOptions = {};
69
+ for (const key of DETECTOR_SAFE_OPTION_KEYS){
70
+ const value = userInitOptions[key];
71
+ if (void 0 !== value) safeOptions[key] = value;
72
+ }
73
+ if (userInitOptions.interpolation) safeOptions.interpolation = {
74
+ ...userInitOptions.interpolation
75
+ };
76
+ return safeOptions;
77
+ };
78
+ const cleanupDetectorCacheEntry = (entry)=>{
79
+ if (!entry || !entry.isTemporary) return;
80
+ const instance = entry.instance;
81
+ try {
82
+ instance?.removeAllListeners?.();
83
+ } catch (error) {}
84
+ try {
85
+ instance?.off?.('*');
86
+ } catch (error) {}
87
+ try {
88
+ instance?.services?.backendConnector?.backend?.stop?.();
89
+ } catch (error) {}
90
+ try {
91
+ instance?.services?.backendConnector?.backend?.close?.();
92
+ } catch (error) {}
93
+ };
94
+ const createDetectorInstance = (baseInstance, configKey)=>{
95
+ const cached = detectorInstanceCache.get(baseInstance);
96
+ if (cached && cached.configKey === configKey) return {
97
+ instance: cached.instance,
98
+ isTemporary: cached.isTemporary
99
+ };
100
+ if (cached) {
101
+ cleanupDetectorCacheEntry(cached);
102
+ detectorInstanceCache.delete(baseInstance);
103
+ }
104
+ const createNewInstance = ()=>{
105
+ if ('function' == typeof baseInstance.createInstance) try {
106
+ const created = baseInstance.createInstance();
107
+ if (created) return {
108
+ instance: created,
109
+ isTemporary: true
110
+ };
111
+ } catch (error) {}
112
+ if ('function' == typeof baseInstance.cloneInstance) try {
113
+ const cloned = baseInstance.cloneInstance();
114
+ if (cloned) return {
115
+ instance: cloned,
116
+ isTemporary: true
117
+ };
118
+ } catch (error) {}
119
+ return {
120
+ instance: baseInstance,
121
+ isTemporary: false
122
+ };
123
+ };
124
+ const created = createNewInstance();
125
+ if (created.isTemporary) detectorInstanceCache.set(baseInstance, {
126
+ instance: created.instance,
127
+ isTemporary: true,
128
+ configKey
129
+ });
130
+ return created;
131
+ };
132
+ __webpack_require__.d(__webpack_exports__, {}, {
133
+ buildDetectorConfigKey: buildDetectorConfigKey,
134
+ createDetectorInstance: createDetectorInstance,
135
+ detectorInstanceCache: detectorInstanceCache,
136
+ pickSafeDetectionOptions: pickSafeDetectionOptions
137
+ });
138
+ exports.buildDetectorConfigKey = __webpack_exports__.buildDetectorConfigKey;
139
+ exports.createDetectorInstance = __webpack_exports__.createDetectorInstance;
140
+ exports.detectorInstanceCache = __webpack_exports__.detectorInstanceCache;
141
+ exports.pickSafeDetectionOptions = __webpack_exports__.pickSafeDetectionOptions;
142
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
143
+ "buildDetectorConfigKey",
144
+ "createDetectorInstance",
145
+ "detectorInstanceCache",
146
+ "pickSafeDetectionOptions"
147
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
148
+ Object.defineProperty(exports, '__esModule', {
149
+ value: true
150
+ });
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ detectLanguageFromI18nextDetector: ()=>detectLanguageFromI18nextDetector
32
+ });
33
+ const runtime_namespaceObject = require("@modern-js/runtime");
34
+ const external_cache_js_namespaceObject = require("./cache.js");
35
+ const external_initOptions_js_namespaceObject = require("./initOptions.js");
36
+ const external_language_js_namespaceObject = require("./language.js");
37
+ const external_middleware_js_namespaceObject = require("./middleware.js");
38
+ const initializeI18nForDetector = async (i18nInstance, options)=>{
39
+ const mergedDetection = (0, external_initOptions_js_namespaceObject.mergeDetectionOptions)(options.i18nextDetector, options.detection, options.localePathRedirect, options.userInitOptions);
40
+ const configKey = (0, external_cache_js_namespaceObject.buildDetectorConfigKey)(options.languages, options.fallbackLanguage, mergedDetection);
41
+ const { instance, isTemporary } = (0, external_cache_js_namespaceObject.createDetectorInstance)(i18nInstance, configKey);
42
+ const safeUserOptions = (0, external_cache_js_namespaceObject.pickSafeDetectionOptions)(options.userInitOptions);
43
+ const initOptions = {
44
+ ...safeUserOptions,
45
+ fallbackLng: options.fallbackLanguage,
46
+ supportedLngs: options.languages,
47
+ detection: mergedDetection,
48
+ initImmediate: true,
49
+ interpolation: {
50
+ ...safeUserOptions?.interpolation || {},
51
+ escapeValue: safeUserOptions?.interpolation?.escapeValue ?? false
52
+ },
53
+ react: {
54
+ useSuspense: false
55
+ }
56
+ };
57
+ (0, external_middleware_js_namespaceObject.useI18nextLanguageDetector)(instance);
58
+ if (instance.isInitialized) {
59
+ if (isTemporary) await instance.init(initOptions);
60
+ } else await instance.init(initOptions);
61
+ return {
62
+ detectorInstance: instance,
63
+ isTemporary
64
+ };
65
+ };
66
+ const detectLanguageFromI18nextDetector = async (i18nInstance, options)=>{
67
+ if (!options.i18nextDetector) return;
68
+ const mergedDetection = (0, external_initOptions_js_namespaceObject.mergeDetectionOptions)(options.i18nextDetector, options.detection, options.localePathRedirect, options.userInitOptions);
69
+ const { detectorInstance, isTemporary } = await initializeI18nForDetector(i18nInstance, options);
70
+ try {
71
+ const request = options.ssrContext?.request;
72
+ if (!(0, runtime_namespaceObject.isBrowser)() && !request) return;
73
+ const detectorLang = (0, external_middleware_js_namespaceObject.detectLanguage)(detectorInstance, request, mergedDetection);
74
+ if (detectorLang) {
75
+ const supportedLang = (0, external_language_js_namespaceObject.getSupportedLanguage)(detectorLang, options.languages);
76
+ if (supportedLang) return supportedLang;
77
+ }
78
+ if (detectorInstance.isInitialized && detectorInstance.language) {
79
+ const currentLang = detectorInstance.language;
80
+ if ((0, external_language_js_namespaceObject.isLanguageSupported)(currentLang, options.languages)) return currentLang;
81
+ }
82
+ } catch (error) {} finally{
83
+ if (isTemporary && detectorInstance !== i18nInstance) external_cache_js_namespaceObject.detectorInstanceCache.set(i18nInstance, {
84
+ instance: detectorInstance,
85
+ isTemporary: true,
86
+ configKey: (0, external_cache_js_namespaceObject.buildDetectorConfigKey)(options.languages, options.fallbackLanguage, mergedDetection)
87
+ });
88
+ else if (detectorInstance === i18nInstance) {
89
+ i18nInstance.isInitialized = false;
90
+ delete i18nInstance.language;
91
+ }
92
+ }
93
+ };
94
+ exports.detectLanguageFromI18nextDetector = __webpack_exports__.detectLanguageFromI18nextDetector;
95
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
96
+ "detectLanguageFromI18nextDetector"
97
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
98
+ Object.defineProperty(exports, '__esModule', {
99
+ value: true
100
+ });