// Map of all 24 supported languages from backend (apps.marriage.translation_utils.LANGUAGE_MAP) export const LANGUAGE_MAP = { ar: "Arabic", az: "Azerbaijani", bn: "Bengali", zh: "Chinese", da: "Danish", de: "German", en: "English", es: "Spanish", fa: "Persian (Farsi)", fr: "French", gu: "Gujarati", ha: "Hausa", he: "Hebrew", hi: "Hindi", id: "Indonesian", ks: "Kashmiri", pt: "Portuguese", ru: "Russian", sw: "Swahili", tg: "Tajik", tr: "Turkish", ul: "Urdu Roman (Latin)", ur: "Urdu", uz: "Uzbek", } as const; export type LanguageCode = keyof typeof LANGUAGE_MAP; export const locales = Object.keys(LANGUAGE_MAP) as LanguageCode[]; export type Locale = string; export const defaultLocale: Locale = "en"; export const localeLabels: Record = { ...LANGUAGE_MAP, fa: "فارسی", }; export const rtlLanguages = ["ar", "fa", "he", "ks", "ur"]; export const localeDirections: Record = Object.keys( LANGUAGE_MAP, ).reduce( (acc, code) => { acc[code] = rtlLanguages.includes(code) ? "rtl" : "ltr"; return acc; }, {} as Record, ); export function isLocale(value: string | undefined): value is Locale { return Boolean(value && value in LANGUAGE_MAP); } export function stripLocale(pathname: string) { const segments = pathname.split("/"); return isLocale(segments[1]) ? `/${segments.slice(2).join("/")}` : pathname; } export function localizePath(pathname: string, locale: Locale) { const normalizedPath = stripLocale(pathname); const suffix = normalizedPath === "/" ? "" : normalizedPath; return `/${locale}${suffix}`; }