full site update

This commit is contained in:
2025-07-24 18:46:24 +02:00
parent bfe2b90d8d
commit 37a6e0ab31
6912 changed files with 540482 additions and 361712 deletions

View File

@@ -1,4 +1,4 @@
import { normalizeTheLocale, toCodes } from "./index.js";
import { getAllCodes, normalizeTheLocale } from "./index.js";
function parseLocale(header) {
if (header === "*") {
return [{ locale: header, qualityValue: void 0 }];
@@ -35,7 +35,7 @@ function parseLocale(header) {
return result;
}
function sortAndFilterLocales(browserLocaleList, locales) {
const normalizedLocales = toCodes(locales).map(normalizeTheLocale);
const normalizedLocales = getAllCodes(locales).map(normalizeTheLocale);
return browserLocaleList.filter((browserLocale) => {
if (browserLocale.locale !== "*") {
return normalizedLocales.includes(normalizeTheLocale(browserLocale.locale));
@@ -59,11 +59,13 @@ function computePreferredLocale(request, locales) {
if (typeof currentLocale === "string") {
if (normalizeTheLocale(currentLocale) === normalizeTheLocale(firstResult.locale)) {
result = currentLocale;
break;
}
} else {
for (const currentCode of currentLocale.codes) {
if (normalizeTheLocale(currentCode) === normalizeTheLocale(firstResult.locale)) {
result = currentLocale.path;
result = currentCode;
break;
}
}
}
@@ -78,13 +80,7 @@ function computePreferredLocaleList(request, locales) {
if (acceptHeader) {
const browserLocaleList = sortAndFilterLocales(parseLocale(acceptHeader), locales);
if (browserLocaleList.length === 1 && browserLocaleList.at(0).locale === "*") {
return locales.map((locale) => {
if (typeof locale === "string") {
return locale;
} else {
return locale.codes.at(0);
}
});
return getAllCodes(locales);
} else if (browserLocaleList.length > 0) {
for (const browserLocale of browserLocaleList) {
for (const loopLocale of locales) {
@@ -95,7 +91,7 @@ function computePreferredLocaleList(request, locales) {
} else {
for (const code of loopLocale.codes) {
if (code === browserLocale.locale) {
result.push(loopLocale.path);
result.push(code);
}
}
}
@@ -168,6 +164,29 @@ function toRoutingStrategy(routing, domains) {
}
return strategy;
}
const PREFIX_DEFAULT_LOCALE = /* @__PURE__ */ new Set([
"pathname-prefix-always",
"domains-prefix-always",
"pathname-prefix-always-no-redirect",
"domains-prefix-always-no-redirect"
]);
const REDIRECT_TO_DEFAULT_LOCALE = /* @__PURE__ */ new Set([
"pathname-prefix-always-no-redirect",
"domains-prefix-always-no-redirect"
]);
function fromRoutingStrategy(strategy, fallbackType) {
let routing;
if (strategy === "manual") {
routing = "manual";
} else {
routing = {
prefixDefaultLocale: PREFIX_DEFAULT_LOCALE.has(strategy),
redirectToDefaultLocale: !REDIRECT_TO_DEFAULT_LOCALE.has(strategy),
fallbackType
};
}
return routing;
}
function toFallbackType(routing) {
if (routing === "manual") {
return "rewrite";
@@ -178,6 +197,7 @@ export {
computeCurrentLocale,
computePreferredLocale,
computePreferredLocaleList,
fromRoutingStrategy,
parseLocale,
toFallbackType,
toRoutingStrategy