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

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 (119) 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 +264 -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 +47 -8
  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 +102 -0
  27. package/dist/cjs/runtime/routerAdapter.js +167 -0
  28. package/dist/cjs/runtime/utils.js +80 -97
  29. package/dist/cjs/server/index.js +62 -14
  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 +351 -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 +221 -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 +24 -3
  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 +55 -0
  48. package/dist/esm/runtime/routerAdapter.mjs +129 -0
  49. package/dist/esm/runtime/utils.mjs +19 -31
  50. package/dist/esm/server/index.mjs +46 -8
  51. package/dist/esm/shared/localisedUrls.mjs +283 -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 +222 -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 +24 -3
  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 +56 -0
  66. package/dist/esm-node/runtime/routerAdapter.mjs +130 -0
  67. package/dist/esm-node/runtime/utils.mjs +19 -31
  68. package/dist/esm-node/server/index.mjs +46 -8
  69. package/dist/esm-node/shared/localisedUrls.mjs +284 -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 +66 -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/defaults.node.d.ts +3 -2
  77. package/dist/types/runtime/i18n/backend/middleware.node.d.ts +1 -1
  78. package/dist/types/runtime/i18n/instance.d.ts +4 -6
  79. package/dist/types/runtime/i18n/react-i18next.d.ts +7 -0
  80. package/dist/types/runtime/index.d.ts +6 -1
  81. package/dist/types/runtime/localizedPaths.d.ts +39 -0
  82. package/dist/types/runtime/routerAdapter.d.ts +26 -0
  83. package/dist/types/runtime/types.d.ts +1 -1
  84. package/dist/types/runtime/utils.d.ts +13 -9
  85. package/dist/types/server/index.d.ts +6 -0
  86. package/dist/types/shared/localisedUrls.d.ts +36 -0
  87. package/dist/types/shared/type.d.ts +14 -0
  88. package/package.json +24 -24
  89. package/rstest.config.mts +44 -0
  90. package/src/cli/index.ts +44 -1
  91. package/src/runtime/I18nLink.tsx +14 -51
  92. package/src/runtime/Link.tsx +430 -0
  93. package/src/runtime/canonicalRoutes.ts +93 -0
  94. package/src/runtime/context.tsx +45 -7
  95. package/src/runtime/hooks.ts +13 -4
  96. package/src/runtime/i18n/backend/defaults.node.ts +40 -2
  97. package/src/runtime/i18n/backend/defaults.ts +3 -1
  98. package/src/runtime/i18n/backend/middleware.node.ts +1 -1
  99. package/src/runtime/i18n/instance.ts +3 -30
  100. package/src/runtime/i18n/react-i18next.ts +25 -0
  101. package/src/runtime/i18n/utils.ts +4 -26
  102. package/src/runtime/index.tsx +47 -12
  103. package/src/runtime/localizedPaths.ts +107 -0
  104. package/src/runtime/routerAdapter.tsx +332 -0
  105. package/src/runtime/types.ts +1 -1
  106. package/src/runtime/utils.ts +33 -38
  107. package/src/server/index.ts +108 -11
  108. package/src/shared/localisedUrls.ts +623 -0
  109. package/src/shared/type.ts +14 -0
  110. package/tests/backendDefaults.test.ts +51 -0
  111. package/tests/i18nUtils.test.ts +59 -0
  112. package/tests/link.test.tsx +525 -0
  113. package/tests/linkTypes.test.ts +28 -0
  114. package/tests/localisedUrls.test.ts +536 -0
  115. package/tests/routerAdapter.test.tsx +456 -0
  116. package/tests/type-fixture/linkTypes.fixture.tsx +51 -0
  117. package/tests/type-fixture/tsconfig.json +15 -0
  118. package/dist/esm/rslib-runtime.mjs +0 -18
  119. package/dist/esm-node/rslib-runtime.mjs +0 -19
@@ -1,25 +1,15 @@
1
1
  "use strict";
