@bleedingdev/modern-js-plugin-i18n 3.5.0-ultramodern.30 → 3.5.0-ultramodern.31

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 (161) hide show
  1. package/dist/cjs/cli/index.js +2 -1
  2. package/dist/cjs/runtime/Link.js +8 -89
  3. package/dist/cjs/runtime/context.js +18 -82
  4. package/dist/cjs/runtime/contextHelpers.js +137 -0
  5. package/dist/cjs/runtime/core.js +29 -132
  6. package/dist/cjs/runtime/i18n/detection/cache.js +149 -0
  7. package/dist/cjs/runtime/i18n/detection/detector.js +100 -0
  8. package/dist/cjs/runtime/i18n/detection/index.js +8 -263
  9. package/dist/cjs/runtime/i18n/detection/initOptions.js +69 -0
  10. package/dist/cjs/runtime/i18n/detection/language.js +62 -0
  11. package/dist/cjs/runtime/i18n/detection/path.js +49 -0
  12. package/dist/cjs/runtime/i18n/detection/priority.js +66 -0
  13. package/dist/cjs/runtime/i18n/detection/ssr.js +70 -0
  14. package/dist/cjs/runtime/i18n/detection/types.js +18 -0
  15. package/dist/cjs/runtime/linkHelpers.js +148 -0
  16. package/dist/cjs/runtime/pluginSetup.js +102 -0
  17. package/dist/cjs/runtime/providerComposition.js +113 -0
  18. package/dist/cjs/runtime/reactI18next.js +43 -0
  19. package/dist/cjs/server/apiPrefix.js +72 -0
  20. package/dist/cjs/server/detectorOptions.js +97 -0
  21. package/dist/cjs/server/index.js +17 -152
  22. package/dist/cjs/server/redirectPolicy.js +102 -0
  23. package/dist/cjs/shared/localisedUrls/config.js +49 -0
  24. package/dist/cjs/shared/localisedUrls/index.js +75 -0
  25. package/dist/cjs/shared/localisedUrls/normalise.js +87 -0
  26. package/dist/cjs/shared/localisedUrls/pathname.js +65 -0
  27. package/dist/cjs/shared/localisedUrls/patterns.js +130 -0
  28. package/dist/cjs/shared/localisedUrls/resolve.js +91 -0
  29. package/dist/cjs/shared/localisedUrls/routes.js +129 -0
  30. package/dist/cjs/shared/localisedUrls/types.js +18 -0
  31. package/dist/cjs/shared/localisedUrls.js +13 -294
  32. package/dist/esm/cli/index.mjs +2 -1
  33. package/dist/esm/runtime/Link.mjs +1 -82
  34. package/dist/esm/runtime/context.mjs +18 -82
  35. package/dist/esm/runtime/contextHelpers.mjs +84 -0
  36. package/dist/esm/runtime/core.mjs +30 -133
  37. package/dist/esm/runtime/i18n/detection/cache.mjs +102 -0
  38. package/dist/esm/runtime/i18n/detection/detector.mjs +62 -0
  39. package/dist/esm/runtime/i18n/detection/index.mjs +4 -260
  40. package/dist/esm/runtime/i18n/detection/initOptions.mjs +28 -0
  41. package/dist/esm/runtime/i18n/detection/language.mjs +21 -0
  42. package/dist/esm/runtime/i18n/detection/path.mjs +11 -0
  43. package/dist/esm/runtime/i18n/detection/priority.mjs +28 -0
  44. package/dist/esm/runtime/i18n/detection/ssr.mjs +26 -0
  45. package/dist/esm/runtime/i18n/detection/types.mjs +0 -0
  46. package/dist/esm/runtime/linkHelpers.mjs +98 -0
  47. package/dist/esm/runtime/pluginSetup.mjs +64 -0
  48. package/dist/esm/runtime/providerComposition.mjs +75 -0
  49. package/dist/esm/runtime/reactI18next.mjs +5 -0
  50. package/dist/esm/server/apiPrefix.mjs +31 -0
  51. package/dist/esm/server/detectorOptions.mjs +59 -0
  52. package/dist/esm/server/index.mjs +4 -139
  53. package/dist/esm/server/redirectPolicy.mjs +52 -0
  54. package/dist/esm/shared/localisedUrls/config.mjs +11 -0
  55. package/dist/esm/shared/localisedUrls/index.mjs +6 -0
  56. package/dist/esm/shared/localisedUrls/normalise.mjs +37 -0
  57. package/dist/esm/shared/localisedUrls/pathname.mjs +24 -0
  58. package/dist/esm/shared/localisedUrls/patterns.mjs +86 -0
  59. package/dist/esm/shared/localisedUrls/resolve.mjs +50 -0
  60. package/dist/esm/shared/localisedUrls/routes.mjs +88 -0
  61. package/dist/esm/shared/localisedUrls/types.mjs +0 -0
  62. package/dist/esm/shared/localisedUrls.mjs +1 -283
  63. package/dist/esm-node/cli/index.mjs +2 -1
  64. package/dist/esm-node/runtime/Link.mjs +1 -82
  65. package/dist/esm-node/runtime/context.mjs +18 -82
  66. package/dist/esm-node/runtime/contextHelpers.mjs +85 -0
  67. package/dist/esm-node/runtime/core.mjs +30 -133
  68. package/dist/esm-node/runtime/i18n/detection/cache.mjs +103 -0
  69. package/dist/esm-node/runtime/i18n/detection/detector.mjs +63 -0
  70. package/dist/esm-node/runtime/i18n/detection/index.mjs +4 -260
  71. package/dist/esm-node/runtime/i18n/detection/initOptions.mjs +29 -0
  72. package/dist/esm-node/runtime/i18n/detection/language.mjs +22 -0
  73. package/dist/esm-node/runtime/i18n/detection/path.mjs +12 -0
  74. package/dist/esm-node/runtime/i18n/detection/priority.mjs +29 -0
  75. package/dist/esm-node/runtime/i18n/detection/ssr.mjs +27 -0
  76. package/dist/esm-node/runtime/i18n/detection/types.mjs +1 -0
  77. package/dist/esm-node/runtime/linkHelpers.mjs +99 -0
  78. package/dist/esm-node/runtime/pluginSetup.mjs +65 -0
  79. package/dist/esm-node/runtime/providerComposition.mjs +76 -0
  80. package/dist/esm-node/runtime/reactI18next.mjs +6 -0
  81. package/dist/esm-node/server/apiPrefix.mjs +32 -0
  82. package/dist/esm-node/server/detectorOptions.mjs +60 -0
  83. package/dist/esm-node/server/index.mjs +4 -139
  84. package/dist/esm-node/server/redirectPolicy.mjs +53 -0
  85. package/dist/esm-node/shared/localisedUrls/config.mjs +12 -0
  86. package/dist/esm-node/shared/localisedUrls/index.mjs +7 -0
  87. package/dist/esm-node/shared/localisedUrls/normalise.mjs +38 -0
  88. package/dist/esm-node/shared/localisedUrls/pathname.mjs +25 -0
  89. package/dist/esm-node/shared/localisedUrls/patterns.mjs +87 -0
  90. package/dist/esm-node/shared/localisedUrls/resolve.mjs +51 -0
  91. package/dist/esm-node/shared/localisedUrls/routes.mjs +89 -0
  92. package/dist/esm-node/shared/localisedUrls/types.mjs +1 -0
  93. package/dist/esm-node/shared/localisedUrls.mjs +1 -283
  94. package/dist/types/runtime/Link.d.ts +3 -7
  95. package/dist/types/runtime/context.d.ts +2 -2
  96. package/dist/types/runtime/contextHelpers.d.ts +28 -0
  97. package/dist/types/runtime/core.d.ts +3 -7
  98. package/dist/types/runtime/i18n/detection/cache.d.ts +14 -0
  99. package/dist/types/runtime/i18n/detection/detector.d.ts +8 -0
  100. package/dist/types/runtime/i18n/detection/index.d.ts +5 -50
  101. package/dist/types/runtime/i18n/detection/initOptions.d.ts +10 -0
  102. package/dist/types/runtime/i18n/detection/language.d.ts +11 -0
  103. package/dist/types/runtime/i18n/detection/path.d.ts +5 -0
  104. package/dist/types/runtime/i18n/detection/priority.d.ts +10 -0
  105. package/dist/types/runtime/i18n/detection/ssr.d.ts +9 -0
  106. package/dist/types/runtime/i18n/detection/types.d.ts +29 -0
  107. package/dist/types/runtime/i18n/react-i18next.d.ts +1 -6
  108. package/dist/types/runtime/linkHelpers.d.ts +17 -0
  109. package/dist/types/runtime/pluginSetup.d.ts +32 -0
  110. package/dist/types/runtime/providerComposition.d.ts +15 -0
  111. package/dist/types/runtime/reactI18next.d.ts +7 -0
  112. package/dist/types/server/apiPrefix.d.ts +7 -0
  113. package/dist/types/server/detectorOptions.d.ts +21 -0
  114. package/dist/types/server/index.d.ts +1 -6
  115. package/dist/types/server/redirectPolicy.d.ts +16 -0
  116. package/dist/types/shared/localisedUrls/config.d.ts +9 -0
  117. package/dist/types/shared/localisedUrls/index.d.ts +7 -0
  118. package/dist/types/shared/localisedUrls/normalise.d.ts +10 -0
  119. package/dist/types/shared/localisedUrls/pathname.d.ts +3 -0
  120. package/dist/types/shared/localisedUrls/patterns.d.ts +5 -0
  121. package/dist/types/shared/localisedUrls/resolve.d.ts +8 -0
  122. package/dist/types/shared/localisedUrls/routes.d.ts +3 -0
  123. package/dist/types/shared/localisedUrls/types.d.ts +14 -0
  124. package/dist/types/shared/localisedUrls.d.ts +2 -42
  125. package/package.json +10 -10
  126. package/src/cli/index.ts +3 -2
  127. package/src/runtime/Link.tsx +11 -138
  128. package/src/runtime/context.tsx +42 -196
  129. package/src/runtime/contextHelpers.ts +232 -0
  130. package/src/runtime/core.tsx +42 -273
  131. package/src/runtime/i18n/detection/cache.ts +175 -0
  132. package/src/runtime/i18n/detection/detector.ts +157 -0
  133. package/src/runtime/i18n/detection/index.ts +10 -641
  134. package/src/runtime/i18n/detection/initOptions.ts +74 -0
  135. package/src/runtime/i18n/detection/language.ts +64 -0
  136. package/src/runtime/i18n/detection/path.ts +41 -0
  137. package/src/runtime/i18n/detection/priority.ts +82 -0
  138. package/src/runtime/i18n/detection/ssr.ts +47 -0
  139. package/src/runtime/i18n/detection/types.ts +33 -0
  140. package/src/runtime/i18n/react-i18next.ts +1 -6
  141. package/src/runtime/linkHelpers.ts +174 -0
  142. package/src/runtime/pluginSetup.ts +189 -0
  143. package/src/runtime/providerComposition.tsx +142 -0
  144. package/src/runtime/reactI18next.ts +20 -0
  145. package/src/server/apiPrefix.ts +67 -0
  146. package/src/server/detectorOptions.ts +105 -0
  147. package/src/server/index.ts +12 -327
  148. package/src/server/redirectPolicy.ts +152 -0
  149. package/src/shared/localisedUrls/config.ts +18 -0
  150. package/src/shared/localisedUrls/index.ts +13 -0
  151. package/src/shared/localisedUrls/normalise.ts +67 -0
  152. package/src/shared/localisedUrls/pathname.ts +57 -0
  153. package/src/shared/localisedUrls/patterns.ts +160 -0
  154. package/src/shared/localisedUrls/resolve.ts +118 -0
  155. package/src/shared/localisedUrls/routes.ts +226 -0
  156. package/src/shared/localisedUrls/types.ts +18 -0
  157. package/src/shared/localisedUrls.ts +20 -629
  158. package/tests/link.test.tsx +111 -0
  159. package/tests/localisedUrls.test.ts +50 -0
  160. package/tests/reactI18nextRuntimeBoundary.test.ts +5 -2
  161. package/tests/routerAdapter.test.tsx +56 -0
