33 lines
1,017 B
TypeScript
33 lines
1,017 B
TypeScript
|
|
import type { Locale } from "./i18n";
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Groupes de pages traduites.
|
||
|
|
* Chaque groupe contient les URLs correspondantes pour chaque langue.
|
||
|
|
*/
|
||
|
|
const translationGroups: Record<Locale, string>[] = [
|
||
|
|
{ fr: "/", en: "/en", ar: "/ar" },
|
||
|
|
{ fr: "/a-propos", en: "/en/about", ar: "/ar/نبذة-عني" },
|
||
|
|
{ fr: "/code", en: "/en/code", ar: "/ar/برمجة" },
|
||
|
|
{ fr: "/theatre", en: "/en/acting", ar: "/ar/مسرح" },
|
||
|
|
{ fr: "/photo", en: "/en/photo", ar: "/ar/تصوير" },
|
||
|
|
];
|
||
|
|
|
||
|
|
/** Index inversé : pathname → groupe de traduction */
|
||
|
|
const pathIndex = new Map<string, Record<Locale, string>>();
|
||
|
|
for (const group of translationGroups) {
|
||
|
|
for (const path of Object.values(group)) {
|
||
|
|
pathIndex.set(path, group);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Retourne les URLs alternatives pour un pathname donné.
|
||
|
|
* Les trailing slashes sont normalisés.
|
||
|
|
*/
|
||
|
|
export function getAlternateUrls(
|
||
|
|
pathname: string,
|
||
|
|
): Record<Locale, string> | undefined {
|
||
|
|
const normalized = pathname.replace(/\/$/, "") || "/";
|
||
|
|
return pathIndex.get(normalized);
|
||
|
|
}
|