2
- var __webpack_modules__ = {
3
- "@modern-js/runtime/router" (module) {
4
- module.exports = require("@modern-js/runtime/router");
5
- }
6
- };
7
- var __webpack_module_cache__ = {};
8
- function __webpack_require__(moduleId) {
9
- var cachedModule = __webpack_module_cache__[moduleId];
10
- if (void 0 !== cachedModule) return cachedModule.exports;
11
- var module = __webpack_module_cache__[moduleId] = {
12
- exports: {}
13
- };
14
- __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
15
- return module.exports;
16
- }
2
+ var __webpack_require__ = {};
17
3
  (()=>{
18
- __webpack_require__.d = (exports1, definition)=>{
19
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
20
- enumerable: true,
21
- get: definition[key]
22
- });
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");
23
13
  };
24
14
  })();
25
15
  (()=>{
@@ -36,92 +26,85 @@ function __webpack_require__(moduleId) {
36
26
  };
37
27
  })();
38
28
  var __webpack_exports__ = {};
39
- (()=>{
40
- __webpack_require__.r(__webpack_exports__);
41
- __webpack_require__.d(__webpack_exports__, {
42
- buildLocalizedUrl: ()=>buildLocalizedUrl,
43
- detectLanguageFromPath: ()=>detectLanguageFromPath,
44
- getEntryPath: ()=>getEntryPath,
45
- getLanguageFromPath: ()=>getLanguageFromPath,
46
- getPathname: ()=>getPathname,
47
- shouldIgnoreRedirect: ()=>shouldIgnoreRedirect,
48
- useRouterHooks: ()=>useRouterHooks
49
- });
50
- const runtime_namespaceObject = require("@modern-js/runtime");
51
- const context_namespaceObject = require("@modern-js/runtime/context");
52
- const getPathname = (context)=>{
53
- if ((0, runtime_namespaceObject.isBrowser)()) return window.location.pathname;
54
- return context.ssrContext?.request?.pathname || '/';
55
- };
56
- const getEntryPath = ()=>{
57
- const basename = (0, context_namespaceObject.getGlobalBasename)();
58
- if (basename) return '/' === basename ? '' : basename;
59
- return '';
60
- };
61
- const getLanguageFromPath = (pathname, languages, fallbackLanguage)=>{
62
- const segments = pathname.split('/').filter(Boolean);
63
- const firstSegment = segments[0];
64
- if (languages.includes(firstSegment)) return firstSegment;
65
- return fallbackLanguage;
66
- };
67
- const buildLocalizedUrl = (pathname, language, languages)=>{
68
- const segments = pathname.split('/').filter(Boolean);
69
- if (segments.length > 0 && languages.includes(segments[0])) segments[0] = language;
70
- else segments.unshift(language);
71
- return `/${segments.join('/')}`;
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ buildLocalizedUrl: ()=>buildLocalizedUrl,
32
+ detectLanguageFromPath: ()=>detectLanguageFromPath,
33
+ getEntryPath: ()=>getEntryPath,
34
+ getLanguageFromPath: ()=>getLanguageFromPath,
35
+ getPathname: ()=>getPathname,
36
+ shouldIgnoreRedirect: ()=>shouldIgnoreRedirect,
37
+ splitUrlTarget: ()=>splitUrlTarget
38
+ });
39
+ const runtime_namespaceObject = require("@modern-js/runtime");
40
+ const context_namespaceObject = require("@modern-js/runtime/context");
41
+ const localisedUrls_js_namespaceObject = require("../shared/localisedUrls.js");
42
+ const getPathname = (context)=>{
43
+ if ((0, runtime_namespaceObject.isBrowser)()) return window.location.pathname;
44
+ return context.ssrContext?.request?.pathname || '/';
45
+ };
46
+ const getEntryPath = ()=>{
47
+ const basename = (0, context_namespaceObject.getGlobalBasename)();
48
+ if (basename) return '/' === basename ? '' : basename;
49
+ return '';
50
+ };
51
+ const getLanguageFromPath = (pathname, languages, fallbackLanguage)=>{
52
+ const segments = pathname.split('/').filter(Boolean);
53
+ const firstSegment = segments[0];
54
+ if (languages.includes(firstSegment)) return firstSegment;
55
+ return fallbackLanguage;
56
+ };
57
+ const splitUrlTarget = (target)=>{
58
+ const hashIndex = target.indexOf('#');
59
+ const hash = hashIndex >= 0 ? target.slice(hashIndex) : '';
60
+ const beforeHash = hashIndex >= 0 ? target.slice(0, hashIndex) : target;
61
+ const searchIndex = beforeHash.indexOf('?');
62
+ const search = searchIndex >= 0 ? beforeHash.slice(searchIndex) : '';
63
+ const pathname = searchIndex >= 0 ? beforeHash.slice(0, searchIndex) : beforeHash;
64
+ return {
65
+ pathname,
66
+ search,
67
+ hash
72
68
  };
73
- const detectLanguageFromPath = (pathname, languages, localePathRedirect)=>{
74
- if (!localePathRedirect) return {
75
- detected: false
76
- };
77
- const entryPath = getEntryPath();
78
- const relativePath = pathname.replace(entryPath, '');
79
- const segments = relativePath.split('/').filter(Boolean);
80
- const segmentsToCheck = !entryPath && segments.length > 1 && segments[0] && !languages.includes(segments[0]) ? segments.slice(1) : segments;
81
- const firstSegment = segmentsToCheck[0];
82
- if (firstSegment && languages.includes(firstSegment)) return {
83
- detected: true,
84
- language: firstSegment
85
- };
86
- return {
87
- detected: false
88
- };
69
+ };
70
+ const buildLocalizedUrl = (target, language, languages, localisedUrls)=>{
71
+ const { pathname, search, hash } = splitUrlTarget(target);
72
+ const localizedPathname = (0, localisedUrls_js_namespaceObject.localiseTargetPathname)(pathname, language, languages, localisedUrls);
73
+ return `${localizedPathname}${search}${hash}`;
74
+ };
75
+ const detectLanguageFromPath = (pathname, languages, localePathRedirect)=>{
76
+ if (!localePathRedirect) return {
77
+ detected: false
89
78
  };
90
- const shouldIgnoreRedirect = (pathname, languages, ignoreRedirectRoutes)=>{
91
- if (!ignoreRedirectRoutes) return false;
92
- const segments = pathname.split('/').filter(Boolean);
93
- let pathWithoutLang = pathname;
94
- if (segments.length > 0 && languages.includes(segments[0])) pathWithoutLang = `/${segments.slice(1).join('/')}`;
95
- const normalizedPath = pathWithoutLang.startsWith('/') ? pathWithoutLang : `/${pathWithoutLang}`;
96
- if ('function' == typeof ignoreRedirectRoutes) return ignoreRedirectRoutes(normalizedPath);
97
- return ignoreRedirectRoutes.some((pattern)=>normalizedPath === pattern || normalizedPath.startsWith(`${pattern}/`));
79
+ const entryPath = getEntryPath();
80
+ const relativePath = pathname.replace(entryPath, '');
81
+ const segments = relativePath.split('/').filter(Boolean);
82
+ const segmentsToCheck = !entryPath && segments.length > 1 && segments[0] && !languages.includes(segments[0]) ? segments.slice(1) : segments;
83
+ const firstSegment = segmentsToCheck[0];
84
+ if (firstSegment && languages.includes(firstSegment)) return {
85
+ detected: true,
86
+ language: firstSegment
98
87
  };
99
- const useRouterHooks = ()=>{
100
- try {
101
- const { useLocation, useNavigate, useParams } = __webpack_require__("@modern-js/runtime/router");
102
- return {
103
- navigate: useNavigate(),
104
- location: useLocation(),
105
- params: useParams(),
106
- hasRouter: true
107
- };
108
- } catch (error) {
109
- return {
110
- navigate: null,
111
- location: null,
112
- params: {},
113
- hasRouter: false
114
- };
115
- }
88
+ return {
89
+ detected: false
116
90
  };
117
- })();
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
+ };
118
101
  exports.buildLocalizedUrl = __webpack_exports__.buildLocalizedUrl;
119
102
  exports.detectLanguageFromPath = __webpack_exports__.detectLanguageFromPath;
120
103
  exports.getEntryPath = __webpack_exports__.getEntryPath;
121
104
  exports.getLanguageFromPath = __webpack_exports__.getLanguageFromPath;
122
105
  exports.getPathname = __webpack_exports__.getPathname;
123
106
  exports.shouldIgnoreRedirect = __webpack_exports__.shouldIgnoreRedirect;
124
- exports.useRouterHooks = __webpack_exports__.useRouterHooks;
107
+ exports.splitUrlTarget = __webpack_exports__.splitUrlTarget;
125
108
  for(var __rspack_i in __webpack_exports__)if (-1 === [
126
109
  "buildLocalizedUrl",
127
110
  "detectLanguageFromPath",
@@ -129,7 +112,7 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
129
112
  "getLanguageFromPath",
130
113
  "getPathname",
131
114
  "shouldIgnoreRedirect",
132
- "useRouterHooks"
115
+ "splitUrlTarget"
133
116
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
134
117
  Object.defineProperty(exports, '__esModule', {
135
118
  value: true
@@ -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
  (()=>{
@@ -24,13 +28,46 @@ var __webpack_require__ = {};
24
28
  var __webpack_exports__ = {};
25
29
  __webpack_require__.r(__webpack_exports__);
26
30
  __webpack_require__.d(__webpack_exports__, {
31
+ collectApiPrefixes: ()=>collectApiPrefixes,
27
32
  default: ()=>server,
28
- i18nServerPlugin: ()=>i18nServerPlugin
33
+ i18nServerPlugin: ()=>i18nServerPlugin,
34
+ matchesApiPrefix: ()=>matchesApiPrefix
29
35
  });
30
36
  const hono_namespaceObject = require("@modern-js/server-core/hono");
31
37
  const config_js_namespaceObject = require("../runtime/i18n/detection/config.js");
38
+ const localisedUrls_js_namespaceObject = require("../shared/localisedUrls.js");
32
39
  const utils_js_namespaceObject = require("../shared/utils.js");
33
40
  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
+ };
34
71
  const convertToHonoLanguageDetectorOptions = (languages, fallbackLanguage, detectionOptions)=>{
35
72
  const mergedDetection = detectionOptions ? (0, config_js_namespaceObject.mergeDetectionOptions)(detectionOptions) : config_js_namespaceObject.DEFAULT_I18NEXT_DETECTION_OPTIONS;
36
73
  const order = (mergedDetection.order || []).filter((item)=>![
@@ -120,15 +157,12 @@ const getLanguageFromPath = (req, urlPath, languages)=>{
120
157
  if (languages.includes(firstSegment)) return firstSegment;
121
158
  return null;
122
159
  };
123
- const buildLocalizedUrl = (req, urlPath, language, languages)=>{
160
+ const buildLocalizedUrl = (req, urlPath, language, languages, localisedUrls)=>{
124
161
  const url = new URL(req.url);
125
162
  const pathname = url.pathname;
126
163
  const basePath = urlPath.replace('/*', '');
127
164
  const remainingPath = pathname.startsWith(basePath) ? pathname.slice(basePath.length) : pathname;
128
- const segments = remainingPath.split('/').filter(Boolean);
129
- if (segments.length > 0 && languages.includes(segments[0])) segments[0] = language;
130
- else segments.unshift(language);
131
- const newPathname = `/${segments.join('/')}`;
165
+ const newPathname = (0, localisedUrls_js_namespaceObject.localiseTargetPathname)(remainingPath, language, languages, localisedUrls);
132
166
  const suffix = `${url.search}${url.hash}`;
133
167
  const localizedUrl = '/' === basePath ? newPathname + suffix : basePath + newPathname + suffix;
134
168
  return localizedUrl;
@@ -138,6 +172,9 @@ const i18nServerPlugin = (options)=>({
138
172
  setup: (api)=>{
139
173
  api.onPrepare(()=>{
140
174
  const { middlewares, routes } = api.getServerContext();
175
+ const serverConfig = api.getServerConfig();
176
+ const bffPrefix = serverConfig?.bff ? serverConfig.bff.prefix ?? '/api' : void 0;
177
+ const apiPrefixes = collectApiPrefixes(routes, bffPrefix);
141
178
  const entryPaths = new Set();
142
179
  routes.forEach((route)=>{
143
180
  if (route.entryName && route.urlPath && '/' !== route.urlPath) {
@@ -149,7 +186,7 @@ const i18nServerPlugin = (options)=>({
149
186
  const { entryName } = route;
150
187
  if (!entryName) return;
151
188
  if (!options.localeDetection) return;
152
- const { localePathRedirect, i18nextDetector = true, languages = [], fallbackLanguage = 'en', detection, ignoreRedirectRoutes } = (0, utils_js_namespaceObject.getLocaleDetectionOptions)(entryName, options.localeDetection);
189
+ const { localePathRedirect, i18nextDetector = true, languages = [], fallbackLanguage = 'en', detection, ignoreRedirectRoutes, localisedUrls } = (0, utils_js_namespaceObject.getLocaleDetectionOptions)(entryName, options.localeDetection);
153
190
  const staticRoutePrefixes = options.staticRoutePrefixes;
154
191
  const originUrlPath = route.urlPath;
155
192
  const urlPath = originUrlPath.endsWith('/') ? `${originUrlPath}*` : `${originUrlPath}/*`;
@@ -163,6 +200,7 @@ const i18nServerPlugin = (options)=>({
163
200
  handler: async (c, next)=>{
164
201
  const url = new URL(c.req.url);
165
202
  const pathname = url.pathname;
203
+ if (matchesApiPrefix(pathname, apiPrefixes)) return await next();
166
204
  if (isStaticResourceRequest(pathname, staticRoutePrefixes, languages)) return await next();
167
205
  if ('/' === originUrlPath) {
168
206
  const pathSegments = pathname.split('/').filter(Boolean);
@@ -181,6 +219,7 @@ const i18nServerPlugin = (options)=>({
181
219
  handler: async (c, next)=>{
182
220
  const url = new URL(c.req.url);
183
221
  const pathname = url.pathname;
222
+ if (matchesApiPrefix(pathname, apiPrefixes)) return await next();
184
223
  if (isStaticResourceRequest(pathname, staticRoutePrefixes, languages)) return await next();
185
224
  if (shouldIgnoreRedirect(pathname, urlPath, ignoreRedirectRoutes)) return await next();
186
225
  if ('/' === originUrlPath) {
@@ -195,9 +234,14 @@ const i18nServerPlugin = (options)=>({
195
234
  let detectedLanguage = null;
196
235
  if (i18nextDetector) detectedLanguage = c.get('language') || null;
197
236
  const targetLanguage = detectedLanguage || fallbackLanguage;
198
- const localizedUrl = buildLocalizedUrl(c.req, originUrlPath, targetLanguage, languages);
237
+ const localizedUrl = buildLocalizedUrl(c.req, originUrlPath, targetLanguage, languages, localisedUrls);
199
238
  return c.redirect(localizedUrl);
200
239
  }
240
+ const localisedUrlsConfig = (0, localisedUrls_js_namespaceObject.resolveLocalisedUrlsConfig)(localisedUrls);
241
+ if (localisedUrlsConfig.enabled) {
242
+ const expectedUrl = buildLocalizedUrl(c.req, originUrlPath, language, languages, localisedUrls);
243
+ if (expectedUrl !== `${pathname}${url.search}${url.hash}`) return c.redirect(expectedUrl);
244
+ }
201
245
  await next();
202
246
  }
203
247
  });
@@ -207,11 +251,15 @@ const i18nServerPlugin = (options)=>({
207
251
  }
208
252
  });
209
253
  const server = i18nServerPlugin;
254
+ exports.collectApiPrefixes = __webpack_exports__.collectApiPrefixes;
210
255
  exports["default"] = __webpack_exports__["default"];
211
256
  exports.i18nServerPlugin = __webpack_exports__.i18nServerPlugin;
257
+ exports.matchesApiPrefix = __webpack_exports__.matchesApiPrefix;
212
258
  for(var __rspack_i in __webpack_exports__)if (-1 === [
259
+ "collectApiPrefixes",
213
260
  "default",
214
- "i18nServerPlugin"
261
+ "i18nServerPlugin",
262
+ "matchesApiPrefix"
215
263
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
216
264
  Object.defineProperty(exports, '__esModule', {
217
265
  value: true
@@ -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,9 +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
- deepMerge: ()=>deepMerge
28
- });
29
30
  function isPlainObject(value) {
30
31
  return null !== value && 'object' == typeof value && !Array.isArray(value) && !(value instanceof Date);
31
32
  }
@@ -45,6 +46,9 @@ function deepMerge(defaultOptions, userOptions) {
45
46
  }
46
47
  return merged;
47
48
  }
49
+ __webpack_require__.d(__webpack_exports__, {
50
+ deepMerge: ()=>deepMerge
51
+ });
48
52
  exports.deepMerge = __webpack_exports__.deepMerge;
49
53
  for(var __rspack_i in __webpack_exports__)if (-1 === [
50
54
  "deepMerge"
@@ -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
  (()=>{