@bleedingdev/modern-js-plugin-i18n 3.2.0-ultramodern.12 → 3.2.0-ultramodern.120

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 (117) hide show
  1. package/README.md +221 -11
  2. package/dist/cjs/cli/index.js +32 -5
  3. package/dist/cjs/runtime/I18nLink.js +17 -28
  4. package/dist/cjs/runtime/Link.js +252 -0
  5. package/dist/cjs/runtime/canonicalRoutes.js +18 -0
  6. package/dist/cjs/runtime/context.js +41 -10
  7. package/dist/cjs/runtime/hooks.js +17 -10
  8. package/dist/cjs/runtime/i18n/backend/config.js +9 -5
  9. package/dist/cjs/runtime/i18n/backend/defaults.js +15 -10
  10. package/dist/cjs/runtime/i18n/backend/defaults.node.js +16 -11
  11. package/dist/cjs/runtime/i18n/backend/index.js +9 -5
  12. package/dist/cjs/runtime/i18n/backend/middleware.common.js +9 -5
  13. package/dist/cjs/runtime/i18n/backend/middleware.js +9 -5
  14. package/dist/cjs/runtime/i18n/backend/middleware.node.js +13 -9
  15. package/dist/cjs/runtime/i18n/backend/sdk-backend.js +9 -5
  16. package/dist/cjs/runtime/i18n/backend/sdk-event.js +16 -11
  17. package/dist/cjs/runtime/i18n/detection/config.js +9 -5
  18. package/dist/cjs/runtime/i18n/detection/index.js +9 -5
  19. package/dist/cjs/runtime/i18n/detection/middleware.js +9 -5
  20. package/dist/cjs/runtime/i18n/detection/middleware.node.js +9 -5
  21. package/dist/cjs/runtime/i18n/index.js +9 -5
  22. package/dist/cjs/runtime/i18n/instance.js +17 -37
  23. package/dist/cjs/runtime/i18n/react-i18next.js +53 -0
  24. package/dist/cjs/runtime/i18n/utils.js +9 -17
  25. package/dist/cjs/runtime/index.js +50 -15
  26. package/dist/cjs/runtime/localizedPaths.js +105 -0
  27. package/dist/cjs/runtime/routerAdapter.js +167 -0
  28. package/dist/cjs/runtime/utils.js +87 -97
  29. package/dist/cjs/server/index.js +69 -13
  30. package/dist/cjs/shared/deepMerge.js +12 -8
  31. package/dist/cjs/shared/detection.js +9 -5
  32. package/dist/cjs/shared/localisedUrls.js +271 -0
  33. package/dist/cjs/shared/utils.js +15 -11
  34. package/dist/esm/cli/index.mjs +23 -0
  35. package/dist/esm/runtime/I18nLink.mjs +7 -22
  36. package/dist/esm/runtime/Link.mjs +209 -0
  37. package/dist/esm/runtime/canonicalRoutes.mjs +0 -0
  38. package/dist/esm/runtime/context.mjs +34 -7
  39. package/dist/esm/runtime/hooks.mjs +9 -6
  40. package/dist/esm/runtime/i18n/backend/defaults.mjs +1 -1
  41. package/dist/esm/runtime/i18n/backend/defaults.node.mjs +2 -2
  42. package/dist/esm/runtime/i18n/backend/middleware.node.mjs +3 -3
  43. package/dist/esm/runtime/i18n/instance.mjs +1 -19
  44. package/dist/esm/runtime/i18n/react-i18next.mjs +15 -0
  45. package/dist/esm/runtime/i18n/utils.mjs +0 -12
  46. package/dist/esm/runtime/index.mjs +23 -13
  47. package/dist/esm/runtime/localizedPaths.mjs +58 -0
  48. package/dist/esm/runtime/routerAdapter.mjs +129 -0
  49. package/dist/esm/runtime/utils.mjs +25 -30
  50. package/dist/esm/server/index.mjs +53 -7
  51. package/dist/esm/shared/localisedUrls.mjs +212 -0
  52. package/dist/esm-node/cli/index.mjs +23 -0
  53. package/dist/esm-node/runtime/I18nLink.mjs +7 -22
  54. package/dist/esm-node/runtime/Link.mjs +210 -0
  55. package/dist/esm-node/runtime/canonicalRoutes.mjs +1 -0
  56. package/dist/esm-node/runtime/context.mjs +34 -7
  57. package/dist/esm-node/runtime/hooks.mjs +9 -6
  58. package/dist/esm-node/runtime/i18n/backend/defaults.mjs +1 -1
  59. package/dist/esm-node/runtime/i18n/backend/defaults.node.mjs +2 -2
  60. package/dist/esm-node/runtime/i18n/backend/middleware.node.mjs +3 -3
  61. package/dist/esm-node/runtime/i18n/instance.mjs +1 -19
  62. package/dist/esm-node/runtime/i18n/react-i18next.mjs +16 -0
  63. package/dist/esm-node/runtime/i18n/utils.mjs +0 -12
  64. package/dist/esm-node/runtime/index.mjs +23 -13
  65. package/dist/esm-node/runtime/localizedPaths.mjs +59 -0
  66. package/dist/esm-node/runtime/routerAdapter.mjs +130 -0
  67. package/dist/esm-node/runtime/utils.mjs +25 -30
  68. package/dist/esm-node/server/index.mjs +53 -7
  69. package/dist/esm-node/shared/localisedUrls.mjs +213 -0
  70. package/dist/types/cli/index.d.ts +1 -0
  71. package/dist/types/runtime/I18nLink.d.ts +6 -0
  72. package/dist/types/runtime/Link.d.ts +56 -0
  73. package/dist/types/runtime/canonicalRoutes.d.ts +60 -0
  74. package/dist/types/runtime/context.d.ts +3 -0
  75. package/dist/types/runtime/hooks.d.ts +4 -2
  76. package/dist/types/runtime/i18n/backend/middleware.node.d.ts +1 -1
  77. package/dist/types/runtime/i18n/instance.d.ts +4 -6
  78. package/dist/types/runtime/i18n/react-i18next.d.ts +7 -0
  79. package/dist/types/runtime/index.d.ts +6 -1
  80. package/dist/types/runtime/localizedPaths.d.ts +39 -0
  81. package/dist/types/runtime/routerAdapter.d.ts +26 -0
  82. package/dist/types/runtime/types.d.ts +1 -1
  83. package/dist/types/runtime/utils.d.ts +13 -9
  84. package/dist/types/server/index.d.ts +6 -0
  85. package/dist/types/shared/localisedUrls.d.ts +21 -0
  86. package/dist/types/shared/type.d.ts +12 -0
  87. package/package.json +24 -28
  88. package/rstest.config.mts +39 -0
  89. package/src/cli/index.ts +44 -1
  90. package/src/runtime/I18nLink.tsx +14 -51
  91. package/src/runtime/Link.tsx +414 -0
  92. package/src/runtime/canonicalRoutes.ts +93 -0
  93. package/src/runtime/context.tsx +45 -7
  94. package/src/runtime/hooks.ts +13 -4
  95. package/src/runtime/i18n/backend/defaults.node.ts +2 -2
  96. package/src/runtime/i18n/backend/defaults.ts +3 -1
  97. package/src/runtime/i18n/backend/middleware.node.ts +1 -1
  98. package/src/runtime/i18n/instance.ts +3 -30
  99. package/src/runtime/i18n/react-i18next.ts +25 -0
  100. package/src/runtime/i18n/utils.ts +4 -26
  101. package/src/runtime/index.tsx +47 -12
  102. package/src/runtime/localizedPaths.ts +118 -0
  103. package/src/runtime/routerAdapter.tsx +333 -0
  104. package/src/runtime/types.ts +1 -1
  105. package/src/runtime/utils.ts +44 -37
  106. package/src/server/index.ts +117 -10
  107. package/src/shared/localisedUrls.ts +453 -0
  108. package/src/shared/type.ts +12 -0
  109. package/tests/i18nUtils.test.ts +52 -0
  110. package/tests/link.test.tsx +475 -0
  111. package/tests/linkTypes.test.ts +28 -0
  112. package/tests/localisedUrls.test.ts +312 -0
  113. package/tests/routerAdapter.test.tsx +452 -0
  114. package/tests/type-fixture/linkTypes.fixture.tsx +51 -0
  115. package/tests/type-fixture/tsconfig.json +15 -0
  116. package/dist/esm/rslib-runtime.mjs +0 -18
  117. package/dist/esm-node/rslib-runtime.mjs +0 -19
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  var __webpack_require__ = {};
3
3
  (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
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");
9
13
  };
