@bleedingdev/modern-js-i18n-runtime-extensions 3.9.0-ultramodern.9 → 3.9.3-ultramodern.2
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/index.js +10 -10
- package/dist/cjs/localeRedirectPolicy.js +6 -6
- package/dist/cjs/native.js +160 -0
- package/dist/cjs/paths.js +11 -3
- package/dist/cjs/requestLanguage.js +195 -0
- package/dist/cjs/router-navigation/adapter.js +93 -0
- package/dist/cjs/{localisedUrls/config.js → router-navigation/index.js} +5 -14
- package/dist/cjs/ssrLanguageHandoff.js +94 -0
- package/dist/cjs/urlRewrite.js +64 -0
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/localeRedirectPolicy.mjs +1 -1
- package/dist/esm/native.mjs +112 -0
- package/dist/esm/paths.mjs +7 -2
- package/dist/esm/requestLanguage.mjs +148 -0
- package/dist/esm/router-navigation/adapter.mjs +55 -0
- package/dist/esm/router-navigation/index.mjs +1 -0
- package/dist/esm/ssrLanguageHandoff.mjs +44 -0
- package/dist/esm/urlRewrite.mjs +26 -0
- package/dist/esm-node/index.mjs +1 -1
- package/dist/esm-node/localeRedirectPolicy.mjs +1 -1
- package/dist/esm-node/native.mjs +113 -0
- package/dist/esm-node/paths.mjs +7 -2
- package/dist/esm-node/requestLanguage.mjs +149 -0
- package/dist/esm-node/router-navigation/adapter.mjs +56 -0
- package/dist/esm-node/router-navigation/index.mjs +2 -0
- package/dist/esm-node/ssrLanguageHandoff.mjs +45 -0
- package/dist/esm-node/urlRewrite.mjs +27 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/localeRedirectPolicy.d.ts +1 -1
- package/dist/types/native.d.ts +21 -0
- package/dist/types/paths.d.ts +8 -1
- package/dist/types/requestLanguage.d.ts +60 -0
- package/dist/types/router-navigation/adapter.d.ts +23 -0
- package/dist/types/router-navigation/index.d.ts +1 -0
- package/dist/types/ssrLanguageHandoff.d.ts +60 -0
- package/dist/types/urlRewrite.d.ts +60 -0
- package/package.json +101 -14
- package/src/index.ts +1 -1
- package/src/localeRedirectPolicy.ts +2 -2
- package/src/native.ts +212 -0
- package/src/paths.ts +23 -2
- package/src/requestLanguage.ts +311 -0
- package/src/router-navigation/adapter.tsx +120 -0
- package/src/router-navigation/index.ts +6 -0
- package/src/ssrLanguageHandoff.ts +138 -0
- package/src/urlRewrite.ts +107 -0
- package/dist/cjs/localisedUrls/index.js +0 -98
- package/dist/cjs/localisedUrls/normalise.js +0 -87
- package/dist/cjs/localisedUrls/pathname.js +0 -68
- package/dist/cjs/localisedUrls/patterns.js +0 -214
- package/dist/cjs/localisedUrls/redirect.js +0 -100
- package/dist/cjs/localisedUrls/resolve.js +0 -78
- package/dist/cjs/localisedUrls/routeIdentity.js +0 -118
- package/dist/cjs/localisedUrls/routes.js +0 -210
- package/dist/cjs/localisedUrls/types.js +0 -18
- package/dist/esm/localisedUrls/config.mjs +0 -11
- package/dist/esm/localisedUrls/index.mjs +0 -8
- package/dist/esm/localisedUrls/normalise.mjs +0 -37
- package/dist/esm/localisedUrls/pathname.mjs +0 -24
- package/dist/esm/localisedUrls/patterns.mjs +0 -152
- package/dist/esm/localisedUrls/redirect.mjs +0 -53
- package/dist/esm/localisedUrls/resolve.mjs +0 -37
- package/dist/esm/localisedUrls/routeIdentity.mjs +0 -77
- package/dist/esm/localisedUrls/routes.mjs +0 -169
- package/dist/esm/localisedUrls/types.mjs +0 -0
- package/dist/esm-node/localisedUrls/config.mjs +0 -12
- package/dist/esm-node/localisedUrls/index.mjs +0 -9
- package/dist/esm-node/localisedUrls/normalise.mjs +0 -38
- package/dist/esm-node/localisedUrls/pathname.mjs +0 -25
- package/dist/esm-node/localisedUrls/patterns.mjs +0 -153
- package/dist/esm-node/localisedUrls/redirect.mjs +0 -54
- package/dist/esm-node/localisedUrls/resolve.mjs +0 -38
- package/dist/esm-node/localisedUrls/routeIdentity.mjs +0 -78
- package/dist/esm-node/localisedUrls/routes.mjs +0 -170
- package/dist/esm-node/localisedUrls/types.mjs +0 -1
- package/dist/types/localisedUrls/config.d.ts +0 -9
- package/dist/types/localisedUrls/index.d.ts +0 -10
- package/dist/types/localisedUrls/normalise.d.ts +0 -10
- package/dist/types/localisedUrls/pathname.d.ts +0 -4
- package/dist/types/localisedUrls/patterns.d.ts +0 -11
- package/dist/types/localisedUrls/redirect.d.ts +0 -19
- package/dist/types/localisedUrls/resolve.d.ts +0 -7
- package/dist/types/localisedUrls/routeIdentity.d.ts +0 -24
- package/dist/types/localisedUrls/routes.d.ts +0 -3
- package/dist/types/localisedUrls/types.d.ts +0 -14
- package/rslib.config.mts +0 -4
- package/rstest.config.mts +0 -36
- package/src/localisedUrls/config.ts +0 -18
- package/src/localisedUrls/index.ts +0 -28
- package/src/localisedUrls/normalise.ts +0 -62
- package/src/localisedUrls/pathname.ts +0 -60
- package/src/localisedUrls/patterns.ts +0 -283
- package/src/localisedUrls/redirect.ts +0 -107
- package/src/localisedUrls/resolve.ts +0 -106
- package/src/localisedUrls/routeIdentity.ts +0 -107
- package/src/localisedUrls/routes.ts +0 -432
- package/src/localisedUrls/types.ts +0 -18
- package/tests/languageSyncController.test.ts +0 -136
- package/tests/localeRedirectPolicy.test.ts +0 -173
- package/tests/localisedUrls.test.ts +0 -532
- package/tests/paths.test.ts +0 -24
- package/tests/reactLanguageSync.test.tsx +0 -136
- package/tests/tsconfig.json +0 -11
- package/tsconfig.json +0 -11
package/dist/cjs/index.js
CHANGED
|
@@ -9,8 +9,8 @@ var __webpack_modules__ = {
|
|
|
9
9
|
"./localeRedirectPolicy" (module) {
|
|
10
10
|
module.exports = require("./localeRedirectPolicy.js");
|
|
11
11
|
},
|
|
12
|
-
"
|
|
13
|
-
module.exports = require("
|
|
12
|
+
"@modern-js/runtime-extensions/localised-urls" (module) {
|
|
13
|
+
module.exports = require("@modern-js/runtime-extensions/localised-urls");
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
16
|
var __webpack_module_cache__ = {};
|
|
@@ -60,21 +60,21 @@ function __webpack_require__(moduleId) {
|
|
|
60
60
|
var __webpack_exports__ = {};
|
|
61
61
|
(()=>{
|
|
62
62
|
__webpack_require__.r(__webpack_exports__);
|
|
63
|
-
var
|
|
63
|
+
var _modern_js_runtime_extensions_localised_urls__rspack_import_0 = __webpack_require__("@modern-js/runtime-extensions/localised-urls");
|
|
64
64
|
var __rspack_reexport = {};
|
|
65
|
-
for(const __rspack_import_key in
|
|
65
|
+
for(const __rspack_import_key in _modern_js_runtime_extensions_localised_urls__rspack_import_0)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_modern_js_runtime_extensions_localised_urls__rspack_import_0[__rspack_import_key];
|
|
66
66
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
67
|
-
var
|
|
67
|
+
var _language_sync_controller__rspack_import_1 = __webpack_require__("./language-sync/controller");
|
|
68
68
|
var __rspack_reexport = {};
|
|
69
|
-
for(const __rspack_import_key in
|
|
69
|
+
for(const __rspack_import_key in _language_sync_controller__rspack_import_1)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_language_sync_controller__rspack_import_1[__rspack_import_key];
|
|
70
70
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
71
|
-
var
|
|
71
|
+
var _language_sync_react__rspack_import_2 = __webpack_require__("./language-sync/react");
|
|
72
72
|
var __rspack_reexport = {};
|
|
73
|
-
for(const __rspack_import_key in
|
|
73
|
+
for(const __rspack_import_key in _language_sync_react__rspack_import_2)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_language_sync_react__rspack_import_2[__rspack_import_key];
|
|
74
74
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
75
|
-
var
|
|
75
|
+
var _localeRedirectPolicy__rspack_import_3 = __webpack_require__("./localeRedirectPolicy");
|
|
76
76
|
var __rspack_reexport = {};
|
|
77
|
-
for(const __rspack_import_key in
|
|
77
|
+
for(const __rspack_import_key in _localeRedirectPolicy__rspack_import_3)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_localeRedirectPolicy__rspack_import_3[__rspack_import_key];
|
|
78
78
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
79
79
|
})();
|
|
80
80
|
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
@@ -34,7 +34,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
34
34
|
isStaticResourceRequest: ()=>isStaticResourceRequest,
|
|
35
35
|
shouldIgnoreRedirect: ()=>shouldIgnoreRedirect
|
|
36
36
|
});
|
|
37
|
-
const
|
|
37
|
+
const localised_urls_namespaceObject = require("@modern-js/runtime-extensions/localised-urls");
|
|
38
38
|
const stripUrlPathPrefix = (pathname, urlPath)=>{
|
|
39
39
|
const basePath = urlPath.replace('/*', '');
|
|
40
40
|
if (!basePath || '/' === basePath) return pathname;
|
|
@@ -43,13 +43,13 @@ const stripUrlPathPrefix = (pathname, urlPath)=>{
|
|
|
43
43
|
};
|
|
44
44
|
const shouldIgnoreRedirect = (pathname, urlPath, ignoreRedirectRoutes)=>{
|
|
45
45
|
const remainingPath = stripUrlPathPrefix(pathname, urlPath);
|
|
46
|
-
return (0,
|
|
46
|
+
return (0, localised_urls_namespaceObject.shouldSkipLocaleRedirect)(remainingPath, [], ignoreRedirectRoutes);
|
|
47
47
|
};
|
|
48
48
|
const isStaticResourceRequest = (pathname, staticRoutePrefixes, languages = [])=>{
|
|
49
|
-
if ((0,
|
|
50
|
-
const matchesStaticRoutePrefix = (targetPathname)=>staticRoutePrefixes.some((prefix)=>(0,
|
|
49
|
+
if ((0, localised_urls_namespaceObject.isDefaultLocaleRedirectSkipPath)(pathname, languages)) return true;
|
|
50
|
+
const matchesStaticRoutePrefix = (targetPathname)=>staticRoutePrefixes.some((prefix)=>(0, localised_urls_namespaceObject.matchesPathPrefix)(targetPathname, prefix));
|
|
51
51
|
if (matchesStaticRoutePrefix(pathname)) return true;
|
|
52
|
-
const pathWithoutLanguage = (0,
|
|
52
|
+
const pathWithoutLanguage = (0, localised_urls_namespaceObject.stripLanguagePrefix)(pathname, languages);
|
|
53
53
|
return pathWithoutLanguage !== pathname && matchesStaticRoutePrefix(pathWithoutLanguage);
|
|
54
54
|
};
|
|
55
55
|
const getLanguageFromPath = (req, urlPath, languages)=>{
|
|
@@ -66,7 +66,7 @@ const buildLocalizedUrl = (req, urlPath, language, languages, localisedUrls)=>{
|
|
|
66
66
|
const pathname = url.pathname;
|
|
67
67
|
const basePath = urlPath.replace('/*', '');
|
|
68
68
|
const remainingPath = stripUrlPathPrefix(pathname, urlPath);
|
|
69
|
-
const newPathname = (0,
|
|
69
|
+
const newPathname = (0, localised_urls_namespaceObject.localiseTargetPathname)(remainingPath, language, languages, localisedUrls);
|
|
70
70
|
const suffix = `${url.search}${url.hash}`;
|
|
71
71
|
const localizedUrl = '/' === basePath ? newPathname + suffix : basePath + newPathname + suffix;
|
|
72
72
|
return localizedUrl;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
14
|
+
var define = (defs, kind)=>{
|
|
15
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
[kind]: defs[key]
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
define(getters, "get");
|
|
21
|
+
define(values, "value");
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
(()=>{
|
|
25
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
26
|
+
})();
|
|
27
|
+
(()=>{
|
|
28
|
+
__webpack_require__.r = (exports1)=>{
|
|
29
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
30
|
+
value: 'Module'
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
33
|
+
value: true
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
var __webpack_exports__ = {};
|
|
38
|
+
__webpack_require__.r(__webpack_exports__);
|
|
39
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
40
|
+
createNativeI18n: ()=>createNativeI18n
|
|
41
|
+
});
|
|
42
|
+
const external_i18next_namespaceObject = require("i18next");
|
|
43
|
+
var external_i18next_default = /*#__PURE__*/ __webpack_require__.n(external_i18next_namespaceObject);
|
|
44
|
+
const controller_js_namespaceObject = require("./language-sync/controller.js");
|
|
45
|
+
const external_requestLanguage_js_namespaceObject = require("./requestLanguage.js");
|
|
46
|
+
const external_ssrLanguageHandoff_js_namespaceObject = require("./ssrLanguageHandoff.js");
|
|
47
|
+
const external_urlRewrite_js_namespaceObject = require("./urlRewrite.js");
|
|
48
|
+
function unwrapResource(module) {
|
|
49
|
+
const resource = 'object' == typeof module && null !== module && 'default' in module ? module.default : module;
|
|
50
|
+
return resource;
|
|
51
|
+
}
|
|
52
|
+
function createNativeI18n(options, loaders) {
|
|
53
|
+
const { initOptions = {}, ...routing } = options;
|
|
54
|
+
const namespaces = [
|
|
55
|
+
...new Set(Object.values(loaders).flatMap(Object.keys))
|
|
56
|
+
].sort();
|
|
57
|
+
const defaultNamespace = 'string' == typeof initOptions.defaultNS ? initOptions.defaultNS : namespaces.includes('translation') ? 'translation' : namespaces[0] ?? 'translation';
|
|
58
|
+
const cookie = routing.detection?.lookupCookie ?? 'i18next';
|
|
59
|
+
const backend = {
|
|
60
|
+
type: 'backend',
|
|
61
|
+
init () {},
|
|
62
|
+
read (language, namespace, callback) {
|
|
63
|
+
const bundles = Object.hasOwn(loaders, language) ? loaders[language] : void 0;
|
|
64
|
+
const load = bundles && Object.hasOwn(bundles, namespace) ? bundles[namespace] : void 0;
|
|
65
|
+
if (!load) return void callback(null, {});
|
|
66
|
+
load().then((module)=>callback(null, unwrapResource(module)), (error)=>callback(error, false));
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const currentLanguage = ()=>(0, external_requestLanguage_js_namespaceObject.languageFromPathname)(window.location.pathname, routing.languages, routing.basePath);
|
|
70
|
+
return {
|
|
71
|
+
languages: routing.languages,
|
|
72
|
+
...void 0 === routing.localisedUrls ? {} : {
|
|
73
|
+
localisedUrls: routing.localisedUrls
|
|
74
|
+
},
|
|
75
|
+
resolveRequest: (request)=>(0, external_requestLanguage_js_namespaceObject.resolveRequestLanguage)(request, routing),
|
|
76
|
+
redirect: external_requestLanguage_js_namespaceObject.createRequestLanguageRedirect,
|
|
77
|
+
async create (language, resources) {
|
|
78
|
+
const instance = external_i18next_default().createInstance();
|
|
79
|
+
instance.use(backend);
|
|
80
|
+
await instance.init({
|
|
81
|
+
...initOptions,
|
|
82
|
+
lng: language,
|
|
83
|
+
fallbackLng: routing.fallbackLanguage,
|
|
84
|
+
supportedLngs: [
|
|
85
|
+
...routing.languages
|
|
86
|
+
],
|
|
87
|
+
ns: namespaces,
|
|
88
|
+
defaultNS: defaultNamespace,
|
|
89
|
+
partialBundledLanguages: true,
|
|
90
|
+
resources: resources ? {
|
|
91
|
+
[language]: resources
|
|
92
|
+
} : {},
|
|
93
|
+
interpolation: {
|
|
94
|
+
escapeValue: false,
|
|
95
|
+
...initOptions.interpolation
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
return instance;
|
|
99
|
+
},
|
|
100
|
+
rewrite: (getLanguage)=>(0, external_urlRewrite_js_namespaceObject.createI18nUrlRewrite)({
|
|
101
|
+
languages: routing.languages,
|
|
102
|
+
getLanguage,
|
|
103
|
+
localisedUrls: routing.localisedUrls
|
|
104
|
+
}),
|
|
105
|
+
handoff (language, instance) {
|
|
106
|
+
return (0, external_ssrLanguageHandoff_js_namespaceObject.createI18nSsrHandoffInlineData)({
|
|
107
|
+
language,
|
|
108
|
+
...instance ? {
|
|
109
|
+
resources: Object.fromEntries(namespaces.map((namespace)=>[
|
|
110
|
+
namespace,
|
|
111
|
+
instance.getResourceBundle(language, namespace) ?? {}
|
|
112
|
+
]))
|
|
113
|
+
} : {}
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
clientHandoff () {
|
|
117
|
+
const handoff = (0, external_ssrLanguageHandoff_js_namespaceObject.readI18nSsrHandoff)();
|
|
118
|
+
if (handoff && routing.languages.includes(handoff.language)) return handoff;
|
|
119
|
+
return {
|
|
120
|
+
language: currentLanguage() ?? routing.fallbackLanguage
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
syncWithRouter (router, instance) {
|
|
124
|
+
const sync = (0, controller_js_namespaceObject.createLatestLanguageSyncBinding)();
|
|
125
|
+
sync.updateCallbacks({
|
|
126
|
+
changeLanguage: (target, language)=>target.changeLanguage(language),
|
|
127
|
+
commitLanguage () {},
|
|
128
|
+
readLanguage: (target)=>target.language,
|
|
129
|
+
reportFailure: ()=>window.location.reload()
|
|
130
|
+
});
|
|
131
|
+
sync.activate(instance);
|
|
132
|
+
const unsubscribe = router.subscribe('onBeforeLoad', ({ toLocation })=>{
|
|
133
|
+
const publicHref = toLocation.maskedLocation?.publicHref ?? toLocation.publicHref;
|
|
134
|
+
const pathname = new URL(publicHref, window.location.origin).pathname;
|
|
135
|
+
const language = (0, external_requestLanguage_js_namespaceObject.languageFromPathname)(pathname, routing.languages, routing.basePath);
|
|
136
|
+
if (language) sync.request(language);
|
|
137
|
+
});
|
|
138
|
+
return ()=>{
|
|
139
|
+
unsubscribe();
|
|
140
|
+
sync.deactivate();
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
persist (instance) {
|
|
144
|
+
const persist = (language)=>{
|
|
145
|
+
document.documentElement.lang = language;
|
|
146
|
+
document.cookie = `${cookie}=${encodeURIComponent(language)}; path=/; max-age=31536000; samesite=lax`;
|
|
147
|
+
};
|
|
148
|
+
if (instance.language) persist(instance.language);
|
|
149
|
+
instance.on('languageChanged', persist);
|
|
150
|
+
return ()=>instance.off('languageChanged', persist);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
exports.createNativeI18n = __webpack_exports__.createNativeI18n;
|
|
155
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
156
|
+
"createNativeI18n"
|
|
157
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
158
|
+
Object.defineProperty(exports, '__esModule', {
|
|
159
|
+
value: true
|
|
160
|
+
});
|
package/dist/cjs/paths.js
CHANGED
|
@@ -30,25 +30,33 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
30
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
31
31
|
buildLocalizedUrl: ()=>buildLocalizedUrl,
|
|
32
32
|
canonicalPath: ()=>canonicalPath,
|
|
33
|
+
configuredLanguage: ()=>configuredLanguage,
|
|
33
34
|
localizePath: ()=>localizePath
|
|
34
35
|
});
|
|
36
|
+
const localised_urls_namespaceObject = require("@modern-js/runtime-extensions/localised-urls");
|
|
35
37
|
const url_namespaceObject = require("@modern-js/runtime-utils/url");
|
|
36
|
-
const
|
|
38
|
+
const configuredLanguage = (requested, languages)=>{
|
|
39
|
+
const language = languages.find((candidate)=>candidate.toLowerCase() === String(requested).toLowerCase());
|
|
40
|
+
if (void 0 === language) throw new RangeError(`Unsupported language "${requested}"; expected one of: ${languages.join(', ')}`);
|
|
41
|
+
return language;
|
|
42
|
+
};
|
|
37
43
|
const buildLocalizedUrl = (target, language, languages, localisedUrls)=>{
|
|
38
44
|
const { pathname, search, hash } = (0, url_namespaceObject.splitUrlTarget)(target);
|
|
39
|
-
return `${(0,
|
|
45
|
+
return `${(0, localised_urls_namespaceObject.localiseTargetPathname)(pathname, language, languages, localisedUrls)}${search}${hash}`;
|
|
40
46
|
};
|
|
41
47
|
const localizePath = (target, language, config)=>buildLocalizedUrl(target, language, config.languages, config.localisedUrls);
|
|
42
48
|
const canonicalPath = (target, config)=>{
|
|
43
49
|
const { pathname, search, hash } = (0, url_namespaceObject.splitUrlTarget)(target);
|
|
44
|
-
return `${(0,
|
|
50
|
+
return `${(0, localised_urls_namespaceObject.canonicalTargetPathname)(pathname, config.languages, config.localisedUrls)}${search}${hash}`;
|
|
45
51
|
};
|
|
46
52
|
exports.buildLocalizedUrl = __webpack_exports__.buildLocalizedUrl;
|
|
47
53
|
exports.canonicalPath = __webpack_exports__.canonicalPath;
|
|
54
|
+
exports.configuredLanguage = __webpack_exports__.configuredLanguage;
|
|
48
55
|
exports.localizePath = __webpack_exports__.localizePath;
|
|
49
56
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
50
57
|
"buildLocalizedUrl",
|
|
51
58
|
"canonicalPath",
|
|
59
|
+
"configuredLanguage",
|
|
52
60
|
"localizePath"
|
|
53
61
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
54
62
|
Object.defineProperty(exports, '__esModule', {
|
|
@@ -0,0 +1,195 @@
|
|
|
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
|
+
createRequestLanguageRedirect: ()=>createRequestLanguageRedirect,
|
|
32
|
+
detectRequestLanguage: ()=>detectRequestLanguage,
|
|
33
|
+
languageFromPathname: ()=>languageFromPathname,
|
|
34
|
+
resolveRequestLanguage: ()=>resolveRequestLanguage
|
|
35
|
+
});
|
|
36
|
+
const localised_urls_namespaceObject = require("@modern-js/runtime-extensions/localised-urls");
|
|
37
|
+
const DEFAULT_ORDER = [
|
|
38
|
+
'querystring',
|
|
39
|
+
'cookie',
|
|
40
|
+
'header'
|
|
41
|
+
];
|
|
42
|
+
const normaliseBasePath = (basePath)=>{
|
|
43
|
+
if (!basePath || '/' === basePath) return '';
|
|
44
|
+
return `/${basePath.split('/').filter(Boolean).join('/')}`;
|
|
45
|
+
};
|
|
46
|
+
const entryPathname = (pathname, basePath)=>{
|
|
47
|
+
const base = normaliseBasePath(basePath);
|
|
48
|
+
if (!base) return pathname || '/';
|
|
49
|
+
if (pathname === base) return '/';
|
|
50
|
+
return pathname.startsWith(`${base}/`) ? pathname.slice(base.length) : void 0;
|
|
51
|
+
};
|
|
52
|
+
const baseLanguage = (tag)=>tag.toLowerCase().split(/[-_]/u)[0];
|
|
53
|
+
const compatibleLanguages = (candidate, languages)=>{
|
|
54
|
+
const value = candidate?.trim().toLowerCase();
|
|
55
|
+
if (!value) return [];
|
|
56
|
+
const base = baseLanguage(value);
|
|
57
|
+
return [
|
|
58
|
+
...languages.filter((language)=>language.toLowerCase() === value),
|
|
59
|
+
...languages.filter((language)=>language.toLowerCase() === base),
|
|
60
|
+
...base === value ? languages.filter((language)=>baseLanguage(language) === value) : []
|
|
61
|
+
].filter((language, index, all)=>all.indexOf(language) === index);
|
|
62
|
+
};
|
|
63
|
+
const matchLanguage = (candidate, languages)=>compatibleLanguages(candidate, languages)[0];
|
|
64
|
+
function languageFromPathname(pathname, languages, basePath) {
|
|
65
|
+
const remaining = entryPathname(pathname, basePath);
|
|
66
|
+
if (void 0 === remaining) return;
|
|
67
|
+
const first = remaining.split('/').filter(Boolean)[0];
|
|
68
|
+
if (!first) return;
|
|
69
|
+
return languages.find((language)=>language.toLowerCase() === first.toLowerCase());
|
|
70
|
+
}
|
|
71
|
+
const readCookie = (header, name)=>{
|
|
72
|
+
if (!header) return null;
|
|
73
|
+
for (const part of header.split(';')){
|
|
74
|
+
const separator = part.indexOf('=');
|
|
75
|
+
if (separator < 0) continue;
|
|
76
|
+
if (part.slice(0, separator).trim() !== name) continue;
|
|
77
|
+
const raw = part.slice(separator + 1).trim();
|
|
78
|
+
try {
|
|
79
|
+
return decodeURIComponent(raw);
|
|
80
|
+
} catch {
|
|
81
|
+
return raw;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
};
|
|
86
|
+
const QVALUE = /^(?:0(?:\.\d{0,3})?|1(?:\.0{0,3})?)$/;
|
|
87
|
+
const rangeSpecificity = (range, language)=>{
|
|
88
|
+
const value = range.toLowerCase().replaceAll('_', '-');
|
|
89
|
+
const supported = language.toLowerCase().replaceAll('_', '-');
|
|
90
|
+
if ('*' === value) return 0;
|
|
91
|
+
if (value === supported) return Number.MAX_SAFE_INTEGER;
|
|
92
|
+
if (supported.startsWith(`${value}-`)) return 1 + value.split('-').length;
|
|
93
|
+
if (baseLanguage(value) === supported) return 1;
|
|
94
|
+
};
|
|
95
|
+
const acceptedLanguages = (header, languages)=>{
|
|
96
|
+
const items = (header ?? '').split(',').map((item, index)=>{
|
|
97
|
+
const [tag, ...parameters] = item.trim().split(';');
|
|
98
|
+
const quality = parameters.map((parameter)=>parameter.trim()).find((parameter)=>parameter.toLowerCase().startsWith('q='));
|
|
99
|
+
const value = quality?.slice(2).trim();
|
|
100
|
+
const q = void 0 === value ? 1 : QVALUE.test(value) ? Number(value) : 0 / 0;
|
|
101
|
+
return {
|
|
102
|
+
tag: tag.trim(),
|
|
103
|
+
q,
|
|
104
|
+
index
|
|
105
|
+
};
|
|
106
|
+
}).filter((item)=>item.tag && !Number.isNaN(item.q));
|
|
107
|
+
const ranked = languages.flatMap((language, position)=>{
|
|
108
|
+
let best;
|
|
109
|
+
for (const item of items){
|
|
110
|
+
const specificity = rangeSpecificity(item.tag, language);
|
|
111
|
+
if (void 0 !== specificity && (!best || specificity > best.specificity)) best = {
|
|
112
|
+
q: item.q,
|
|
113
|
+
index: item.index,
|
|
114
|
+
specificity
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return best && best.q > 0 ? [
|
|
118
|
+
{
|
|
119
|
+
language,
|
|
120
|
+
position,
|
|
121
|
+
...best
|
|
122
|
+
}
|
|
123
|
+
] : [];
|
|
124
|
+
});
|
|
125
|
+
return ranked.sort((left, right)=>right.q - left.q || left.index - right.index || right.specificity - left.specificity || left.position - right.position).map((entry)=>entry.language);
|
|
126
|
+
};
|
|
127
|
+
function detectRequestLanguage(request, languages, detection = {}) {
|
|
128
|
+
const url = new URL(request.url);
|
|
129
|
+
for (const detector of detection.order ?? DEFAULT_ORDER){
|
|
130
|
+
let language;
|
|
131
|
+
if ('querystring' === detector) language = matchLanguage(url.searchParams.get(detection.lookupQuerystring ?? 'lng'), languages);
|
|
132
|
+
else if ('cookie' === detector) language = matchLanguage(readCookie(request.headers.get('cookie'), detection.lookupCookie ?? 'i18next'), languages);
|
|
133
|
+
else if ('header' === detector) language = acceptedLanguages(request.headers.get(detection.lookupHeader ?? 'accept-language'), languages).find(Boolean);
|
|
134
|
+
if (language) return language;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function resolveRequestLanguage(request, options) {
|
|
138
|
+
const { languages, fallbackLanguage } = options;
|
|
139
|
+
const url = new URL(request.url);
|
|
140
|
+
const fromPath = languageFromPathname(url.pathname, languages, options.basePath);
|
|
141
|
+
if (fromPath) return {
|
|
142
|
+
kind: 'language',
|
|
143
|
+
language: fromPath
|
|
144
|
+
};
|
|
145
|
+
const detected = (false === options.detect ? void 0 : detectRequestLanguage(request, languages, options.detection)) ?? fallbackLanguage;
|
|
146
|
+
const remaining = entryPathname(url.pathname, options.basePath);
|
|
147
|
+
if (void 0 === remaining || (0, localised_urls_namespaceObject.shouldSkipLocaleRedirect)(remaining, [
|
|
148
|
+
...languages
|
|
149
|
+
], options.ignoreRedirectRoutes)) {
|
|
150
|
+
const vary = (false === options.detect ? [] : options.detection?.order ?? DEFAULT_ORDER).flatMap((detector)=>'header' === detector ? [
|
|
151
|
+
options.detection?.lookupHeader ?? 'Accept-Language'
|
|
152
|
+
] : 'cookie' === detector ? [
|
|
153
|
+
'Cookie'
|
|
154
|
+
] : []);
|
|
155
|
+
return vary.length ? {
|
|
156
|
+
kind: 'language',
|
|
157
|
+
language: detected,
|
|
158
|
+
vary
|
|
159
|
+
} : {
|
|
160
|
+
kind: 'language',
|
|
161
|
+
language: detected
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
const localized = (0, localised_urls_namespaceObject.localiseTargetPathname)(remaining, detected, [
|
|
165
|
+
...languages
|
|
166
|
+
], options.localisedUrls);
|
|
167
|
+
return {
|
|
168
|
+
kind: 'redirect',
|
|
169
|
+
language: detected,
|
|
170
|
+
location: `${normaliseBasePath(options.basePath)}${localized}${url.search}`
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
function createRequestLanguageRedirect(location) {
|
|
174
|
+
return new Response(null, {
|
|
175
|
+
status: 302,
|
|
176
|
+
headers: {
|
|
177
|
+
'cache-control': 'private, no-store',
|
|
178
|
+
location,
|
|
179
|
+
vary: 'Accept-Language, Cookie'
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
exports.createRequestLanguageRedirect = __webpack_exports__.createRequestLanguageRedirect;
|
|
184
|
+
exports.detectRequestLanguage = __webpack_exports__.detectRequestLanguage;
|
|
185
|
+
exports.languageFromPathname = __webpack_exports__.languageFromPathname;
|
|
186
|
+
exports.resolveRequestLanguage = __webpack_exports__.resolveRequestLanguage;
|
|
187
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
188
|
+
"createRequestLanguageRedirect",
|
|
189
|
+
"detectRequestLanguage",
|
|
190
|
+
"languageFromPathname",
|
|
191
|
+
"resolveRequestLanguage"
|
|
192
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
193
|
+
Object.defineProperty(exports, '__esModule', {
|
|
194
|
+
value: true
|
|
195
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
createI18nRouterNavigation: ()=>createI18nRouterNavigation
|
|
32
|
+
});
|
|
33
|
+
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
34
|
+
const runtime_namespaceObject = require("@modern-js/runtime");
|
|
35
|
+
const context_namespaceObject = require("@modern-js/runtime/context");
|
|
36
|
+
const router_state_namespaceObject = require("@modern-js/runtime-extensions/router-state");
|
|
37
|
+
const external_react_namespaceObject = require("react");
|
|
38
|
+
const subscribeNone = ()=>()=>{};
|
|
39
|
+
const getEmptySnapshot = ()=>null;
|
|
40
|
+
const createI18nRouterNavigation = ({ I18nNavigationProvider, useNativeI18nRouterAdapter })=>{
|
|
41
|
+
const NavigationProvider = I18nNavigationProvider;
|
|
42
|
+
const useIntegratedRouterAdapter = ()=>{
|
|
43
|
+
const runtimeContext = (0, external_react_namespaceObject.useContext)(runtime_namespaceObject.RuntimeContext);
|
|
44
|
+
const internalContext = (0, external_react_namespaceObject.useContext)(context_namespaceObject.InternalRuntimeContext);
|
|
45
|
+
const native = useNativeI18nRouterAdapter();
|
|
46
|
+
const getCapability = (0, external_react_namespaceObject.useCallback)(()=>(0, router_state_namespaceObject.getRouterRuntimeState)(internalContext)?.navigation ?? (0, router_state_namespaceObject.getRouterRuntimeState)(runtimeContext)?.navigation, [
|
|
47
|
+
internalContext,
|
|
48
|
+
runtimeContext
|
|
49
|
+
]);
|
|
50
|
+
const subscribeCapability = (0, external_react_namespaceObject.useCallback)((update)=>{
|
|
51
|
+
const stopInternal = (0, router_state_namespaceObject.subscribeRouterRuntimeState)(internalContext, update);
|
|
52
|
+
const stopPublic = internalContext === runtimeContext ? void 0 : (0, router_state_namespaceObject.subscribeRouterRuntimeState)(runtimeContext, update);
|
|
53
|
+
return ()=>{
|
|
54
|
+
stopInternal();
|
|
55
|
+
stopPublic?.();
|
|
56
|
+
};
|
|
57
|
+
}, [
|
|
58
|
+
internalContext,
|
|
59
|
+
runtimeContext
|
|
60
|
+
]);
|
|
61
|
+
const capability = (0, external_react_namespaceObject.useSyncExternalStore)(subscribeCapability, getCapability, getCapability);
|
|
62
|
+
const snapshot = (0, external_react_namespaceObject.useSyncExternalStore)(capability?.subscribe ?? subscribeNone, capability?.getSnapshot ?? getEmptySnapshot, capability?.getSnapshot ?? getEmptySnapshot);
|
|
63
|
+
if (native.hasRouter || !capability || !snapshot) return native;
|
|
64
|
+
const internalState = (0, router_state_namespaceObject.getRouterRuntimeState)(internalContext);
|
|
65
|
+
return {
|
|
66
|
+
framework: internalState?.navigation === capability ? internalState.framework : (0, router_state_namespaceObject.getRouterRuntimeState)(runtimeContext)?.framework,
|
|
67
|
+
hasRouter: true,
|
|
68
|
+
...snapshot,
|
|
69
|
+
navigate: capability.navigate,
|
|
70
|
+
Link: capability.Link,
|
|
71
|
+
createLinkProps: capability.createLinkProps
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
const I18nRouterNavigationProvider = ({ children })=>{
|
|
75
|
+
const value = useIntegratedRouterAdapter();
|
|
76
|
+
const native = useNativeI18nRouterAdapter();
|
|
77
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(NavigationProvider, {
|
|
78
|
+
value: value.hasRouter && !native.hasRouter ? value : null,
|
|
79
|
+
children: children
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
useIntegratedRouterAdapter,
|
|
84
|
+
I18nRouterNavigationProvider
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
exports.createI18nRouterNavigation = __webpack_exports__.createI18nRouterNavigation;
|
|
88
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
89
|
+
"createI18nRouterNavigation"
|
|
90
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
91
|
+
Object.defineProperty(exports, '__esModule', {
|
|
92
|
+
value: true
|
|
93
|
+
});
|
|
@@ -27,22 +27,13 @@ var __webpack_require__ = {};
|
|
|
27
27
|
})();
|
|
28
28
|
var __webpack_exports__ = {};
|
|
29
29
|
__webpack_require__.r(__webpack_exports__);
|
|
30
|
-
|
|
31
|
-
|
|
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
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
createI18nRouterNavigation: ()=>external_adapter_js_namespaceObject.createI18nRouterNavigation
|
|
42
32
|
});
|
|
43
|
-
|
|
33
|
+
const external_adapter_js_namespaceObject = require("./adapter.js");
|
|
34
|
+
exports.createI18nRouterNavigation = __webpack_exports__.createI18nRouterNavigation;
|
|
44
35
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
45
|
-
"
|
|
36
|
+
"createI18nRouterNavigation"
|
|
46
37
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
47
38
|
Object.defineProperty(exports, '__esModule', {
|
|
48
39
|
value: true
|