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.
94 lines
2.5 KiB
94 lines
2.5 KiB
import type { Locale } from "@/translations/config";
|
|
|
|
import ar from "@/translations/locales/ar.json";
|
|
import az from "@/translations/locales/az.json";
|
|
import bn from "@/translations/locales/bn.json";
|
|
import da from "@/translations/locales/da.json";
|
|
import de from "@/translations/locales/de.json";
|
|
import en from "@/translations/locales/en.json";
|
|
import es from "@/translations/locales/es.json";
|
|
import fa from "@/translations/locales/fa.json";
|
|
import fr from "@/translations/locales/fr.json";
|
|
import gu from "@/translations/locales/gu.json";
|
|
import ha from "@/translations/locales/ha.json";
|
|
import he from "@/translations/locales/he.json";
|
|
import hi from "@/translations/locales/hi.json";
|
|
import id from "@/translations/locales/id.json";
|
|
import ks from "@/translations/locales/ks.json";
|
|
import pt from "@/translations/locales/pt.json";
|
|
import ru from "@/translations/locales/ru.json";
|
|
import sw from "@/translations/locales/sw.json";
|
|
import tg from "@/translations/locales/tg.json";
|
|
import tr from "@/translations/locales/tr.json";
|
|
import ul from "@/translations/locales/ul.json";
|
|
import ur from "@/translations/locales/ur.json";
|
|
import uz from "@/translations/locales/uz.json";
|
|
import zh from "@/translations/locales/zh.json";
|
|
|
|
export const dictionaries = {
|
|
ar,
|
|
az,
|
|
bn,
|
|
da,
|
|
de,
|
|
en,
|
|
es,
|
|
fa,
|
|
fr,
|
|
gu,
|
|
ha,
|
|
he,
|
|
hi,
|
|
id,
|
|
ks,
|
|
pt,
|
|
ru,
|
|
sw,
|
|
tg,
|
|
tr,
|
|
ul,
|
|
ur,
|
|
uz,
|
|
zh,
|
|
} as const;
|
|
|
|
export type Dictionary = typeof dictionaries.en;
|
|
|
|
function mergeWithEnglishFallback(
|
|
fallback: Record<string, unknown>,
|
|
localized: Record<string, unknown>,
|
|
): Record<string, unknown> {
|
|
const result = { ...fallback };
|
|
|
|
for (const [key, localizedValue] of Object.entries(localized)) {
|
|
const fallbackValue = fallback[key];
|
|
|
|
if (
|
|
localizedValue &&
|
|
typeof localizedValue === "object" &&
|
|
!Array.isArray(localizedValue) &&
|
|
fallbackValue &&
|
|
typeof fallbackValue === "object" &&
|
|
!Array.isArray(fallbackValue)
|
|
) {
|
|
result[key] = mergeWithEnglishFallback(
|
|
fallbackValue as Record<string, unknown>,
|
|
localizedValue as Record<string, unknown>,
|
|
);
|
|
} else {
|
|
result[key] = localizedValue;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
export function getDictionary(locale: Locale): Dictionary {
|
|
const localized = (dictionaries as unknown as Record<string, Dictionary>)[
|
|
locale
|
|
];
|
|
|
|
if (!localized || locale === "en") return dictionaries.en;
|
|
|
|
return mergeWithEnglishFallback(dictionaries.en, localized) as Dictionary;
|
|
}
|