You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.6 KiB
68 lines
1.6 KiB
// 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<string, string> = {
|
|
...LANGUAGE_MAP,
|
|
fa: "فارسی",
|
|
};
|
|
|
|
export const rtlLanguages = ["ar", "fa", "he", "ks", "ur"];
|
|
|
|
export const localeDirections: Record<string, "ltr" | "rtl"> = Object.keys(
|
|
LANGUAGE_MAP,
|
|
).reduce(
|
|
(acc, code) => {
|
|
acc[code] = rtlLanguages.includes(code) ? "rtl" : "ltr";
|
|
return acc;
|
|
},
|
|
{} as Record<string, "ltr" | "rtl">,
|
|
);
|
|
|
|
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}`;
|
|
}
|