This commit is contained in:
2026-08-14 16:03:47 +01:00
parent fd53e3f4fb
commit dfdc3b2840
2463 changed files with 186456 additions and 111315 deletions
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
+10 -33
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -84,20 +83,12 @@ const normalizeLanguage = (lang, options) => {
}
};
const detectFromQuery = (c, options) => {
try {
const query = c.req.query(options.lookupQueryString);
return normalizeLanguage(query, options);
} catch {
return void 0;
}
const query = c.req.query(options.lookupQueryString);
return normalizeLanguage(query, options);
};
const detectFromCookie = (c, options) => {
try {
const cookie = (0, import_cookie.getCookie)(c, options.lookupCookie);
return normalizeLanguage(cookie, options);
} catch {
return void 0;
}
const cookie = (0, import_cookie.getCookie)(c, options.lookupCookie);
return normalizeLanguage(cookie, options);
};
function detectFromHeader(c, options) {
try {
@@ -118,14 +109,10 @@ function detectFromHeader(c, options) {
}
}
function detectFromPath(c, options) {
try {
const url = new URL(c.req.url);
const pathSegments = url.pathname.split("/").filter(Boolean);
const langSegment = pathSegments[options.lookupFromPathIndex];
return normalizeLanguage(langSegment, options);
} catch {
return void 0;
}
const url = new URL(c.req.url);
const pathSegments = url.pathname.split("/").filter(Boolean);
const langSegment = pathSegments[options.lookupFromPathIndex];
return normalizeLanguage(langSegment, options);
}
const detectors = {
querystring: detectFromQuery,
@@ -160,9 +147,6 @@ const detectLanguage = (c, options) => {
let detectedLang;
for (const detectorName of options.order) {
const detector = detectors[detectorName];
if (!detector) {
continue;
}
try {
detectedLang = detector(c, options);
if (detectedLang) {
@@ -195,15 +179,8 @@ const languageDetector = (userOptions) => {
};
validateOptions(options);
return async function languageDetector2(ctx, next) {
try {
const lang = detectLanguage(ctx, options);
ctx.set("language", lang);
} catch (error) {
if (options.debug) {
console.error("Language detection failed:", error);
}
ctx.set("language", options.fallbackLanguage);
}
const lang = detectLanguage(ctx, options);
ctx.set("language", lang);
await next();
};
};