Files
Arkie-Library-Frontend/src/languageRoutes.ts
2026-06-01 15:09:58 +08:00

36 lines
1.0 KiB
TypeScript

import type { Lang } from "./i18n";
export const localizedHomeRoutes: ReadonlyArray<{ lang: Lang; path: string }> =
[
{ lang: "zh-CN", path: "/chinese" },
{ lang: "ja", path: "/japanese" },
{ lang: "ko", path: "/korean" },
{ lang: "vi", path: "/vietnamese" },
{ lang: "id", path: "/indonesian" },
{ lang: "ms", path: "/malay" },
];
function normalizePathname(pathname: string): string {
const normalized = pathname.replace(/\/+$/, "");
return normalized || "/";
}
export function languageForHomePathname(pathname: string): Lang | null {
const normalized = normalizePathname(pathname);
return (
localizedHomeRoutes.find((route) => route.path === normalized)?.lang ?? null
);
}
export function isHomePathname(pathname: string): boolean {
return (
normalizePathname(pathname) === "/" ||
languageForHomePathname(pathname) !== null
);
}
export function homePathForLang(lang: Lang): string {
if (lang === "en") return "/";
return localizedHomeRoutes.find((route) => route.lang === lang)?.path ?? "/";
}