Finalize multilingual routing and translations
CI / quality (push) Waiting to run

This commit is contained in:
MOH
2026-03-07 14:10:30 +01:00
parent 1ad9ae9629
commit 7f4277d1d7
53 changed files with 2805 additions and 1382 deletions
+41
View File
@@ -0,0 +1,41 @@
import { routing } from "@/i18n/routing";
export type AppLocale = (typeof routing.locales)[number];
export function resolveLocale(locale: string): AppLocale {
if (locale === "en" || locale === "ar") {
return locale;
}
return routing.defaultLocale;
}
export function getDirection(locale: string): "ltr" | "rtl" {
return resolveLocale(locale) === "ar" ? "rtl" : "ltr";
}
export function stripLocalePrefix(pathname: string): string {
for (const locale of routing.locales) {
if (pathname === `/${locale}`) {
return "/";
}
if (pathname.startsWith(`/${locale}/`)) {
return pathname.slice(locale.length + 1);
}
}
return pathname || "/";
}
export function getLocalizedPath(locale: string, pathname = "/"): string {
const localeKey = resolveLocale(locale);
const normalizedPath = pathname === "" ? "/" : pathname;
const strippedPath = stripLocalePrefix(normalizedPath);
if (localeKey === routing.defaultLocale) {
return strippedPath;
}
return strippedPath === "/" ? `/${localeKey}` : `/${localeKey}${strippedPath}`;
}