@@ -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
+ });
@@ -28,153 +28,18 @@ var __webpack_require__ = {};
28
28
  var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
30
  __webpack_require__.d(__webpack_exports__, {
31
- collectApiPrefixes: ()=>collectApiPrefixes,
31
+ collectApiPrefixes: ()=>external_apiPrefix_js_namespaceObject.collectApiPrefixes,
32
32
  default: ()=>server,
33
33
  i18nServerPlugin: ()=>i18nServerPlugin,
34
- matchesApiPrefix: ()=>matchesApiPrefix
34
+ matchesApiPrefix: ()=>external_apiPrefix_js_namespaceObject.matchesApiPrefix
35
35
  });
36
36
  const hono_namespaceObject = require("@modern-js/server-core/hono");
37
- const config_js_namespaceObject = require("../runtime/i18n/detection/config.js");
38
37
  const localisedUrls_js_namespaceObject = require("../shared/localisedUrls.js");
39
38
  const utils_js_namespaceObject = require("../shared/utils.js");
39
+ const external_apiPrefix_js_namespaceObject = require("./apiPrefix.js");
40
+ const external_detectorOptions_js_namespaceObject = require("./detectorOptions.js");
41
+ const external_redirectPolicy_js_namespaceObject = require("./redirectPolicy.js");
40
42
  const { languageDetector } = hono_namespaceObject;
