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

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
@@ -0,0 +1,148 @@
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 warnedTargets = new Set();
31
+ const warnOnce = (key, message)=>{
32
+ if ('development' !== process.env.NODE_ENV || warnedTargets.has(key)) return;
33
+ warnedTargets.add(key);
34
+ console.warn(message);
35
+ };
36
+ const interpolateRouteParams = (pathname, params)=>{
37
+ if (!/[$:*{]/.test(pathname)) return pathname;
38
+ const resolveParam = (name)=>{
39
+ const value = params?.[name];
40
+ return void 0 === value ? void 0 : String(value);
41
+ };
42
+ const segments = pathname.split('/').map((segment)=>{
43
+ if (!segment) return segment;
44
+ if (segment.startsWith('{-$') && segment.endsWith('}')) {
45
+ const value = resolveParam(segment.slice(3, -1));
46
+ return void 0 === value ? null : encodeURIComponent(value);
47
+ }
48
+ if ('$' === segment || '*' === segment) {
49
+ const value = resolveParam('_splat') ?? resolveParam('*');
50
+ return void 0 === value ? null : value.split('/').map(encodeURIComponent).join('/');
51
+ }
52
+ if (segment.startsWith('$')) {
53
+ const value = resolveParam(segment.slice(1));
54
+ if (void 0 === value) {
55
+ warnOnce(`missing-param:${pathname}:${segment}`, `[plugin-i18n] <Link to="${pathname}"> is missing required param "${segment.slice(1)}".`);
56
+ return segment;
57
+ }
58
+ return encodeURIComponent(value);
59
+ }
60
+ if (segment.startsWith(':')) {
61
+ const optional = segment.endsWith('?');
62
+ const name = segment.slice(1, optional ? -1 : void 0);
63
+ const value = resolveParam(name);
64
+ if (void 0 === value) {
65
+ if (optional) return null;
66
+ warnOnce(`missing-param:${pathname}:${segment}`, `[plugin-i18n] <Link to="${pathname}"> is missing required param "${name}".`);
67
+ return segment;
68
+ }
69
+ return encodeURIComponent(value);
70
+ }
71
+ return segment;
72
+ }).filter((segment)=>null !== segment);
73
+ return segments.join('/') || '/';
74
+ };
75
+ const normalizeSearch = (search, searchFromTo)=>{
76
+ if (search && 'object' == typeof search) {
77
+ const searchObject = {};
78
+ const params = new URLSearchParams();
79
+ for (const [key, value] of Object.entries(search)){
80
+ if (null == value) continue;
81
+ if (Array.isArray(value)) {
82
+ const values = value.filter((item)=>null != item).map(String);
83
+ if (0 === values.length) continue;
84
+ searchObject[key] = values;
85
+ for (const item of values)params.append(key, item);
86
+ continue;
87
+ }
88
+ const stringValue = String(value);
89
+ searchObject[key] = stringValue;
90
+ params.append(key, stringValue);
91
+ }
92
+ const serialized = params.toString();
93
+ return {
94
+ searchString: serialized ? `?${serialized}` : '',
95
+ searchObject: Object.keys(searchObject).length > 0 ? searchObject : void 0
96
+ };
97
+ }
98
+ const raw = 'string' == typeof search ? search : searchFromTo;
99
+ if (!raw) return {
100
+ searchString: '',
101
+ searchObject: void 0
102
+ };
103
+ const searchString = raw.startsWith('?') ? raw : `?${raw}`;
104
+ const searchObject = {};
105
+ new URLSearchParams(searchString).forEach((value, key)=>{
106
+ const existing = searchObject[key];
107
+ if (void 0 === existing) searchObject[key] = value;
108
+ else if (Array.isArray(existing)) existing.push(value);
109
+ else searchObject[key] = [
110
+ existing,
111
+ value
112
+ ];
113
+ });
114
+ return {
115
+ searchString,
116
+ searchObject
117
+ };
118
+ };
119
+ const splitActiveProps = (active, activeProps)=>{
120
+ if (!active || !activeProps) return {};
121
+ return activeProps;
122
+ };
123
+ const mergeClassNames = (...values)=>{
124
+ const classNames = values.filter((value)=>'string' == typeof value && value.length > 0);
125
+ return classNames.length > 0 ? classNames.join(' ') : void 0;
126
+ };
127
+ __webpack_require__.d(__webpack_exports__, {}, {
128
+ interpolateRouteParams: interpolateRouteParams,
129
+ mergeClassNames: mergeClassNames,
130
+ normalizeSearch: normalizeSearch,
131
+ splitActiveProps: splitActiveProps,
132
+ warnOnce: warnOnce
133
+ });
134
+ exports.interpolateRouteParams = __webpack_exports__.interpolateRouteParams;
135
+ exports.mergeClassNames = __webpack_exports__.mergeClassNames;
136
+ exports.normalizeSearch = __webpack_exports__.normalizeSearch;
137
+ exports.splitActiveProps = __webpack_exports__.splitActiveProps;
138
+ exports.warnOnce = __webpack_exports__.warnOnce;
139
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
140
+ "interpolateRouteParams",
141
+ "mergeClassNames",
142
+ "normalizeSearch",
143
+ "splitActiveProps",
144
+ "warnOnce"
145
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
146
+ Object.defineProperty(exports, '__esModule', {
147
+ value: true
148
+ });
@@ -0,0 +1,102 @@
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
+ setupI18nBeforeRender: ()=>setupI18nBeforeRender
32
+ });
33
+ const runtime_namespaceObject = require("@modern-js/runtime");
34
+ const merge_namespaceObject = require("@modern-js/runtime-utils/merge");
35
+ const index_js_namespaceObject = require("./i18n/index.js");
36
+ const backend_index_js_namespaceObject = require("./i18n/backend/index.js");
37
+ const detection_index_js_namespaceObject = require("./i18n/detection/index.js");
38
+ const middleware_js_namespaceObject = require("./i18n/detection/middleware.js");
39
+ const external_utils_js_namespaceObject = require("./utils.js");
40
+ let i18nLifecycleHelpersPromise;
41
+ function loadI18nLifecycleHelpers() {
42
+ i18nLifecycleHelpersPromise ??= Promise.all([
43
+ import("./i18n/backend/middleware.js"),
44
+ import("./i18n/utils.js")
45
+ ]).then(([backendMiddleware, utils])=>({
46
+ useI18nextBackend: backendMiddleware.useI18nextBackend,
47
+ changeI18nLanguage: utils.changeI18nLanguage,
48
+ ensureLanguageMatch: utils.ensureLanguageMatch,
49
+ initializeI18nInstance: utils.initializeI18nInstance,
50
+ setupClonedInstance: utils.setupClonedInstance
51
+ }));
52
+ return i18nLifecycleHelpersPromise;
53
+ }
54
+ async function setupI18nBeforeRender(context, options) {
55
+ const { api, userI18nInstance, initOptions, backend, backendEnabled, i18nextDetector, detection, localePathRedirect, languages, fallbackLanguage, resolveReactI18nextIntegration, setI18nextProvider } = options;
56
+ const { useI18nextBackend, changeI18nLanguage, ensureLanguageMatch, initializeI18nInstance, setupClonedInstance } = await loadI18nLifecycleHelpers();
57
+ let i18nInstance = await (0, index_js_namespaceObject.getI18nInstance)(userI18nInstance);
58
+ const { i18n: otherConfig } = api.getRuntimeConfig();
59
+ const { initOptions: otherInitOptions } = otherConfig || {};
60
+ const userInitOptions = (0, merge_namespaceObject.merge)(otherInitOptions || {}, initOptions || {});
61
+ const reactI18nextIntegration = await resolveReactI18nextIntegration();
62
+ setI18nextProvider(reactI18nextIntegration?.I18nextProvider ?? null);
63
+ if (reactI18nextIntegration?.initReactI18next) i18nInstance.use(reactI18nextIntegration.initReactI18next);
64
+ const pathname = (0, external_utils_js_namespaceObject.getPathname)(context);
65
+ if (i18nextDetector) (0, middleware_js_namespaceObject.useI18nextLanguageDetector)(i18nInstance);
66
+ const mergedDetection = (0, detection_index_js_namespaceObject.mergeDetectionOptions)(i18nextDetector, detection, localePathRedirect, userInitOptions);
67
+ const mergedBackend = (0, backend_index_js_namespaceObject.mergeBackendOptions)(backend, userInitOptions);
68
+ const hasSdkConfig = 'function' == typeof userInitOptions?.backend?.sdk || mergedBackend?.sdk && 'function' == typeof mergedBackend.sdk;
69
+ if (mergedBackend && (backendEnabled || hasSdkConfig)) useI18nextBackend(i18nInstance, mergedBackend);
70
+ const { finalLanguage } = await (0, detection_index_js_namespaceObject.detectLanguageWithPriority)(i18nInstance, {
71
+ languages,
72
+ fallbackLanguage,
73
+ localePathRedirect,
74
+ i18nextDetector,
75
+ detection,
76
+ userInitOptions,
77
+ mergedBackend,
78
+ pathname,
79
+ ssrContext: context.ssrContext
80
+ });
81
+ await initializeI18nInstance(i18nInstance, finalLanguage, fallbackLanguage, languages, mergedDetection, mergedBackend, userInitOptions);
82
+ if (!(0, runtime_namespaceObject.isBrowser)() && i18nInstance.cloneInstance) {
83
+ i18nInstance = i18nInstance.cloneInstance();
84
+ await setupClonedInstance(i18nInstance, finalLanguage, fallbackLanguage, languages, backendEnabled, backend, i18nextDetector, detection, localePathRedirect, userInitOptions);
85
+ }
86
+ if (localePathRedirect) await ensureLanguageMatch(i18nInstance, finalLanguage);
87
+ if (!(0, runtime_namespaceObject.isBrowser)()) (0, detection_index_js_namespaceObject.exportServerLngToWindow)(context, finalLanguage);
88
+ context.i18nInstance = i18nInstance;
89
+ context.changeLanguage = async (newLang)=>{
90
+ await changeI18nLanguage(i18nInstance, newLang, {
91
+ detectionOptions: mergedDetection
92
+ });
93
+ };
94
+ return i18nInstance;
95
+ }
96
+ exports.setupI18nBeforeRender = __webpack_exports__.setupI18nBeforeRender;
97
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
98
+ "setupI18nBeforeRender"
99
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
100
+ Object.defineProperty(exports, '__esModule', {
101
+ value: true
102
+ });
@@ -0,0 +1,114 @@
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
+ createI18nRootWrapper: ()=>createI18nRootWrapper
32
+ });
33
+ const jsx_runtime_namespaceObject = require("react/jsx-runtime");
34
+ const runtime_namespaceObject = require("@modern-js/runtime");
35
+ const head_namespaceObject = require("@modern-js/runtime/head");
36
+ const external_react_namespaceObject = require("react");
37
+ const external_context_js_namespaceObject = require("./context.js");
38
+ const external_hooks_js_namespaceObject = require("./hooks.js");
39
+ const instance_js_namespaceObject = require("./i18n/instance.js");
40
+ const createI18nRootWrapper = (options)=>(App)=>(props)=>{
41
+ const { entryName, htmlLangAttr, localePathRedirect, languages, fallbackLanguage, ignoreRedirectRoutes, localisedUrls, getLatestI18nInstance, getI18nextProvider } = options;
42
+ const runtimeContext = (0, external_react_namespaceObject.useContext)(runtime_namespaceObject.RuntimeContext);
43
+ const i18nInstance = runtimeContext.i18nInstance || getLatestI18nInstance();
44
+ const initialLang = (0, external_react_namespaceObject.useMemo)(()=>i18nInstance?.language || fallbackLanguage, [
45
+ i18nInstance?.language,
46
+ fallbackLanguage
47
+ ]);
48
+ const [lang, setLang] = (0, external_react_namespaceObject.useState)(initialLang);
49
+ const [forceUpdate, setForceUpdate] = (0, external_react_namespaceObject.useState)(0);
50
+ const prevLangRef = (0, external_react_namespaceObject.useRef)(lang);
51
+ const runtimeContextRef = (0, external_react_namespaceObject.useRef)(runtimeContext);
52
+ runtimeContextRef.current = runtimeContext;
53
+ (0, external_react_namespaceObject.useEffect)(()=>{
54
+ if (i18nInstance?.language) {
55
+ const translator = i18nInstance.translator;
56
+ if (translator) translator.language = i18nInstance.language;
57
+ }
58
+ }, [
59
+ i18nInstance?.language
60
+ ]);
61
+ (0, external_react_namespaceObject.useEffect)(()=>{
62
+ prevLangRef.current = lang;
63
+ }, [
64
+ lang
65
+ ]);
66
+ (0, external_hooks_js_namespaceObject.useSdkResourcesLoader)(i18nInstance, setForceUpdate);
67
+ (0, external_hooks_js_namespaceObject.useLanguageSync)(i18nInstance, localePathRedirect, languages, runtimeContextRef, prevLangRef, setLang);
68
+ (0, external_hooks_js_namespaceObject.useClientSideRedirect)(i18nInstance, localePathRedirect, languages, fallbackLanguage, ignoreRedirectRoutes, localisedUrls);
69
+ const contextValue = (0, external_react_namespaceObject.useMemo)(()=>(0, external_hooks_js_namespaceObject.createContextValue)(lang, i18nInstance, entryName, languages, localePathRedirect, ignoreRedirectRoutes, localisedUrls, setLang), [
70
+ lang,
71
+ i18nInstance,
72
+ entryName,
73
+ languages,
74
+ localePathRedirect,
75
+ ignoreRedirectRoutes,
76
+ localisedUrls,
77
+ forceUpdate
78
+ ]);
79
+ const children = props.children;
80
+ let appContent = App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
81
+ ...props,
82
+ children: children
83
+ }) : children;
84
+ if (i18nInstance) {
85
+ const I18nextProvider = getI18nextProvider();
86
+ if (I18nextProvider) {
87
+ const i18nextInstanceForProvider = (0, instance_js_namespaceObject.getI18nextInstanceForProvider)(i18nInstance);
88
+ appContent = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(I18nextProvider, {
89
+ i18n: i18nextInstanceForProvider,
90
+ children: appContent
91
+ });
92
+ }
93
+ }
94
+ return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
95
+ children: [
96
+ Boolean(htmlLangAttr) && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(head_namespaceObject.Helmet, {
97
+ htmlAttributes: {
98
+ lang
99
+ }
100
+ }),
101
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_context_js_namespaceObject.ModernI18nProvider, {
102
+ value: contextValue,
103
+ children: appContent
104
+ })
105
+ ]
106
+ });
107
+ };
108
+ exports.createI18nRootWrapper = __webpack_exports__.createI18nRootWrapper;
109
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
110
+ "createI18nRootWrapper"
111
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
112
+ Object.defineProperty(exports, '__esModule', {
113
+ value: true
114
+ });
@@ -0,0 +1,43 @@
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 resolveReactI18nextIntegration = async (reactI18next, loadReactI18nextIntegration)=>{
31
+ if (!reactI18next) return null;
32
+ return loadReactI18nextIntegration?.() ?? null;
33
+ };
34
+ __webpack_require__.d(__webpack_exports__, {}, {
35
+ resolveReactI18nextIntegration: resolveReactI18nextIntegration
36
+ });
37
+ exports.resolveReactI18nextIntegration = __webpack_exports__.resolveReactI18nextIntegration;
38
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
39
+ "resolveReactI18nextIntegration"
40
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
41
+ Object.defineProperty(exports, '__esModule', {
42
+ value: true
43
+ });
@@ -89,15 +89,7 @@ const detectLanguageFromPath = (pathname, languages, localePathRedirect)=>{
89
89
  detected: false
90
90
  };
