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
+10 -32
View File
@@ -53,20 +53,12 @@ var normalizeLanguage = (lang, options) => {
}
};
var 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);
};
var detectFromCookie = (c, options) => {
try {
const cookie = getCookie(c, options.lookupCookie);
return normalizeLanguage(cookie, options);
} catch {
return void 0;
}
const cookie = getCookie(c, options.lookupCookie);
return normalizeLanguage(cookie, options);
};
function detectFromHeader(c, options) {
try {
@@ -87,14 +79,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);
}
var detectors = {
querystring: detectFromQuery,
@@ -129,9 +117,6 @@ var 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) {
@@ -164,15 +149,8 @@ var 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();
};
};