41
- const normalizeApiPrefix = (prefix)=>{
42
- const trimmedPrefix = prefix.trim();
43
- if (!trimmedPrefix) return null;
44
- const prefixedPath = trimmedPrefix.startsWith('/') ? trimmedPrefix : `/${trimmedPrefix}`;
45
- const withoutWildcard = prefixedPath.replace(/\/\*$/, '');
46
- const normalizedPrefix = withoutWildcard.length > 1 ? withoutWildcard.replace(/\/+$/, '') : withoutWildcard;
47
- return '/' === normalizedPrefix ? null : normalizedPrefix;
48
- };
49
- const collectApiPrefixes = (routes, bffPrefix)=>{
50
- const prefixes = new Set();
51
- for (const route of routes){
52
- if (!route.isApi || !route.urlPath) continue;
53
- const normalizedPrefix = normalizeApiPrefix(route.urlPath);
54
- if (normalizedPrefix) prefixes.add(normalizedPrefix);
55
- }
56
- const bffPrefixes = Array.isArray(bffPrefix) ? bffPrefix : bffPrefix ? [
57
- bffPrefix
58
- ] : [];
59
- for (const prefix of bffPrefixes){
60
- const normalizedPrefix = normalizeApiPrefix(prefix);
61
- if (normalizedPrefix) prefixes.add(normalizedPrefix);
62
- }
63
- return [
64
- ...prefixes
65
- ];
66
- };
67
- const matchesApiPrefix = (pathname, apiPrefixes)=>{
68
- const normalizedPathname = pathname.startsWith('/') ? pathname : `/${pathname}`;
69
- return apiPrefixes.some((prefix)=>normalizedPathname === prefix || normalizedPathname.startsWith(`${prefix}/`));
70
- };
71
- const convertToHonoLanguageDetectorOptions = (languages, fallbackLanguage, detectionOptions)=>{
72
- const mergedDetection = detectionOptions ? (0, config_js_namespaceObject.mergeDetectionOptions)(detectionOptions) : config_js_namespaceObject.DEFAULT_I18NEXT_DETECTION_OPTIONS;
73
- const order = (mergedDetection.order || []).filter((item)=>![
74
- 'path',
75
- 'localStorage',
76
- 'navigator',
77
- 'htmlTag',
78
- 'subdomain'
79
- ].includes(item));
80
- const detectionOrder = order.length > 0 ? order : [
81
- 'querystring',
82
- 'cookie',
83
- 'header'
84
- ];
85
- const honoOrder = detectionOrder.map((item)=>{
86
- if ('querystring' === item) return 'querystring';
87
- if ('cookie' === item) return 'cookie';
88
- if ('header' === item) return 'header';
89
- return item;
90
- });
91
- const caches = false === mergedDetection.caches ? false : Array.isArray(mergedDetection.caches) && !mergedDetection.caches.includes('cookie') ? false : [
92
- 'cookie'
93
- ];
94
- const cookieMinutes = mergedDetection.cookieMinutes;
95
- const cookieMaxAge = 'number' == typeof cookieMinutes && Number.isFinite(cookieMinutes) ? Math.max(0, Math.floor(60 * cookieMinutes)) : 60 * config_js_namespaceObject.DEFAULT_I18NEXT_DETECTION_OPTIONS.cookieMinutes;
96
- const cookieDomain = mergedDetection.cookieDomain;
97
- const cookieSecure = mergedDetection.cookieSecure;
98
- const cookieHttpOnly = mergedDetection.cookieHttpOnly;
99
- const cookieSameSite = mergedDetection.cookieSameSite;
100
- const normalizedCookieDomain = 'string' == typeof cookieDomain ? cookieDomain : void 0;
101
- const cookieOptions = {
102
- maxAge: cookieMaxAge,
103
- sameSite: 'None' === cookieSameSite || 'none' === cookieSameSite ? 'None' : 'Lax' === cookieSameSite || 'lax' === cookieSameSite ? 'Lax' : 'Strict',
104
- secure: 'boolean' == typeof cookieSecure ? cookieSecure : false,
105
- httpOnly: 'boolean' == typeof cookieHttpOnly ? cookieHttpOnly : false,
106
- ...normalizedCookieDomain ? {
107
- domain: normalizedCookieDomain
108
- } : {}
109
- };
110
- return {
111
- supportedLanguages: languages.length > 0 ? languages : [
112
- fallbackLanguage
113
- ],
114
- fallbackLanguage,
115
- order: honoOrder,
116
- lookupQueryString: mergedDetection.lookupQuerystring || config_js_namespaceObject.DEFAULT_I18NEXT_DETECTION_OPTIONS.lookupQuerystring || 'lng',
117
- lookupCookie: mergedDetection.lookupCookie || config_js_namespaceObject.DEFAULT_I18NEXT_DETECTION_OPTIONS.lookupCookie || 'i18next',
118
- lookupFromHeaderKey: mergedDetection.lookupHeader || config_js_namespaceObject.DEFAULT_I18NEXT_DETECTION_OPTIONS.lookupHeader || 'accept-language',
119
- ...void 0 !== caches && {
120
- caches
121
- },
122
- ...false !== caches && {
123
- cookieOptions
124
- },
125
- ignoreCase: true
126
- };
127
- };
128
- const shouldIgnoreRedirect = (pathname, urlPath, ignoreRedirectRoutes)=>{
129
- if (!ignoreRedirectRoutes) return false;
130
- const basePath = urlPath.replace('/*', '');
131
- const remainingPath = pathname.startsWith(basePath) ? pathname.slice(basePath.length) : pathname;
132
- const normalizedPath = remainingPath.startsWith('/') ? remainingPath : `/${remainingPath}`;
133
- if ('function' == typeof ignoreRedirectRoutes) return ignoreRedirectRoutes(normalizedPath);
134
- return ignoreRedirectRoutes.some((pattern)=>normalizedPath === pattern || normalizedPath.startsWith(`${pattern}/`));
135
- };
136
- const isStaticResourceRequest = (pathname, staticRoutePrefixes, languages = [])=>{
137
- if (staticRoutePrefixes.some((prefix)=>pathname.startsWith(`${prefix}/`) || pathname === prefix)) return true;
138
- const standardStaticPrefixes = [
139
- '/static/',
140
- '/upload/'
141
- ];
142
- if (standardStaticPrefixes.some((prefix)=>pathname.startsWith(prefix))) return true;
143
- const pathSegments = pathname.split('/').filter(Boolean);
144
- if (pathSegments.length > 0 && languages.includes(pathSegments[0])) {
145
- const pathWithoutLang = '/' + pathSegments.slice(1).join('/');
146
- if (standardStaticPrefixes.some((prefix)=>pathWithoutLang.startsWith(prefix)) || staticRoutePrefixes.some((prefix)=>pathWithoutLang.startsWith(`${prefix}/`) || pathWithoutLang === prefix)) return true;
147
- }
148
- return false;
149
- };
150
- const getLanguageFromPath = (req, urlPath, languages)=>{
151
- const url = new URL(req.url, `http://${req.header().host}`);
152
- const pathname = url.pathname;
153
- const basePath = urlPath.replace('/*', '');
154
- const remainingPath = pathname.startsWith(basePath) ? pathname.slice(basePath.length) : pathname;
155
- const segments = remainingPath.split('/').filter(Boolean);
156
- const firstSegment = segments[0];
157
- if (languages.includes(firstSegment)) return firstSegment;
158
- return null;
159
- };
160
- const buildLocalizedUrl = (req, urlPath, language, languages, localisedUrls)=>{
161
- const url = new URL(req.url);
162
- const pathname = url.pathname;
163
- const basePath = urlPath.replace('/*', '');
164
- const remainingPath = pathname.startsWith(basePath) ? pathname.slice(basePath.length) : pathname;
165
- const newPathname = (0, localisedUrls_js_namespaceObject.localiseTargetPathname)(remainingPath, language, languages, localisedUrls);
166
- const suffix = `${url.search}${url.hash}`;
167
- const localizedUrl = '/' === basePath ? newPathname + suffix : basePath + newPathname + suffix;
168
- return localizedUrl;
169
- };
170
- const createLocaleRedirectResponse = (location)=>new Response(null, {
171
- status: 302,
172
- headers: {
173
- 'Cache-Control': 'private, no-store',
174
- Location: location,
175
- Vary: 'Accept-Language, Cookie'
176
- }
177
- });
178
43
  const i18nServerPlugin = (options)=>({
179
44
  name: '@modern-js/plugin-i18n/server',
180
45
  setup: (api)=>{
@@ -182,7 +47,7 @@ const i18nServerPlugin = (options)=>({
182
47
  const { middlewares, routes } = api.getServerContext();
183
48
  const serverConfig = api.getServerConfig();
184
49
  const bffPrefix = serverConfig?.bff ? serverConfig.bff.prefix ?? '/api' : void 0;
185
- const apiPrefixes = collectApiPrefixes(routes, bffPrefix);
50
+ const apiPrefixes = (0, external_apiPrefix_js_namespaceObject.collectApiPrefixes)(routes, bffPrefix);
186
51
  const entryPaths = new Set();
187
52
  routes.forEach((route)=>{
188
53
  if (route.entryName && route.urlPath && '/' !== route.urlPath) {
@@ -200,7 +65,7 @@ const i18nServerPlugin = (options)=>({
200
65
  const urlPath = originUrlPath.endsWith('/') ? `${originUrlPath}*` : `${originUrlPath}/*`;
201
66
  if (localePathRedirect) {
202
67
  if (i18nextDetector) {
203
- const detectorOptions = convertToHonoLanguageDetectorOptions(languages, fallbackLanguage, detection);
68
+ const detectorOptions = (0, external_detectorOptions_js_namespaceObject.convertToHonoLanguageDetectorOptions)(languages, fallbackLanguage, detection);
204
69
  const detectorHandler = languageDetector(detectorOptions);
205
70
  middlewares.push({
206
71
  name: 'i18n-language-detector',
@@ -208,8 +73,8 @@ const i18nServerPlugin = (options)=>({
208
73
  handler: async (c, next)=>{
209
74
  const url = new URL(c.req.url);
210
75
  const pathname = url.pathname;
211
- if (matchesApiPrefix(pathname, apiPrefixes)) return await next();
212
- if (isStaticResourceRequest(pathname, staticRoutePrefixes, languages)) return await next();
76
+ if ((0, external_apiPrefix_js_namespaceObject.matchesApiPrefix)(pathname, apiPrefixes)) return await next();
77
+ if ((0, external_redirectPolicy_js_namespaceObject.isStaticResourceRequest)(pathname, staticRoutePrefixes, languages)) return await next();
213
78
  if ('/' === originUrlPath) {
214
79
  const pathSegments = pathname.split('/').filter(Boolean);
215
80
  if (pathSegments.length > 0) {
@@ -227,9 +92,9 @@ const i18nServerPlugin = (options)=>({
227
92
  handler: async (c, next)=>{
228
93
  const url = new URL(c.req.url);
229
94
  const pathname = url.pathname;
230
- if (matchesApiPrefix(pathname, apiPrefixes)) return await next();
231
- if (isStaticResourceRequest(pathname, staticRoutePrefixes, languages)) return await next();
232
- if (shouldIgnoreRedirect(pathname, urlPath, ignoreRedirectRoutes)) return await next();
95
+ if ((0, external_apiPrefix_js_namespaceObject.matchesApiPrefix)(pathname, apiPrefixes)) return await next();
96
+ if ((0, external_redirectPolicy_js_namespaceObject.isStaticResourceRequest)(pathname, staticRoutePrefixes, languages)) return await next();
97
+ if ((0, external_redirectPolicy_js_namespaceObject.shouldIgnoreRedirect)(pathname, urlPath, ignoreRedirectRoutes)) return await next();
233
98
  if ('/' === originUrlPath) {
234
99
  const pathSegments = pathname.split('/').filter(Boolean);
235
100
  if (pathSegments.length > 0) {
@@ -237,18 +102,18 @@ const i18nServerPlugin = (options)=>({
237
102
  if (entryPaths.has(firstSegment)) return await next();
238
103
  }
239
104
  }
240
- const language = getLanguageFromPath(c.req, urlPath, languages);
105
+ const language = (0, external_redirectPolicy_js_namespaceObject.getLanguageFromPath)(c.req, urlPath, languages);
241
106
  if (!language) {
242
107
  let detectedLanguage = null;
243
108
  if (i18nextDetector) detectedLanguage = c.get('language') || null;
244
109
  const targetLanguage = detectedLanguage || fallbackLanguage;
245
- const localizedUrl = buildLocalizedUrl(c.req, originUrlPath, targetLanguage, languages, localisedUrls);
246
- return createLocaleRedirectResponse(localizedUrl);
110
+ const localizedUrl = (0, external_redirectPolicy_js_namespaceObject.buildLocalizedUrl)(c.req, originUrlPath, targetLanguage, languages, localisedUrls);
111
+ return (0, external_redirectPolicy_js_namespaceObject.createLocaleRedirectResponse)(localizedUrl);
247
112
  }
248
113
  const localisedUrlsConfig = (0, localisedUrls_js_namespaceObject.resolveLocalisedUrlsConfig)(localisedUrls);
249
114
  if (localisedUrlsConfig.enabled) {
250
- const expectedUrl = buildLocalizedUrl(c.req, originUrlPath, language, languages, localisedUrls);
251
- if (expectedUrl !== `${pathname}${url.search}${url.hash}`) return createLocaleRedirectResponse(expectedUrl);
115
+ const expectedUrl = (0, external_redirectPolicy_js_namespaceObject.buildLocalizedUrl)(c.req, originUrlPath, language, languages, localisedUrls);
116
+ if (expectedUrl !== `${pathname}${url.search}${url.hash}`) return (0, external_redirectPolicy_js_namespaceObject.createLocaleRedirectResponse)(expectedUrl);
252
117
  }
253
118
  await next();
254
119
  }
@@ -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
+ buildLocalizedUrl: ()=>buildLocalizedUrl,
32
+ createLocaleRedirectResponse: ()=>createLocaleRedirectResponse,
33
+ getLanguageFromPath: ()=>getLanguageFromPath,
34
+ isStaticResourceRequest: ()=>isStaticResourceRequest,
35
+ shouldIgnoreRedirect: ()=>shouldIgnoreRedirect
36
+ });
37
+ const localisedUrls_js_namespaceObject = require("../shared/localisedUrls.js");
38
+ const shouldIgnoreRedirect = (pathname, urlPath, ignoreRedirectRoutes)=>{
39
+ if (!ignoreRedirectRoutes) return false;
40
+ const basePath = urlPath.replace('/*', '');
41
+ const remainingPath = pathname.startsWith(basePath) ? pathname.slice(basePath.length) : pathname;
42
+ const normalizedPath = remainingPath.startsWith('/') ? remainingPath : `/${remainingPath}`;
43
+ if ('function' == typeof ignoreRedirectRoutes) return ignoreRedirectRoutes(normalizedPath);
44
+ return ignoreRedirectRoutes.some((pattern)=>normalizedPath === pattern || normalizedPath.startsWith(`${pattern}/`));
45
+ };
46
+ const isStaticResourceRequest = (pathname, staticRoutePrefixes, languages = [])=>{
47
+ if (staticRoutePrefixes.some((prefix)=>pathname.startsWith(`${prefix}/`) || pathname === prefix)) return true;
48
+ const standardStaticPrefixes = [
49
+ '/static/',
50
+ '/upload/'
51
+ ];
52
+ if (standardStaticPrefixes.some((prefix)=>pathname.startsWith(prefix))) return true;
53
+ const pathSegments = pathname.split('/').filter(Boolean);
54
+ if (pathSegments.length > 0 && languages.includes(pathSegments[0])) {
55
+ const pathWithoutLang = '/' + pathSegments.slice(1).join('/');
56
+ if (standardStaticPrefixes.some((prefix)=>pathWithoutLang.startsWith(prefix)) || staticRoutePrefixes.some((prefix)=>pathWithoutLang.startsWith(`${prefix}/`) || pathWithoutLang === prefix)) return true;
57
+ }
58
+ return false;
59
+ };
60
+ const getLanguageFromPath = (req, urlPath, languages)=>{
61
+ const url = new URL(req.url, `http://${req.header().host}`);
62
+ const pathname = url.pathname;
63
+ const basePath = urlPath.replace('/*', '');
64
+ const remainingPath = pathname.startsWith(basePath) ? pathname.slice(basePath.length) : pathname;
65
+ const segments = remainingPath.split('/').filter(Boolean);
66
+ const firstSegment = segments[0];
67
+ if (languages.includes(firstSegment)) return firstSegment;
68
+ return null;
69
+ };
70
+ const buildLocalizedUrl = (req, urlPath, language, languages, localisedUrls)=>{
71
+ const url = new URL(req.url);
72
+ const pathname = url.pathname;
73
+ const basePath = urlPath.replace('/*', '');
74
+ const remainingPath = pathname.startsWith(basePath) ? pathname.slice(basePath.length) : pathname;
75
+ const newPathname = (0, localisedUrls_js_namespaceObject.localiseTargetPathname)(remainingPath, language, languages, localisedUrls);
76
+ const suffix = `${url.search}${url.hash}`;
77
+ const localizedUrl = '/' === basePath ? newPathname + suffix : basePath + newPathname + suffix;
78
+ return localizedUrl;
79
+ };
80
+ const createLocaleRedirectResponse = (location)=>new Response(null, {
81
+ status: 302,
82
+ headers: {
83
+ 'Cache-Control': 'private, no-store',
84
+ Location: location,
85
+ Vary: 'Accept-Language, Cookie'
86
+ }
87
+ });
88
+ exports.buildLocalizedUrl = __webpack_exports__.buildLocalizedUrl;
89
+ exports.createLocaleRedirectResponse = __webpack_exports__.createLocaleRedirectResponse;
90
+ exports.getLanguageFromPath = __webpack_exports__.getLanguageFromPath;
91
+ exports.isStaticResourceRequest = __webpack_exports__.isStaticResourceRequest;
92
+ exports.shouldIgnoreRedirect = __webpack_exports__.shouldIgnoreRedirect;
93
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
94
+ "buildLocalizedUrl",
95
+ "createLocaleRedirectResponse",
96
+ "getLanguageFromPath",
97
+ "isStaticResourceRequest",
98
+ "shouldIgnoreRedirect"
99
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
100
+ Object.defineProperty(exports, '__esModule', {
101
+ value: true
102
+ });
@@ -0,0 +1,49 @@
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 resolveLocalisedUrlsConfig = (option)=>{
31
+ if (option && 'object' == typeof option && Object.keys(option).length > 0) return {
32
+ enabled: true,
33
+ map: option
34
+ };
35
+ return {
36
+ enabled: false,
37
+ map: {}
38
+ };
39
+ };
40
+ __webpack_require__.d(__webpack_exports__, {}, {
41
+ resolveLocalisedUrlsConfig: resolveLocalisedUrlsConfig
42
+ });
43
+ exports.resolveLocalisedUrlsConfig = __webpack_exports__.resolveLocalisedUrlsConfig;
44
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
45
+ "resolveLocalisedUrlsConfig"
46
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
47
+ Object.defineProperty(exports, '__esModule', {
48
+ value: true
49
+ });
@@ -0,0 +1,75 @@
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
+ applyLocalisedUrlsToRoutes: ()=>external_routes_js_namespaceObject.applyLocalisedUrlsToRoutes,
32
+ buildPathFromPattern: ()=>external_patterns_js_namespaceObject.buildPathFromPattern,
33
+ canonicalTargetPathname: ()=>external_pathname_js_namespaceObject.canonicalTargetPathname,
34
+ localiseTargetPathname: ()=>external_pathname_js_namespaceObject.localiseTargetPathname,
35
+ matchPathPattern: ()=>external_patterns_js_namespaceObject.matchPathPattern,
36
+ normalisePathPattern: ()=>external_normalise_js_namespaceObject.normalisePathPattern,
37
+ normalisePathname: ()=>external_normalise_js_namespaceObject.normalisePathname,
38
+ resolveCanonicalLocalisedPath: ()=>external_resolve_js_namespaceObject.resolveCanonicalLocalisedPath,
39
+ resolveLocalisedPath: ()=>external_resolve_js_namespaceObject.resolveLocalisedPath,
40
+ resolveLocalisedUrlsConfig: ()=>external_config_js_namespaceObject.resolveLocalisedUrlsConfig,
41
+ validateLocalisedUrls: ()=>external_routes_js_namespaceObject.validateLocalisedUrls
42
+ });
43
+ const external_config_js_namespaceObject = require("./config.js");
44
+ const external_normalise_js_namespaceObject = require("./normalise.js");
45
+ const external_pathname_js_namespaceObject = require("./pathname.js");
46
+ const external_patterns_js_namespaceObject = require("./patterns.js");
47
+ const external_resolve_js_namespaceObject = require("./resolve.js");
48
+ const external_routes_js_namespaceObject = require("./routes.js");
49
+ exports.applyLocalisedUrlsToRoutes = __webpack_exports__.applyLocalisedUrlsToRoutes;
50
+ exports.buildPathFromPattern = __webpack_exports__.buildPathFromPattern;
51
+ exports.canonicalTargetPathname = __webpack_exports__.canonicalTargetPathname;
52
+ exports.localiseTargetPathname = __webpack_exports__.localiseTargetPathname;
53
+ exports.matchPathPattern = __webpack_exports__.matchPathPattern;
54
+ exports.normalisePathPattern = __webpack_exports__.normalisePathPattern;
55
+ exports.normalisePathname = __webpack_exports__.normalisePathname;
56
+ exports.resolveCanonicalLocalisedPath = __webpack_exports__.resolveCanonicalLocalisedPath;
57
+ exports.resolveLocalisedPath = __webpack_exports__.resolveLocalisedPath;
58
+ exports.resolveLocalisedUrlsConfig = __webpack_exports__.resolveLocalisedUrlsConfig;
59
+ exports.validateLocalisedUrls = __webpack_exports__.validateLocalisedUrls;
60
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
61
+ "applyLocalisedUrlsToRoutes",
62
+ "buildPathFromPattern",
63
+ "canonicalTargetPathname",
64
+ "localiseTargetPathname",
65
+ "matchPathPattern",
66
+ "normalisePathPattern",
67
+ "normalisePathname",
68
+ "resolveCanonicalLocalisedPath",
69
+ "resolveLocalisedPath",
70
+ "resolveLocalisedUrlsConfig",
71
+ "validateLocalisedUrls"
72
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
73
+ Object.defineProperty(exports, '__esModule', {
74
+ value: true
75
+ });