Add missing languages + add support for scripts (pain)

This commit is contained in:
mrjvs 2024-01-03 21:20:57 +01:00
parent a4f75a34ab
commit 7155ffce40
3 changed files with 44 additions and 5 deletions

View File

@ -1,13 +1,21 @@
import ar from "@/assets/locales/ar.json";
import bg from "@/assets/locales/bg.json";
import bn from "@/assets/locales/bn.json";
import cs from "@/assets/locales/cs.json";
import de from "@/assets/locales/de.json";
import el from "@/assets/locales/el.json";
import en from "@/assets/locales/en.json";
import es from "@/assets/locales/es.json";
import et from "@/assets/locales/et.json";
import fa from "@/assets/locales/fa.json";
import fr from "@/assets/locales/fr.json";
import gu from "@/assets/locales/gu.json";
import he from "@/assets/locales/he.json";
import hi from "@/assets/locales/hi.json";
import id from "@/assets/locales/id.json";
import it from "@/assets/locales/it.json";
import ja from "@/assets/locales/ja.json";
import ko from "@/assets/locales/ko.json";
import lv from "@/assets/locales/lv.json";
import minion from "@/assets/locales/minion.json";
import ne from "@/assets/locales/ne.json";
@ -15,12 +23,16 @@ import nl from "@/assets/locales/nl.json";
import pirate from "@/assets/locales/pirate.json";
import pl from "@/assets/locales/pl.json";
import ptbr from "@/assets/locales/pt-BR.json";
import ru from "@/assets/locales/ru.json";
import sl from "@/assets/locales/sl.json";
import sv from "@/assets/locales/sv.json";
import ta from "@/assets/locales/ta.json";
import th from "@/assets/locales/th.json";
import tok from "@/assets/locales/tok.json";
import tr from "@/assets/locales/tr.json";
import uk from "@/assets/locales/uk.json";
import vi from "@/assets/locales/vi.json";
import zhhant from "@/assets/locales/zh-Hant.json";
import zh from "@/assets/locales/zh.json";
export const locales = {
@ -48,5 +60,17 @@ export const locales = {
hi,
"pt-BR": ptbr,
uk,
bg,
bn,
el,
fa,
gu,
id,
ja,
ko,
sl,
ta,
"zh-HANT": zhhant,
ru,
};
export type Locales = keyof typeof locales;

View File

@ -43,7 +43,7 @@ export function FlagIcon(props: FlagIconProps) {
return (
<span
className={classNames(
"!w-8 h-6 rounded overflow-hidden bg-cover bg-center block fi",
"!w-8 min-w-8 h-6 rounded overflow-hidden bg-cover bg-center block fi",
backgroundClass,
countryCode ? `fi-${countryCode}` : undefined,
)}

View File

@ -16,6 +16,8 @@ const countryPriority: Record<string, string> = {
ar: "sa",
es: "es",
zh: "cn",
ko: "kr",
ta: "lk",
};
// list of iso639_1 Alpha-2 codes used as default languages
@ -39,6 +41,17 @@ const defaultLanguageCodes: string[] = [
"ar-SA",
"es-ES",
"et-EE",
"bg-BG",
"bn-BD",
"el-GR",
"fa-IR",
"gu-IN",
"id-ID",
"ja-JP",
"ko-KR",
"sl-SI",
"ta-LK",
"ru-RU",
];
export interface LocaleInfo {
@ -80,7 +93,6 @@ function populateLanguageCode(language: string): string {
*/
export function getPrettyLanguageNameFromLocale(locale: string): string | null {
const tag = getTag(populateLanguageCode(locale), true);
const lang = tag?.language?.Description?.[0] ?? null;
if (!lang) return null;
@ -159,12 +171,15 @@ export function getLocaleInfo(locale: string): LocaleInfo | null {
});
if (!output) return null;
const extras = [];
if (tag.region?.Description) extras.push(tag.region.Description[0]);
if (tag.script?.Description) extras.push(tag.script.Description[0]);
const extraStringified = extras.map((v) => `(${v})`).join(" ");
return {
code: tag.parts.langtag ?? realLocale,
isRtl: output.direction === "RTL",
name:
output.name[0] +
(tag.region?.Description ? ` (${tag.region.Description[0]})` : ""),
name: output.name[0] + (extraStringified ? ` ${extraStringified}` : ""),
nativeName: output.nativeName[0] ?? undefined,
};
}