26 lines
676 B
JavaScript
26 lines
676 B
JavaScript
function pathHasLocale(path, locales) {
|
|
const segments = path.split("/").map(normalizeThePath);
|
|
for (const segment of segments) {
|
|
for (const locale of locales) {
|
|
if (typeof locale === "string") {
|
|
if (normalizeTheLocale(segment) === normalizeTheLocale(locale)) {
|
|
return true;
|
|
}
|
|
} else if (segment === locale.path) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
function normalizeTheLocale(locale) {
|
|
return locale.replaceAll("_", "-").toLowerCase();
|
|
}
|
|
function normalizeThePath(path) {
|
|
return path.endsWith(".html") ? path.slice(0, -5) : path;
|
|
}
|
|
export {
|
|
normalizeTheLocale,
|
|
normalizeThePath,
|
|
pathHasLocale
|
|
};
|