91
91
  };
92
- const shouldIgnoreRedirect = (pathname, languages, ignoreRedirectRoutes)=>{
93
- if (!ignoreRedirectRoutes) return false;
94
- const segments = pathname.split('/').filter(Boolean);
95
- let pathWithoutLang = pathname;
96
- if (segments.length > 0 && languages.includes(segments[0])) pathWithoutLang = `/${segments.slice(1).join('/')}`;
97
- const normalizedPath = pathWithoutLang.startsWith('/') ? pathWithoutLang : `/${pathWithoutLang}`;
98
- if ('function' == typeof ignoreRedirectRoutes) return ignoreRedirectRoutes(normalizedPath);
99
- return ignoreRedirectRoutes.some((pattern)=>normalizedPath === pattern || normalizedPath.startsWith(`${pattern}/`));
100
- };
92
+ const shouldIgnoreRedirect = (pathname, languages, ignoreRedirectRoutes)=>(0, localisedUrls_js_namespaceObject.shouldSkipLocaleRedirect)(pathname, languages, ignoreRedirectRoutes);
101
93
  exports.buildLocalizedUrl = __webpack_exports__.buildLocalizedUrl;
102
94
  exports.detectLanguageFromPath = __webpack_exports__.detectLanguageFromPath;
103
95
  exports.getEntryPath = __webpack_exports__.getEntryPath;