10
14
  })();
11
15
  (()=>{
@@ -23,16 +27,6 @@ var __webpack_require__ = {};
23
27
  })();
24
28
  var __webpack_exports__ = {};
25
29
  __webpack_require__.r(__webpack_exports__);
26
- __webpack_require__.d(__webpack_exports__, {
27
- getActualI18nextInstance: ()=>getActualI18nextInstance,
28
- getI18nInstance: ()=>getI18nInstance,
29
- getI18nWrapperI18nextInstance: ()=>getI18nWrapperI18nextInstance,
30
- getI18nextInstanceForProvider: ()=>getI18nextInstanceForProvider,
31
- getI18nextProvider: ()=>getI18nextProvider,
32
- getInitReactI18next: ()=>getInitReactI18next,
33
- isI18nInstance: ()=>isI18nInstance,
34
- isI18nWrapperInstance: ()=>isI18nWrapperInstance
35
- });
36
30
  function isI18nWrapperInstance(obj) {
37
31
  if (!obj || 'object' != typeof obj) return false;
38
32
  if (!obj.i18nInstance || 'object' != typeof obj.i18nInstance) return false;
@@ -75,14 +69,6 @@ async function createI18nextInstance() {
75
69
  return null;
76
70
  }
77
71
  }
78
- async function tryImportReactI18next() {
79
- try {
80
- const reactI18next = await import("react-i18next");
81
- return reactI18next;
82
- } catch (error) {
83
- return null;
84
- }
85
- }
86
72
  function getI18nextInstanceForProvider(instance) {
87
73
  if (isI18nWrapperInstance(instance)) {
88
74
  const i18nextInstance = getI18nWrapperI18nextInstance(instance);
@@ -99,22 +85,18 @@ async function getI18nInstance(userInstance) {
99
85
  if (i18nextInstance) return i18nextInstance;
100
86
  throw new Error('No i18n instance found');
101
87
  }
102
- async function getInitReactI18next() {
103
- const reactI18nextModule = await tryImportReactI18next();
104
- if (reactI18nextModule) return reactI18nextModule.initReactI18next;
105
- return null;
106
- }
107
- async function getI18nextProvider() {
108
- const reactI18nextModule = await tryImportReactI18next();
109
- if (reactI18nextModule) return reactI18nextModule.I18nextProvider;
110
- return null;
111
- }
88
+ __webpack_require__.d(__webpack_exports__, {
89
+ getActualI18nextInstance: ()=>getActualI18nextInstance,
90
+ getI18nInstance: ()=>getI18nInstance,
91
+ getI18nWrapperI18nextInstance: ()=>getI18nWrapperI18nextInstance,
92
+ getI18nextInstanceForProvider: ()=>getI18nextInstanceForProvider,
93
+ isI18nInstance: ()=>isI18nInstance,
94
+ isI18nWrapperInstance: ()=>isI18nWrapperInstance
95
+ });
112
96
  exports.getActualI18nextInstance = __webpack_exports__.getActualI18nextInstance;
113
97
  exports.getI18nInstance = __webpack_exports__.getI18nInstance;
114
98
  exports.getI18nWrapperI18nextInstance = __webpack_exports__.getI18nWrapperI18nextInstance;
115
99
  exports.getI18nextInstanceForProvider = __webpack_exports__.getI18nextInstanceForProvider;
116
- exports.getI18nextProvider = __webpack_exports__.getI18nextProvider;
117
- exports.getInitReactI18next = __webpack_exports__.getInitReactI18next;
118
100
  exports.isI18nInstance = __webpack_exports__.isI18nInstance;
119
101
  exports.isI18nWrapperInstance = __webpack_exports__.isI18nWrapperInstance;
120
102
  for(var __rspack_i in __webpack_exports__)if (-1 === [
@@ -122,8 +104,6 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
122
104
  "getI18nInstance",
123
105
  "getI18nWrapperI18nextInstance",
124
106
  "getI18nextInstanceForProvider",
125
- "getI18nextProvider",
126
- "getInitReactI18next",
127
107
  "isI18nInstance",
128
108
  "isI18nWrapperInstance"
129
109
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
@@ -0,0 +1,53 @@
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
+ async function tryImportReactI18next() {
31
+ try {
32
+ return await import("react-i18next");
33
+ } catch (error) {
34
+ return null;
35
+ }
36
+ }
37
+ async function getReactI18nextIntegration() {
38
+ const reactI18nextModule = await tryImportReactI18next();
39
+ return {
40
+ I18nextProvider: reactI18nextModule?.I18nextProvider ?? null,
41
+ initReactI18next: reactI18nextModule?.initReactI18next ?? null
42
+ };
43
+ }
44
+ __webpack_require__.d(__webpack_exports__, {
45
+ getReactI18nextIntegration: ()=>getReactI18nextIntegration
46
+ });
47
+ exports.getReactI18nextIntegration = __webpack_exports__.getReactI18nextIntegration;
48
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
49
+ "getReactI18nextIntegration"
50
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
51
+ Object.defineProperty(exports, '__esModule', {
52
+ value: true
53
+ });
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  var __webpack_require__ = {};
3
3
  (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
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");
9
13
  };
10
14
  })();
11
15
  (()=>{
@@ -133,18 +137,6 @@ const initializeI18nInstance = async (i18nInstance, finalLanguage, fallbackLangu
133
137
  };
134
138
  }
135
139
  }
136
- if (mergedBackend && hasOptions(i18nInstance)) {
137
- const defaultNS = initOptions.defaultNS || initOptions.ns || 'translation';
138
- const ns = Array.isArray(defaultNS) ? defaultNS[0] : defaultNS;
139
- let retries = 20;
140
- while(retries > 0){
141
- const actualInstance = (0, external_instance_js_namespaceObject.getActualI18nextInstance)(i18nInstance);
142
- const store = actualInstance.store;
143
- if (store?.data?.[finalLanguage]?.[ns]) break;
144
- await new Promise((resolve)=>setTimeout(resolve, 100));
145
- retries--;
146
- }
147
- }
148
140
  }
149
141
  };
