@bleedingdev/modern-js-plugin-i18n 3.5.0-ultramodern.9 → 3.5.0-ultramodern.90
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.
- package/dist/cjs/cli/index.js +2 -1
- package/dist/cjs/cli/locales.js +15 -15
- package/dist/cjs/runtime/Link.js +8 -89
- package/dist/cjs/runtime/context.js +78 -91
- package/dist/cjs/runtime/contextHelpers.js +143 -0
- package/dist/cjs/runtime/core.js +32 -132
- package/dist/cjs/runtime/hooks.js +54 -21
- package/dist/cjs/runtime/i18n/backend/defaults.node.js +7 -7
- package/dist/cjs/runtime/i18n/detection/cache.js +150 -0
- package/dist/cjs/runtime/i18n/detection/detector.js +100 -0
- package/dist/cjs/runtime/i18n/detection/index.js +8 -263
- package/dist/cjs/runtime/i18n/detection/initOptions.js +69 -0
- package/dist/cjs/runtime/i18n/detection/language.js +62 -0
- package/dist/cjs/runtime/i18n/detection/path.js +49 -0
- package/dist/cjs/runtime/i18n/detection/priority.js +66 -0
- package/dist/cjs/runtime/i18n/detection/ssr.js +70 -0
- package/dist/cjs/runtime/i18n/detection/types.js +18 -0
- package/dist/cjs/runtime/i18n/instance.js +34 -10
- package/dist/cjs/runtime/linkHelpers.js +148 -0
- package/dist/cjs/runtime/pluginSetup.js +102 -0
- package/dist/cjs/runtime/providerComposition.js +115 -0
- package/dist/cjs/runtime/reactI18next.js +43 -0
- package/dist/cjs/runtime/routerAdapter.js +16 -8
- package/dist/cjs/runtime/utils.js +1 -9
- package/dist/cjs/server/apiPrefix.js +72 -0
- package/dist/cjs/server/detectorOptions.js +97 -0
- package/dist/cjs/server/index.js +17 -144
- package/dist/cjs/server/redirectPolicy.js +96 -0
- package/dist/cjs/shared/detection.js +2 -104
- package/dist/cjs/shared/localisedUrls/config.js +49 -0
- package/dist/cjs/shared/localisedUrls/index.js +91 -0
- package/dist/cjs/shared/localisedUrls/normalise.js +87 -0
- package/dist/cjs/shared/localisedUrls/pathname.js +68 -0
- package/dist/cjs/shared/localisedUrls/patterns.js +130 -0
- package/dist/cjs/shared/localisedUrls/redirect.js +103 -0
- package/dist/cjs/shared/localisedUrls/resolve.js +88 -0
- package/dist/cjs/shared/localisedUrls/routes.js +130 -0
- package/dist/cjs/shared/localisedUrls/types.js +18 -0
- package/dist/cjs/shared/localisedUrls.js +28 -294
- package/dist/cjs/shared/utils.js +2 -8
- package/dist/esm/cli/index.mjs +2 -1
- package/dist/esm/cli/locales.mjs +13 -13
- package/dist/esm/runtime/Link.mjs +1 -82
- package/dist/esm/runtime/context.mjs +76 -92
- package/dist/esm/runtime/contextHelpers.mjs +87 -0
- package/dist/esm/runtime/core.mjs +30 -133
- package/dist/esm/runtime/hooks.mjs +56 -23
- package/dist/esm/runtime/i18n/backend/defaults.node.mjs +5 -5
- package/dist/esm/runtime/i18n/detection/cache.mjs +103 -0
- package/dist/esm/runtime/i18n/detection/detector.mjs +62 -0
- package/dist/esm/runtime/i18n/detection/index.mjs +4 -260
- package/dist/esm/runtime/i18n/detection/initOptions.mjs +28 -0
- package/dist/esm/runtime/i18n/detection/language.mjs +21 -0
- package/dist/esm/runtime/i18n/detection/path.mjs +11 -0
- package/dist/esm/runtime/i18n/detection/priority.mjs +28 -0
- package/dist/esm/runtime/i18n/detection/ssr.mjs +26 -0
- package/dist/esm/runtime/i18n/detection/types.mjs +0 -0
- package/dist/esm/runtime/i18n/instance.mjs +35 -8
- package/dist/esm/runtime/linkHelpers.mjs +98 -0
- package/dist/esm/runtime/pluginSetup.mjs +64 -0
- package/dist/esm/runtime/providerComposition.mjs +77 -0
- package/dist/esm/runtime/reactI18next.mjs +5 -0
- package/dist/esm/runtime/routerAdapter.mjs +16 -8
- package/dist/esm/runtime/utils.mjs +2 -10
- package/dist/esm/server/apiPrefix.mjs +31 -0
- package/dist/esm/server/detectorOptions.mjs +59 -0
- package/dist/esm/server/index.mjs +8 -135
- package/dist/esm/server/redirectPolicy.mjs +46 -0
- package/dist/esm/shared/detection.mjs +1 -71
- package/dist/esm/shared/localisedUrls/config.mjs +11 -0
- package/dist/esm/shared/localisedUrls/index.mjs +7 -0
- package/dist/esm/shared/localisedUrls/normalise.mjs +37 -0
- package/dist/esm/shared/localisedUrls/pathname.mjs +24 -0
- package/dist/esm/shared/localisedUrls/patterns.mjs +86 -0
- package/dist/esm/shared/localisedUrls/redirect.mjs +56 -0
- package/dist/esm/shared/localisedUrls/resolve.mjs +47 -0
- package/dist/esm/shared/localisedUrls/routes.mjs +89 -0
- package/dist/esm/shared/localisedUrls/types.mjs +0 -0
- package/dist/esm/shared/localisedUrls.mjs +1 -283
- package/dist/esm/shared/utils.mjs +1 -1
- package/dist/esm-node/cli/index.mjs +2 -1
- package/dist/esm-node/cli/locales.mjs +13 -13
- package/dist/esm-node/runtime/Link.mjs +1 -82
- package/dist/esm-node/runtime/context.mjs +76 -92
- package/dist/esm-node/runtime/contextHelpers.mjs +88 -0
- package/dist/esm-node/runtime/core.mjs +30 -133
- package/dist/esm-node/runtime/hooks.mjs +56 -23
- package/dist/esm-node/runtime/i18n/backend/defaults.node.mjs +5 -5
- package/dist/esm-node/runtime/i18n/detection/cache.mjs +104 -0
- package/dist/esm-node/runtime/i18n/detection/detector.mjs +63 -0
- package/dist/esm-node/runtime/i18n/detection/index.mjs +4 -260
- package/dist/esm-node/runtime/i18n/detection/initOptions.mjs +29 -0
- package/dist/esm-node/runtime/i18n/detection/language.mjs +22 -0
- package/dist/esm-node/runtime/i18n/detection/path.mjs +12 -0
- package/dist/esm-node/runtime/i18n/detection/priority.mjs +29 -0
- package/dist/esm-node/runtime/i18n/detection/ssr.mjs +27 -0
- package/dist/esm-node/runtime/i18n/detection/types.mjs +1 -0
- package/dist/esm-node/runtime/i18n/instance.mjs +35 -8
- package/dist/esm-node/runtime/linkHelpers.mjs +99 -0
- package/dist/esm-node/runtime/pluginSetup.mjs +65 -0
- package/dist/esm-node/runtime/providerComposition.mjs +78 -0
- package/dist/esm-node/runtime/reactI18next.mjs +6 -0
- package/dist/esm-node/runtime/routerAdapter.mjs +16 -8
- package/dist/esm-node/runtime/utils.mjs +2 -10
- package/dist/esm-node/server/apiPrefix.mjs +32 -0
- package/dist/esm-node/server/detectorOptions.mjs +60 -0
- package/dist/esm-node/server/index.mjs +8 -135
- package/dist/esm-node/server/redirectPolicy.mjs +47 -0
- package/dist/esm-node/shared/detection.mjs +1 -71
- package/dist/esm-node/shared/localisedUrls/config.mjs +12 -0
- package/dist/esm-node/shared/localisedUrls/index.mjs +8 -0
- package/dist/esm-node/shared/localisedUrls/normalise.mjs +38 -0
- package/dist/esm-node/shared/localisedUrls/pathname.mjs +25 -0
- package/dist/esm-node/shared/localisedUrls/patterns.mjs +87 -0
- package/dist/esm-node/shared/localisedUrls/redirect.mjs +57 -0
- package/dist/esm-node/shared/localisedUrls/resolve.mjs +48 -0
- package/dist/esm-node/shared/localisedUrls/routes.mjs +90 -0
- package/dist/esm-node/shared/localisedUrls/types.mjs +1 -0
- package/dist/esm-node/shared/localisedUrls.mjs +1 -283
- package/dist/esm-node/shared/utils.mjs +1 -1
- package/dist/types/cli/locales.d.ts +1 -1
- package/dist/types/runtime/Link.d.ts +3 -7
- package/dist/types/runtime/context.d.ts +21 -5
- package/dist/types/runtime/contextHelpers.d.ts +29 -0
- package/dist/types/runtime/core.d.ts +4 -8
- package/dist/types/runtime/hooks.d.ts +3 -7
- package/dist/types/runtime/i18n/backend/middleware.common.d.ts +2 -1
- package/dist/types/runtime/i18n/detection/cache.d.ts +14 -0
- package/dist/types/runtime/i18n/detection/detector.d.ts +8 -0
- package/dist/types/runtime/i18n/detection/index.d.ts +5 -50
- package/dist/types/runtime/i18n/detection/initOptions.d.ts +10 -0
- package/dist/types/runtime/i18n/detection/language.d.ts +11 -0
- package/dist/types/runtime/i18n/detection/middleware.d.ts +4 -4
- package/dist/types/runtime/i18n/detection/middleware.node.d.ts +4 -4
- package/dist/types/runtime/i18n/detection/path.d.ts +5 -0
- package/dist/types/runtime/i18n/detection/priority.d.ts +10 -0
- package/dist/types/runtime/i18n/detection/ssr.d.ts +9 -0
- package/dist/types/runtime/i18n/detection/types.d.ts +32 -0
- package/dist/types/runtime/i18n/instance.d.ts +31 -27
- package/dist/types/runtime/i18n/react-i18next.d.ts +1 -6
- package/dist/types/runtime/i18n/utils.d.ts +14 -5
- package/dist/types/runtime/linkHelpers.d.ts +17 -0
- package/dist/types/runtime/pluginSetup.d.ts +32 -0
- package/dist/types/runtime/providerComposition.d.ts +16 -0
- package/dist/types/runtime/reactI18next.d.ts +7 -0
- package/dist/types/runtime/routerAdapter.d.ts +7 -6
- package/dist/types/runtime/utils.d.ts +7 -2
- package/dist/types/server/apiPrefix.d.ts +7 -0
- package/dist/types/server/detectorOptions.d.ts +21 -0
- package/dist/types/server/index.d.ts +1 -6
- package/dist/types/server/redirectPolicy.d.ts +22 -0
- package/dist/types/shared/detection.d.ts +1 -11
- package/dist/types/shared/localisedUrls/config.d.ts +9 -0
- package/dist/types/shared/localisedUrls/index.d.ts +9 -0
- package/dist/types/shared/localisedUrls/normalise.d.ts +10 -0
- package/dist/types/shared/localisedUrls/pathname.d.ts +4 -0
- package/dist/types/shared/localisedUrls/patterns.d.ts +5 -0
- package/dist/types/shared/localisedUrls/redirect.d.ts +11 -0
- package/dist/types/shared/localisedUrls/resolve.d.ts +7 -0
- package/dist/types/shared/localisedUrls/routes.d.ts +3 -0
- package/dist/types/shared/localisedUrls/types.d.ts +14 -0
- package/dist/types/shared/localisedUrls.d.ts +2 -36
- package/dist/types/shared/utils.d.ts +0 -2
- package/package.json +17 -20
- package/rstest.config.mts +8 -1
- package/src/cli/index.ts +5 -4
- package/src/cli/locales.ts +3 -3
- package/src/runtime/Link.tsx +11 -138
- package/src/runtime/context.tsx +170 -207
- package/src/runtime/contextHelpers.ts +242 -0
- package/src/runtime/core.tsx +48 -275
- package/src/runtime/hooks.ts +86 -24
- package/src/runtime/i18n/backend/defaults.node.ts +2 -2
- package/src/runtime/i18n/backend/middleware.common.ts +5 -4
- package/src/runtime/i18n/detection/cache.ts +189 -0
- package/src/runtime/i18n/detection/detector.ts +166 -0
- package/src/runtime/i18n/detection/index.ts +10 -641
- package/src/runtime/i18n/detection/initOptions.ts +74 -0
- package/src/runtime/i18n/detection/language.ts +64 -0
- package/src/runtime/i18n/detection/middleware.node.ts +26 -7
- package/src/runtime/i18n/detection/middleware.ts +15 -7
- package/src/runtime/i18n/detection/path.ts +41 -0
- package/src/runtime/i18n/detection/priority.ts +82 -0
- package/src/runtime/i18n/detection/ssr.ts +47 -0
- package/src/runtime/i18n/detection/types.ts +41 -0
- package/src/runtime/i18n/instance.ts +98 -34
- package/src/runtime/i18n/react-i18next.ts +1 -6
- package/src/runtime/i18n/utils.ts +18 -9
- package/src/runtime/linkHelpers.ts +174 -0
- package/src/runtime/pluginSetup.ts +189 -0
- package/src/runtime/providerComposition.tsx +148 -0
- package/src/runtime/reactI18next.ts +20 -0
- package/src/runtime/routerAdapter.tsx +36 -15
- package/src/runtime/utils.ts +13 -35
- package/src/server/apiPrefix.ts +67 -0
- package/src/server/detectorOptions.ts +105 -0
- package/src/server/index.ts +14 -319
- package/src/server/redirectPolicy.ts +127 -0
- package/src/shared/detection.ts +1 -1
- package/src/shared/localisedUrls/config.ts +18 -0
- package/src/shared/localisedUrls/index.ts +24 -0
- package/src/shared/localisedUrls/normalise.ts +67 -0
- package/src/shared/localisedUrls/pathname.ts +60 -0
- package/src/shared/localisedUrls/patterns.ts +160 -0
- package/src/shared/localisedUrls/redirect.ts +93 -0
- package/src/shared/localisedUrls/resolve.ts +135 -0
- package/src/shared/localisedUrls/routes.ts +234 -0
- package/src/shared/localisedUrls/types.ts +18 -0
- package/src/shared/localisedUrls.ts +26 -623
- package/src/shared/utils.ts +2 -2
- package/tests/federatedI18nBoundary.client.test.tsx +112 -0
- package/tests/federatedI18nBoundary.test.tsx +120 -0
- package/tests/fixtures/localised-routes.golden.json +156 -0
- package/tests/link.test.tsx +111 -0
- package/tests/localisedUrlRewriteMatrix.fork.test.ts +147 -0
- package/tests/localisedUrls.test.ts +148 -2
- package/tests/reactI18nextRuntimeBoundary.test.ts +6 -3
- package/tests/redirectPolicy.test.ts +45 -0
- package/tests/routerAdapter.test.tsx +603 -0
- package/tests/type-fixture/fixture-globals.d.ts +11 -0
- package/tests/type-fixture/tsconfig.json +1 -0
|
@@ -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
|
+
});
|
package/dist/cjs/server/index.js
CHANGED
|
@@ -28,145 +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
43
|
const i18nServerPlugin = (options)=>({
|
|
171
44
|
name: '@modern-js/plugin-i18n/server',
|
|
172
45
|
setup: (api)=>{
|
|
@@ -174,7 +47,7 @@ const i18nServerPlugin = (options)=>({
|
|
|
174
47
|
const { middlewares, routes } = api.getServerContext();
|
|
175
48
|
const serverConfig = api.getServerConfig();
|
|
176
49
|
const bffPrefix = serverConfig?.bff ? serverConfig.bff.prefix ?? '/api' : void 0;
|
|
177
|
-
const apiPrefixes = collectApiPrefixes(routes, bffPrefix);
|
|
50
|
+
const apiPrefixes = (0, external_apiPrefix_js_namespaceObject.collectApiPrefixes)(routes, bffPrefix);
|
|
178
51
|
const entryPaths = new Set();
|
|
179
52
|
routes.forEach((route)=>{
|
|
180
53
|
if (route.entryName && route.urlPath && '/' !== route.urlPath) {
|
|
@@ -192,7 +65,7 @@ const i18nServerPlugin = (options)=>({
|
|
|
192
65
|
const urlPath = originUrlPath.endsWith('/') ? `${originUrlPath}*` : `${originUrlPath}/*`;
|
|
193
66
|
if (localePathRedirect) {
|
|
194
67
|
if (i18nextDetector) {
|
|
195
|
-
const detectorOptions = convertToHonoLanguageDetectorOptions(languages, fallbackLanguage, detection);
|
|
68
|
+
const detectorOptions = (0, external_detectorOptions_js_namespaceObject.convertToHonoLanguageDetectorOptions)(languages, fallbackLanguage, detection);
|
|
196
69
|
const detectorHandler = languageDetector(detectorOptions);
|
|
197
70
|
middlewares.push({
|
|
198
71
|
name: 'i18n-language-detector',
|
|
@@ -200,8 +73,8 @@ const i18nServerPlugin = (options)=>({
|
|
|
200
73
|
handler: async (c, next)=>{
|
|
201
74
|
const url = new URL(c.req.url);
|
|
202
75
|
const pathname = url.pathname;
|
|
203
|
-
if (matchesApiPrefix(pathname, apiPrefixes)) return await next();
|
|
204
|
-
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();
|
|
205
78
|
if ('/' === originUrlPath) {
|
|
206
79
|
const pathSegments = pathname.split('/').filter(Boolean);
|
|
207
80
|
if (pathSegments.length > 0) {
|
|
@@ -219,9 +92,9 @@ const i18nServerPlugin = (options)=>({
|
|
|
219
92
|
handler: async (c, next)=>{
|
|
220
93
|
const url = new URL(c.req.url);
|
|
221
94
|
const pathname = url.pathname;
|
|
222
|
-
if (matchesApiPrefix(pathname, apiPrefixes)) return await next();
|
|
223
|
-
if (isStaticResourceRequest(pathname, staticRoutePrefixes, languages)) return await next();
|
|
224
|
-
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();
|
|
225
98
|
if ('/' === originUrlPath) {
|
|
226
99
|
const pathSegments = pathname.split('/').filter(Boolean);
|
|
227
100
|
if (pathSegments.length > 0) {
|
|
@@ -229,18 +102,18 @@ const i18nServerPlugin = (options)=>({
|
|
|
229
102
|
if (entryPaths.has(firstSegment)) return await next();
|
|
230
103
|
}
|
|
231
104
|
}
|
|
232
|
-
const language = getLanguageFromPath(c.req, urlPath, languages);
|
|
105
|
+
const language = (0, external_redirectPolicy_js_namespaceObject.getLanguageFromPath)(c.req, urlPath, languages);
|
|
233
106
|
if (!language) {
|
|
234
107
|
let detectedLanguage = null;
|
|
235
108
|
if (i18nextDetector) detectedLanguage = c.get('language') || null;
|
|
236
109
|
const targetLanguage = detectedLanguage || fallbackLanguage;
|
|
237
|
-
const localizedUrl = buildLocalizedUrl(c.req, originUrlPath, targetLanguage, languages, localisedUrls);
|
|
238
|
-
return
|
|
110
|
+
const localizedUrl = (0, external_redirectPolicy_js_namespaceObject.buildLocalizedUrl)(c.req, originUrlPath, targetLanguage, languages, localisedUrls);
|
|
111
|
+
return (0, external_redirectPolicy_js_namespaceObject.createLocaleRedirectResponse)(localizedUrl);
|
|
239
112
|
}
|
|
240
113
|
const localisedUrlsConfig = (0, localisedUrls_js_namespaceObject.resolveLocalisedUrlsConfig)(localisedUrls);
|
|
241
114
|
if (localisedUrlsConfig.enabled) {
|
|
242
|
-
const expectedUrl = buildLocalizedUrl(c.req, originUrlPath, language, languages, localisedUrls);
|
|
243
|
-
if (expectedUrl !== `${pathname}${url.search}${url.hash}`) return
|
|
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);
|
|
244
117
|
}
|
|
245
118
|
await next();
|
|
246
119
|
}
|
|
@@ -0,0 +1,96 @@
|
|
|
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 stripUrlPathPrefix = (pathname, urlPath)=>{
|
|
39
|
+
const basePath = urlPath.replace('/*', '');
|
|
40
|
+
if (!basePath || '/' === basePath) return pathname;
|
|
41
|
+
const remainingPath = pathname.startsWith(basePath) ? pathname.slice(basePath.length) : pathname;
|
|
42
|
+
return remainingPath || '/';
|
|
43
|
+
};
|
|
44
|
+
const shouldIgnoreRedirect = (pathname, urlPath, ignoreRedirectRoutes)=>{
|
|
45
|
+
const remainingPath = stripUrlPathPrefix(pathname, urlPath);
|
|
46
|
+
return (0, localisedUrls_js_namespaceObject.shouldSkipLocaleRedirect)(remainingPath, [], ignoreRedirectRoutes);
|
|
47
|
+
};
|
|
48
|
+
const isStaticResourceRequest = (pathname, staticRoutePrefixes, languages = [])=>{
|
|
49
|
+
if ((0, localisedUrls_js_namespaceObject.isDefaultLocaleRedirectSkipPath)(pathname, languages)) return true;
|
|
50
|
+
const matchesStaticRoutePrefix = (targetPathname)=>staticRoutePrefixes.some((prefix)=>(0, localisedUrls_js_namespaceObject.matchesPathPrefix)(targetPathname, prefix));
|
|
51
|
+
if (matchesStaticRoutePrefix(pathname)) return true;
|
|
52
|
+
const pathWithoutLanguage = (0, localisedUrls_js_namespaceObject.stripLanguagePrefix)(pathname, languages);
|
|
53
|
+
return pathWithoutLanguage !== pathname && matchesStaticRoutePrefix(pathWithoutLanguage);
|
|
54
|
+
};
|
|
55
|
+
const getLanguageFromPath = (req, urlPath, languages)=>{
|
|
56
|
+
const url = new URL(req.url, `http://${req.header().host}`);
|
|
57
|
+
const pathname = url.pathname;
|
|
58
|
+
const remainingPath = stripUrlPathPrefix(pathname, urlPath);
|
|
59
|
+
const segments = remainingPath.split('/').filter(Boolean);
|
|
60
|
+
const firstSegment = segments[0];
|
|
61
|
+
if (languages.includes(firstSegment)) return firstSegment;
|
|
62
|
+
return null;
|
|
63
|
+
};
|
|
64
|
+
const buildLocalizedUrl = (req, urlPath, language, languages, localisedUrls)=>{
|
|
65
|
+
const url = new URL(req.url);
|
|
66
|
+
const pathname = url.pathname;
|
|
67
|
+
const basePath = urlPath.replace('/*', '');
|
|
68
|
+
const remainingPath = stripUrlPathPrefix(pathname, urlPath);
|
|
69
|
+
const newPathname = (0, localisedUrls_js_namespaceObject.localiseTargetPathname)(remainingPath, language, languages, localisedUrls);
|
|
70
|
+
const suffix = `${url.search}${url.hash}`;
|
|
71
|
+
const localizedUrl = '/' === basePath ? newPathname + suffix : basePath + newPathname + suffix;
|
|
72
|
+
return localizedUrl;
|
|
73
|
+
};
|
|
74
|
+
const createLocaleRedirectResponse = (location)=>new Response(null, {
|
|
75
|
+
status: 302,
|
|
76
|
+
headers: {
|
|
77
|
+
'Cache-Control': 'private, no-store',
|
|
78
|
+
Location: location,
|
|
79
|
+
Vary: 'Accept-Language, Cookie'
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
exports.buildLocalizedUrl = __webpack_exports__.buildLocalizedUrl;
|
|
83
|
+
exports.createLocaleRedirectResponse = __webpack_exports__.createLocaleRedirectResponse;
|
|
84
|
+
exports.getLanguageFromPath = __webpack_exports__.getLanguageFromPath;
|
|
85
|
+
exports.isStaticResourceRequest = __webpack_exports__.isStaticResourceRequest;
|
|
86
|
+
exports.shouldIgnoreRedirect = __webpack_exports__.shouldIgnoreRedirect;
|
|
87
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
88
|
+
"buildLocalizedUrl",
|
|
89
|
+
"createLocaleRedirectResponse",
|
|
90
|
+
"getLanguageFromPath",
|
|
91
|
+
"isStaticResourceRequest",
|
|
92
|
+
"shouldIgnoreRedirect"
|
|
93
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
94
|
+
Object.defineProperty(exports, '__esModule', {
|
|
95
|
+
value: true
|
|
96
|
+
});
|
|
@@ -1,109 +1,7 @@
|
|
|
1
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
2
|
var __webpack_exports__ = {};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
detectLanguageFromRequest: ()=>detectLanguageFromRequest
|
|
32
|
-
});
|
|
33
|
-
const config_js_namespaceObject = require("../runtime/i18n/detection/config.js");
|
|
34
|
-
function detectLanguageFromRequest(req, languages, detectionOptions) {
|
|
35
|
-
try {
|
|
36
|
-
const mergedDetection = detectionOptions ? (0, config_js_namespaceObject.mergeDetectionOptions)(detectionOptions) : config_js_namespaceObject.DEFAULT_I18NEXT_DETECTION_OPTIONS;
|
|
37
|
-
const order = (mergedDetection.order || []).filter((item)=>![
|
|
38
|
-
'path',
|
|
39
|
-
'localStorage',
|
|
40
|
-
'navigator',
|
|
41
|
-
'htmlTag',
|
|
42
|
-
'subdomain'
|
|
43
|
-
].includes(item));
|
|
44
|
-
const detectionOrder = order.length > 0 ? order : [
|
|
45
|
-
'querystring',
|
|
46
|
-
'cookie',
|
|
47
|
-
'header'
|
|
48
|
-
];
|
|
49
|
-
const getHeader = (name)=>{
|
|
50
|
-
req.headers, Headers;
|
|
51
|
-
return req.headers.get(name);
|
|
52
|
-
};
|
|
53
|
-
for (const method of detectionOrder){
|
|
54
|
-
let detectedLang = null;
|
|
55
|
-
switch(method){
|
|
56
|
-
case 'querystring':
|
|
57
|
-
{
|
|
58
|
-
const lookupKey = mergedDetection.lookupQuerystring || config_js_namespaceObject.DEFAULT_I18NEXT_DETECTION_OPTIONS.lookupQuerystring || 'lng';
|
|
59
|
-
const host = getHeader('host') || 'localhost';
|
|
60
|
-
const url = new URL(req.url, `http://${host}`);
|
|
61
|
-
detectedLang = url.searchParams.get(lookupKey);
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
case 'cookie':
|
|
65
|
-
{
|
|
66
|
-
const lookupKey = mergedDetection.lookupCookie || config_js_namespaceObject.DEFAULT_I18NEXT_DETECTION_OPTIONS.lookupCookie || 'i18next';
|
|
67
|
-
const cookieHeader = getHeader('Cookie');
|
|
68
|
-
if (cookieHeader) {
|
|
69
|
-
const cookies = cookieHeader.split(';').reduce((acc, item)=>{
|
|
70
|
-
const [key, value] = item.trim().split('=');
|
|
71
|
-
if (key && value) acc[key] = value;
|
|
72
|
-
return acc;
|
|
73
|
-
}, {});
|
|
74
|
-
detectedLang = cookies[lookupKey] || null;
|
|
75
|
-
}
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
case 'header':
|
|
79
|
-
{
|
|
80
|
-
const lookupKey = mergedDetection.lookupHeader || config_js_namespaceObject.DEFAULT_I18NEXT_DETECTION_OPTIONS.lookupHeader || 'accept-language';
|
|
81
|
-
const acceptLanguage = getHeader(lookupKey);
|
|
82
|
-
if (acceptLanguage) {
|
|
83
|
-
const languagesList = acceptLanguage.split(',').map((lang)=>{
|
|
84
|
-
const [code, q] = lang.trim().split(';');
|
|
85
|
-
return {
|
|
86
|
-
code: code.split('-')[0],
|
|
87
|
-
quality: q ? parseFloat(q.split('=')[1]) : 1.0
|
|
88
|
-
};
|
|
89
|
-
}).sort((a, b)=>b.quality - a.quality);
|
|
90
|
-
for (const lang of languagesList)if (0 === languages.length || languages.includes(lang.code)) {
|
|
91
|
-
detectedLang = lang.code;
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
break;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
if (detectedLang && (0 === languages.length || languages.includes(detectedLang))) return detectedLang;
|
|
99
|
-
}
|
|
100
|
-
} catch (error) {}
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
exports.detectLanguageFromRequest = __webpack_exports__.detectLanguageFromRequest;
|
|
104
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
105
|
-
"detectLanguageFromRequest"
|
|
106
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
3
|
+
require("../runtime/i18n/detection/config.js");
|
|
4
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
107
5
|
Object.defineProperty(exports, '__esModule', {
|
|
108
6
|
value: true
|
|
109
7
|
});
|
|
@@ -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,91 @@
|
|
|
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
|
+
DEFAULT_LOCALE_REDIRECT_SKIP_RULES: ()=>external_redirect_js_namespaceObject.DEFAULT_LOCALE_REDIRECT_SKIP_RULES,
|
|
32
|
+
applyLocalisedUrlsToRoutes: ()=>external_routes_js_namespaceObject.applyLocalisedUrlsToRoutes,
|
|
33
|
+
buildPathFromPattern: ()=>external_patterns_js_namespaceObject.buildPathFromPattern,
|
|
34
|
+
canonicalTargetPathname: ()=>external_pathname_js_namespaceObject.canonicalTargetPathname,
|
|
35
|
+
isDefaultLocaleRedirectSkipPath: ()=>external_redirect_js_namespaceObject.isDefaultLocaleRedirectSkipPath,
|
|
36
|
+
localiseTargetPathname: ()=>external_pathname_js_namespaceObject.localiseTargetPathname,
|
|
37
|
+
matchPathPattern: ()=>external_patterns_js_namespaceObject.matchPathPattern,
|
|
38
|
+
matchesPathPrefix: ()=>external_redirect_js_namespaceObject.matchesPathPrefix,
|
|
39
|
+
normalisePathPattern: ()=>external_normalise_js_namespaceObject.normalisePathPattern,
|
|
40
|
+
normalisePathname: ()=>external_normalise_js_namespaceObject.normalisePathname,
|
|
41
|
+
resolveCanonicalLocalisedPath: ()=>external_resolve_js_namespaceObject.resolveCanonicalLocalisedPath,
|
|
42
|
+
resolveLocalisedPath: ()=>external_resolve_js_namespaceObject.resolveLocalisedPath,
|
|
43
|
+
resolveLocalisedUrlsConfig: ()=>external_config_js_namespaceObject.resolveLocalisedUrlsConfig,
|
|
44
|
+
shouldSkipLocaleRedirect: ()=>external_redirect_js_namespaceObject.shouldSkipLocaleRedirect,
|
|
45
|
+
stripLanguagePrefix: ()=>external_pathname_js_namespaceObject.stripLanguagePrefix,
|
|
46
|
+
validateLocalisedUrls: ()=>external_routes_js_namespaceObject.validateLocalisedUrls
|
|
47
|
+
});
|
|
48
|
+
const external_config_js_namespaceObject = require("./config.js");
|
|
49
|
+
const external_normalise_js_namespaceObject = require("./normalise.js");
|
|
50
|
+
const external_pathname_js_namespaceObject = require("./pathname.js");
|
|
51
|
+
const external_patterns_js_namespaceObject = require("./patterns.js");
|
|
52
|
+
const external_redirect_js_namespaceObject = require("./redirect.js");
|
|
53
|
+
const external_resolve_js_namespaceObject = require("./resolve.js");
|
|
54
|
+
const external_routes_js_namespaceObject = require("./routes.js");
|
|
55
|
+
exports.DEFAULT_LOCALE_REDIRECT_SKIP_RULES = __webpack_exports__.DEFAULT_LOCALE_REDIRECT_SKIP_RULES;
|
|
56
|
+
exports.applyLocalisedUrlsToRoutes = __webpack_exports__.applyLocalisedUrlsToRoutes;
|
|
57
|
+
exports.buildPathFromPattern = __webpack_exports__.buildPathFromPattern;
|
|
58
|
+
exports.canonicalTargetPathname = __webpack_exports__.canonicalTargetPathname;
|
|
59
|
+
exports.isDefaultLocaleRedirectSkipPath = __webpack_exports__.isDefaultLocaleRedirectSkipPath;
|
|
60
|
+
exports.localiseTargetPathname = __webpack_exports__.localiseTargetPathname;
|
|
61
|
+
exports.matchPathPattern = __webpack_exports__.matchPathPattern;
|
|
62
|
+
exports.matchesPathPrefix = __webpack_exports__.matchesPathPrefix;
|
|
63
|
+
exports.normalisePathPattern = __webpack_exports__.normalisePathPattern;
|
|
64
|
+
exports.normalisePathname = __webpack_exports__.normalisePathname;
|
|
65
|
+
exports.resolveCanonicalLocalisedPath = __webpack_exports__.resolveCanonicalLocalisedPath;
|
|
66
|
+
exports.resolveLocalisedPath = __webpack_exports__.resolveLocalisedPath;
|
|
67
|
+
exports.resolveLocalisedUrlsConfig = __webpack_exports__.resolveLocalisedUrlsConfig;
|
|
68
|
+
exports.shouldSkipLocaleRedirect = __webpack_exports__.shouldSkipLocaleRedirect;
|
|
69
|
+
exports.stripLanguagePrefix = __webpack_exports__.stripLanguagePrefix;
|
|
70
|
+
exports.validateLocalisedUrls = __webpack_exports__.validateLocalisedUrls;
|
|
71
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
72
|
+
"DEFAULT_LOCALE_REDIRECT_SKIP_RULES",
|
|
73
|
+
"applyLocalisedUrlsToRoutes",
|
|
74
|
+
"buildPathFromPattern",
|
|
75
|
+
"canonicalTargetPathname",
|
|
76
|
+
"isDefaultLocaleRedirectSkipPath",
|
|
77
|
+
"localiseTargetPathname",
|
|
78
|
+
"matchPathPattern",
|
|
79
|
+
"matchesPathPrefix",
|
|
80
|
+
"normalisePathPattern",
|
|
81
|
+
"normalisePathname",
|
|
82
|
+
"resolveCanonicalLocalisedPath",
|
|
83
|
+
"resolveLocalisedPath",
|
|
84
|
+
"resolveLocalisedUrlsConfig",
|
|
85
|
+
"shouldSkipLocaleRedirect",
|
|
86
|
+
"stripLanguagePrefix",
|
|
87
|
+
"validateLocalisedUrls"
|
|
88
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
89
|
+
Object.defineProperty(exports, '__esModule', {
|
|
90
|
+
value: true
|
|
91
|
+
});
|