@@ -0,0 +1,72 @@
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 normalizeApiPrefix = (prefix)=>{
31
+ const trimmedPrefix = prefix.trim();
32
+ if (!trimmedPrefix) return null;
33
+ const prefixedPath = trimmedPrefix.startsWith('/') ? trimmedPrefix : `/${trimmedPrefix}`;
34
+ const withoutWildcard = prefixedPath.replace(/\/\*$/, '');
35
+ const normalizedPrefix = withoutWildcard.length > 1 ? withoutWildcard.replace(/\/+$/, '') : withoutWildcard;
36
+ return '/' === normalizedPrefix ? null : normalizedPrefix;
37
+ };
38
+ const collectApiPrefixes = (routes, bffPrefix)=>{
39
+ const prefixes = new Set();
40
+ for (const route of routes){
41
+ if (!route.isApi || !route.urlPath) continue;
42
+ const normalizedPrefix = normalizeApiPrefix(route.urlPath);
43
+ if (normalizedPrefix) prefixes.add(normalizedPrefix);
44
+ }
45
+ const bffPrefixes = Array.isArray(bffPrefix) ? bffPrefix : bffPrefix ? [
46
+ bffPrefix
47
+ ] : [];
48
+ for (const prefix of bffPrefixes){
49
+ const normalizedPrefix = normalizeApiPrefix(prefix);
50
+ if (normalizedPrefix) prefixes.add(normalizedPrefix);
51
+ }
52
+ return [
53
+ ...prefixes
54
+ ];
55
+ };
56
+ const matchesApiPrefix = (pathname, apiPrefixes)=>{
57
+ const normalizedPathname = pathname.startsWith('/') ? pathname : `/${pathname}`;
58
+ return apiPrefixes.some((prefix)=>normalizedPathname === prefix || normalizedPathname.startsWith(`${prefix}/`));
59
+ };
60
+ __webpack_require__.d(__webpack_exports__, {}, {
61
+ collectApiPrefixes: collectApiPrefixes,
62
+ matchesApiPrefix: matchesApiPrefix
63
+ });
64
+ exports.collectApiPrefixes = __webpack_exports__.collectApiPrefixes;
65
+ exports.matchesApiPrefix = __webpack_exports__.matchesApiPrefix;
66
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
67
+ "collectApiPrefixes",
68
+ "matchesApiPrefix"
69
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
70
+ Object.defineProperty(exports, '__esModule', {
71
+ value: true
72
+ });
@@ -0,0 +1,97 @@
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
+ convertToHonoLanguageDetectorOptions: ()=>convertToHonoLanguageDetectorOptions
32
+ });
33
+ const config_js_namespaceObject = require("../runtime/i18n/detection/config.js");
34
+ const convertToHonoLanguageDetectorOptions = (languages, fallbackLanguage, detectionOptions)=>{
35
+ const mergedDetection = detectionOptions ? (0, config_js_namespaceObject.mergeDetectionOptions)(detectionOptions) : config_js_namespaceObject.DEFAULT_I18NEXT_DETECTION_OPTIONS;
36
+ const order = (mergedDetection.order || []).filter((item)=>![
37
+ 'path',
38
+ 'localStorage',
39
+ 'navigator',
40
+ 'htmlTag',
41
+ 'subdomain'
42
+ ].includes(item));
43
+ const detectionOrder = order.length > 0 ? order : [
44
+ 'querystring',
45
+ 'cookie',
46
+ 'header'
47
+ ];
48
+ const honoOrder = detectionOrder.map((item)=>{
49
+ if ('querystring' === item) return 'querystring';
50
+ if ('cookie' === item) return 'cookie';
51
+ if ('header' === item) return 'header';
52
+ return item;
53
+ });
54
+ const caches = false === mergedDetection.caches ? false : Array.isArray(mergedDetection.caches) && !mergedDetection.caches.includes('cookie') ? false : [
55
+ 'cookie'
56
+ ];
57
+ const cookieMinutes = mergedDetection.cookieMinutes;
58
+ const cookieMaxAge = 'number' == typeof cookieMinutes && Number.isFinite(cookieMinutes) ? Math.max(0, Math.floor(60 * cookieMinutes)) : 60 * config_js_namespaceObject.DEFAULT_I18NEXT_DETECTION_OPTIONS.cookieMinutes;
59
+ const cookieDomain = mergedDetection.cookieDomain;
60
+ const cookieSecure = mergedDetection.cookieSecure;
61
+ const cookieHttpOnly = mergedDetection.cookieHttpOnly;
62
+ const cookieSameSite = mergedDetection.cookieSameSite;
63
+ const normalizedCookieDomain = 'string' == typeof cookieDomain ? cookieDomain : void 0;
64
+ const cookieOptions = {
65
+ maxAge: cookieMaxAge,
66
+ sameSite: 'None' === cookieSameSite || 'none' === cookieSameSite ? 'None' : 'Lax' === cookieSameSite || 'lax' === cookieSameSite ? 'Lax' : 'Strict',
67
+ secure: 'boolean' == typeof cookieSecure ? cookieSecure : false,
68
+ httpOnly: 'boolean' == typeof cookieHttpOnly ? cookieHttpOnly : false,
69
+ ...normalizedCookieDomain ? {
70
+ domain: normalizedCookieDomain
71
+ } : {}
72
+ };
73
+ return {
74
+ supportedLanguages: languages.length > 0 ? languages : [
75
+ fallbackLanguage
76
+ ],
77
+ fallbackLanguage,
78
+ order: honoOrder,
79
+ lookupQueryString: mergedDetection.lookupQuerystring || config_js_namespaceObject.DEFAULT_I18NEXT_DETECTION_OPTIONS.lookupQuerystring || 'lng',
80
+ lookupCookie: mergedDetection.lookupCookie || config_js_namespaceObject.DEFAULT_I18NEXT_DETECTION_OPTIONS.lookupCookie || 'i18next',
81
+ lookupFromHeaderKey: mergedDetection.lookupHeader || config_js_namespaceObject.DEFAULT_I18NEXT_DETECTION_OPTIONS.lookupHeader || 'accept-language',
82
+ ...void 0 !== caches && {
83
+ caches
84
+ },
85
+ ...false !== caches && {
86
+ cookieOptions
87
+ },
88
+ ignoreCase: true
89
+ };
90
+ };
91
+ exports.convertToHonoLanguageDetectorOptions = __webpack_exports__.convertToHonoLanguageDetectorOptions;
92
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
93
+ "convertToHonoLanguageDetectorOptions"
94
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
95
+ Object.defineProperty(exports, '__esModule', {
96
+ value: true
97
+ });