150
142
  function hasOptions(instance) {
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  var __webpack_require__ = {};
3
3
  (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
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");
9
13
  };
10
14
  })();
11
15
  (()=>{
@@ -25,8 +29,15 @@ var __webpack_exports__ = {};
25
29
  __webpack_require__.r(__webpack_exports__);
26
30
  __webpack_require__.d(__webpack_exports__, {
27
31
  I18nLink: ()=>external_I18nLink_js_namespaceObject.I18nLink,
32
+ Link: ()=>external_Link_js_namespaceObject.Link,
33
+ buildLocalizedUrl: ()=>external_utils_js_namespaceObject.buildLocalizedUrl,
34
+ canonicalPath: ()=>external_localizedPaths_js_namespaceObject.canonicalPath,
28
35
  default: ()=>runtime,
29
36
  i18nPlugin: ()=>i18nPlugin,
37
+ localizePath: ()=>external_localizedPaths_js_namespaceObject.localizePath,
38
+ splitUrlTarget: ()=>external_utils_js_namespaceObject.splitUrlTarget,
39
+ useLocalizedLocation: ()=>external_localizedPaths_js_namespaceObject.useLocalizedLocation,
40
+ useLocalizedPaths: ()=>external_localizedPaths_js_namespaceObject.useLocalizedPaths,
30
41
  useModernI18n: ()=>external_context_js_namespaceObject.useModernI18n
31
42
  });
32
43
  const jsx_runtime_namespaceObject = require("react/jsx-runtime");
@@ -46,22 +57,29 @@ const utils_js_namespaceObject = require("./i18n/utils.js");
46
57
  const external_utils_js_namespaceObject = require("./utils.js");
47
58
  require("./types.js");
48
59
  const external_I18nLink_js_namespaceObject = require("./I18nLink.js");
60
+ const external_Link_js_namespaceObject = require("./Link.js");
61
+ const external_localizedPaths_js_namespaceObject = require("./localizedPaths.js");
49
62
  const i18nPlugin = (options)=>({
50
63
  name: '@modern-js/plugin-i18n',
51
64
  setup: (api)=>{
52
- const { entryName, i18nInstance: userI18nInstance, initOptions, localeDetection, backend, htmlLangAttr = false } = options;
53
- const { localePathRedirect = false, i18nextDetector = true, languages = [], fallbackLanguage = 'en', detection, ignoreRedirectRoutes } = localeDetection || {};
65
+ const { entryName, i18nInstance: userI18nInstance, initOptions, localeDetection, backend, htmlLangAttr = false, reactI18next = true } = options;
66
+ const { localePathRedirect = false, i18nextDetector = true, languages = [], fallbackLanguage = 'en', detection, ignoreRedirectRoutes, localisedUrls } = localeDetection || {};
54
67
  const { enabled: backendEnabled = false } = backend || {};
55
68
  let latestI18nInstance;
56
69
  let I18nextProvider;
70
+ const loadReactI18nextIntegration = async ()=>{
71
+ if (!reactI18next) return null;
72
+ const { getReactI18nextIntegration } = await import("./i18n/react-i18next.js");
73
+ return getReactI18nextIntegration();
74
+ };
57
75
  api.onBeforeRender(async (context)=>{
58
76
  let i18nInstance = await (0, index_js_namespaceObject.getI18nInstance)(userI18nInstance);
59
77
  const { i18n: otherConfig } = api.getRuntimeConfig();
60
78
  const { initOptions: otherInitOptions } = otherConfig || {};
61
79
  const userInitOptions = (0, merge_namespaceObject.merge)(otherInitOptions || {}, initOptions || {});
62
- const initReactI18next = await (0, instance_js_namespaceObject.getInitReactI18next)();
63
- I18nextProvider = await (0, instance_js_namespaceObject.getI18nextProvider)();
64
- if (initReactI18next) i18nInstance.use(initReactI18next);
80
+ const reactI18nextIntegration = await loadReactI18nextIntegration();
81
+ I18nextProvider = reactI18nextIntegration?.I18nextProvider ?? null;
82
+ if (reactI18nextIntegration?.initReactI18next) i18nInstance.use(reactI18nextIntegration.initReactI18next);
65
83
  const pathname = (0, external_utils_js_namespaceObject.getPathname)(context);
66
84
  if (i18nextDetector) (0, detection_middleware_js_namespaceObject.useI18nextLanguageDetector)(i18nInstance);
67
85
  const mergedDetection = (0, detection_index_js_namespaceObject.mergeDetectionOptions)(i18nextDetector, detection, localePathRedirect, userInitOptions);
@@ -121,16 +139,18 @@ const i18nPlugin = (options)=>({
121
139
  ]);
122
140
  (0, external_hooks_js_namespaceObject.useSdkResourcesLoader)(i18nInstance, setForceUpdate);
123
141
  (0, external_hooks_js_namespaceObject.useLanguageSync)(i18nInstance, localePathRedirect, languages, runtimeContextRef, prevLangRef, setLang);
124
- (0, external_hooks_js_namespaceObject.useClientSideRedirect)(i18nInstance, localePathRedirect, languages, fallbackLanguage, ignoreRedirectRoutes);
125
- const contextValue = (0, external_react_namespaceObject.useMemo)(()=>(0, external_hooks_js_namespaceObject.createContextValue)(lang, i18nInstance, entryName, languages, localePathRedirect, ignoreRedirectRoutes, setLang), [
142
+ (0, external_hooks_js_namespaceObject.useClientSideRedirect)(i18nInstance, localePathRedirect, languages, fallbackLanguage, ignoreRedirectRoutes, localisedUrls);
143
+ const contextValue = (0, external_react_namespaceObject.useMemo)(()=>(0, external_hooks_js_namespaceObject.createContextValue)(lang, i18nInstance, entryName, languages, localePathRedirect, ignoreRedirectRoutes, localisedUrls, setLang), [
126
144
  lang,
127
145
  i18nInstance,
128
146
  entryName,
129
147
  languages,
130
148
  localePathRedirect,
131
149
  ignoreRedirectRoutes,
150
+ localisedUrls,
132
151
  forceUpdate
133
152
  ]);
153
+ const children = props.children;
134
154
  const appContent = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
135
155
  children: [
136
156
  Boolean(htmlLangAttr) && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(head_namespaceObject.Helmet, {
@@ -140,9 +160,10 @@ const i18nPlugin = (options)=>({
140
160
  }),
141
161
  /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_context_js_namespaceObject.ModernI18nProvider, {
142
162
  value: contextValue,
143
- children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
144
- ...props
145
- })
163
+ children: App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
164
+ ...props,
165
+ children: children
166
+ }) : children
146
167
  })
147
168
  ]
148
169
  });
@@ -160,13 +181,27 @@ const i18nPlugin = (options)=>({
160
181
  });
161
182
  const runtime = i18nPlugin;
162
183
  exports.I18nLink = __webpack_exports__.I18nLink;
184
+ exports.Link = __webpack_exports__.Link;
185
+ exports.buildLocalizedUrl = __webpack_exports__.buildLocalizedUrl;
186
+ exports.canonicalPath = __webpack_exports__.canonicalPath;
163
187
  exports["default"] = __webpack_exports__["default"];
164
188
  exports.i18nPlugin = __webpack_exports__.i18nPlugin;
189
+ exports.localizePath = __webpack_exports__.localizePath;
190
+ exports.splitUrlTarget = __webpack_exports__.splitUrlTarget;
191
+ exports.useLocalizedLocation = __webpack_exports__.useLocalizedLocation;
192
+ exports.useLocalizedPaths = __webpack_exports__.useLocalizedPaths;
165
193
  exports.useModernI18n = __webpack_exports__.useModernI18n;
166
194
  for(var __rspack_i in __webpack_exports__)if (-1 === [
167
195
  "I18nLink",
196
+ "Link",
197
+ "buildLocalizedUrl",
198
+ "canonicalPath",
168
199
  "default",
169
200
  "i18nPlugin",
201
+ "localizePath",
202
+ "splitUrlTarget",
203
+ "useLocalizedLocation",
204
+ "useLocalizedPaths",
170
205
  "useModernI18n"
171
206
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
172
207
  Object.defineProperty(exports, '__esModule', {
@@ -0,0 +1,105 @@
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
+ canonicalPath: ()=>canonicalPath,
32
+ localizePath: ()=>localizePath,
33
+ useLocalizedLocation: ()=>useLocalizedLocation,
34
+ useLocalizedPaths: ()=>useLocalizedPaths
35
+ });
36
+ const external_react_namespaceObject = require("react");
37
+ const localisedUrls_js_namespaceObject = require("../shared/localisedUrls.js");
38
+ const external_context_js_namespaceObject = require("./context.js");
39
+ const external_routerAdapter_js_namespaceObject = require("./routerAdapter.js");
40
+ const external_utils_js_namespaceObject = require("./utils.js");
41
+ const localizePath = (pathname, language, config)=>(0, external_utils_js_namespaceObject.buildLocalizedUrl)(pathname, language, config.languages, config.localisedUrls);
42
+ const canonicalPath = (target, config)=>{
43
+ const { pathname, search, hash } = (0, external_utils_js_namespaceObject.splitUrlTarget)(target);
44
+ const segments = pathname.split('/').filter(Boolean);
45
+ const pathWithoutLanguage = segments.length > 0 && config.languages.includes(segments[0]) ? `/${segments.slice(1).join('/')}` : pathname || '/';
46
+ const localisedUrlsConfig = (0, localisedUrls_js_namespaceObject.resolveLocalisedUrlsConfig)(config.localisedUrls);
47
+ const resolvedPath = localisedUrlsConfig.enabled ? (0, localisedUrls_js_namespaceObject.resolveCanonicalLocalisedPath)(pathWithoutLanguage, config.languages, localisedUrlsConfig.map) : pathWithoutLanguage;
48
+ return `${resolvedPath}${search}${hash}`;
49
+ };
50
+ const useLocalizedPaths = ()=>{
51
+ const { supportedLanguages, localisedUrls } = (0, external_context_js_namespaceObject.useModernI18n)();
52
+ return (0, external_react_namespaceObject.useMemo)(()=>{
53
+ const config = {
54
+ languages: supportedLanguages,
55
+ localisedUrls
56
+ };
57
+ return {
58
+ localizePath: (pathname, language)=>localizePath(pathname, language, config),
59
+ canonicalPath: (pathname)=>canonicalPath(pathname, config)
60
+ };
61
+ }, [
62
+ supportedLanguages,
63
+ localisedUrls
64
+ ]);
65
+ };
66
+ const useLocalizedLocation = ()=>{
67
+ const { language, supportedLanguages, localisedUrls } = (0, external_context_js_namespaceObject.useModernI18n)();
68
+ const { location } = (0, external_routerAdapter_js_namespaceObject.useI18nRouterAdapter)();
69
+ const pathname = location?.pathname ?? '/';
70
+ const search = location?.search ?? '';
71
+ const hash = location?.hash ?? '';
72
+ return (0, external_react_namespaceObject.useMemo)(()=>{
73
+ const config = {
74
+ languages: supportedLanguages,
75
+ localisedUrls
76
+ };
77
+ const alternates = {};
78
+ for (const supportedLanguage of supportedLanguages)alternates[supportedLanguage] = `${localizePath(pathname, supportedLanguage, config)}${search}${hash}`;
79
+ return {
80
+ language,
81
+ canonical: canonicalPath(pathname, config),
82
+ alternates
83
+ };
84
+ }, [
85
+ language,
86
+ supportedLanguages,
87
+ localisedUrls,
88
+ pathname,
89
+ search,
90
+ hash
91
+ ]);
92
+ };
93
+ exports.canonicalPath = __webpack_exports__.canonicalPath;
94
+ exports.localizePath = __webpack_exports__.localizePath;
95
+ exports.useLocalizedLocation = __webpack_exports__.useLocalizedLocation;
96
+ exports.useLocalizedPaths = __webpack_exports__.useLocalizedPaths;
97
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
98
+ "canonicalPath",
99
+ "localizePath",
100
+ "useLocalizedLocation",
101
+ "useLocalizedPaths"
102
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
103
+ Object.defineProperty(exports, '__esModule', {
104
+ value: true
105
+ });
@@ -0,0 +1,167 @@
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
+ useI18nRouterAdapter: ()=>useI18nRouterAdapter
32
+ });
33
+ const runtime_namespaceObject = require("@modern-js/runtime");
34
+ const context_namespaceObject = require("@modern-js/runtime/context");
35
+ const router_namespaceObject = require("@modern-js/runtime/router");
36
+ const external_react_namespaceObject = require("react");
37
+ const normalizeUrlPart = (value, prefix)=>{
38
+ if ('string' != typeof value || !value) return '';
39
+ return value.startsWith(prefix) ? value : `${prefix}${value}`;
40
+ };
41
+ const normalizeLocation = (location)=>{
42
+ if (!location || 'object' != typeof location) return null;
43
+ const locationValue = location;
44
+ if ('string' != typeof locationValue.pathname) return null;
45
+ return {
46
+ pathname: locationValue.pathname,
47
+ search: normalizeUrlPart('string' == typeof locationValue.search ? locationValue.search : locationValue.searchStr, '?'),
48
+ hash: normalizeUrlPart(locationValue.hash, '#')
49
+ };
50
+ };
51
+ const getWindowLocation = ()=>{
52
+ if (!(0, runtime_namespaceObject.isBrowser)()) return null;
53
+ return {
54
+ pathname: window.location.pathname,
55
+ search: window.location.search,
56
+ hash: window.location.hash
57
+ };
58
+ };
59
+ const getRouterFramework = (runtimeContext, internalContext, inReactRouter)=>{
60
+ const framework = internalContext.routerFramework || internalContext.routerRuntime?.framework || runtimeContext.routerFramework;
61
+ if (framework) return framework;
62
+ if (internalContext.router?.useRouter || runtimeContext.router?.useRouter) return 'tanstack';
63
+ if (internalContext.router?.useLocation || internalContext.router?.useHref || runtimeContext.router?.useLocation || runtimeContext.router?.useHref) return 'react-router';
64
+ if (inReactRouter) return 'react-router';
65
+ };
66
+ const getRouterInstance = (internalContext, contextRouter)=>{
67
+ if (contextRouter) return contextRouter;
68
+ const router = internalContext.routerInstance || internalContext.routerRuntime?.instance;
69
+ if (!router || 'object' != typeof router) return null;
70
+ return router;
71
+ };
72
+ const getRouterStateLocation = (internalContext, contextRouter)=>{
73
+ const router = getRouterInstance(internalContext, contextRouter);
74
+ return normalizeLocation(router?.stores?.location?.get?.()) || normalizeLocation(router?.state?.location);
75
+ };
76
+ const getRouterParams = (internalContext, contextRouter)=>{
77
+ const router = getRouterInstance(internalContext, contextRouter);
78
+ const matches = router?.stores?.matches?.get?.() || router?.state?.matches;
79
+ if (!Array.isArray(matches)) return {};
80
+ return matches.reduce((params, match)=>{
81
+ if (match?.params) Object.assign(params, match.params);
82
+ return params;
83
+ }, {});
84
+ };
85
+ const useI18nRouterAdapter = ()=>{
86
+ const runtimeContext = (0, external_react_namespaceObject.useContext)(runtime_namespaceObject.RuntimeContext);
87
+ const internalContext = (0, external_react_namespaceObject.useContext)(context_namespaceObject.InternalRuntimeContext);
88
+ const inReactRouter = (0, router_namespaceObject.useInRouterContext)();
89
+ const reactRouterNavigate = inReactRouter ? (0, router_namespaceObject.useNavigate)() : null;
90
+ const reactRouterLocation = inReactRouter ? (0, router_namespaceObject.useLocation)() : null;
91
+ const reactRouterParams = inReactRouter ? (0, router_namespaceObject.useParams)() : {};
92
+ const framework = getRouterFramework(runtimeContext, internalContext, inReactRouter);
93
+ const contextUseRouter = inReactRouter || 'tanstack' !== framework ? void 0 : internalContext.router?.useRouter || runtimeContext.router?.useRouter;
94
+ const contextRouter = contextUseRouter ? contextUseRouter({
95
+ warn: false
96
+ }) : null;
97
+ const [, setRouterVersion] = (0, external_react_namespaceObject.useState)(0);
98
+ const hasRouter = 'tanstack' === framework || 'react-router' === framework || Boolean(reactRouterNavigate);
99
+ (0, external_react_namespaceObject.useEffect)(()=>{
100
+ if ('tanstack' !== framework) return;
101
+ const router = getRouterInstance(internalContext, contextRouter);
102
+ if (!router) return;
103
+ const update = ()=>setRouterVersion((version)=>version + 1);
104
+ const unsubscribers = [];
105
+ if ('function' == typeof router.stores?.location?.subscribe) {
106
+ const unsubscribe = router.stores.location.subscribe(update);
107
+ if ('function' == typeof unsubscribe) unsubscribers.push(unsubscribe);
108
+ }
109
+ if ('function' == typeof router.subscribe) for (const eventType of [
110
+ 'onBeforeNavigate',
111
+ 'onBeforeLoad'
112
+ ]){
113
+ const unsubscribe = router.subscribe(eventType, update);
114
+ if ('function' == typeof unsubscribe) unsubscribers.push(unsubscribe);
115
+ }
116
+ return ()=>{
117
+ for (const unsubscribe of unsubscribers)unsubscribe();
118
+ };
119
+ }, [
120
+ contextRouter,
121
+ framework,
122
+ internalContext
123
+ ]);
124
+ const navigate = (0, external_react_namespaceObject.useCallback)((href, options)=>{
125
+ const router = getRouterInstance(internalContext, contextRouter);
126
+ const activeFramework = getRouterFramework(runtimeContext, internalContext, inReactRouter);
127
+ if ('tanstack' === activeFramework) {
128
+ if ('function' == typeof router?.navigate) return router.navigate({
129
+ to: href,
130
+ replace: options?.replace,
131
+ ...options?.state === void 0 ? {} : {
132
+ state: options.state
133
+ }
134
+ });
135
+ throw new Error('TanStack router instance is not available.');
136
+ }
137
+ if (reactRouterNavigate) return reactRouterNavigate(href, options);
138
+ if ('react-router' === activeFramework) {
139
+ if ('function' == typeof router?.navigate) return router.navigate(href, options);
140
+ throw new Error('React Router instance is not available.');
141
+ }
142
+ }, [
143
+ contextRouter,
144
+ internalContext,
145
+ inReactRouter,
146
+ reactRouterNavigate,
147
+ runtimeContext
148
+ ]);
149
+ const location = (reactRouterLocation ? normalizeLocation(reactRouterLocation) : getRouterStateLocation(internalContext, contextRouter)) || getWindowLocation();
150
+ const params = inReactRouter ? reactRouterParams : getRouterParams(internalContext, contextRouter);
151
+ const Link = 'tanstack' === framework ? internalContext.router?.Link || runtimeContext.router?.Link || null : 'react-router' === framework || inReactRouter ? router_namespaceObject.Link : null;
152
+ return {
153
+ framework,
154
+ hasRouter,
155
+ location,
156
+ navigate: hasRouter ? navigate : null,
157
+ Link,
158
+ params
159
+ };
160
+ };
161
+ exports.useI18nRouterAdapter = __webpack_exports__.useI18nRouterAdapter;
162
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
163
+ "useI18nRouterAdapter"
164
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
165
+ Object.defineProperty(exports, '__esModule', {
166
+ value: true
167
+ });