const LANG3_TO_NAME = { | |
afr: 'afrikaans', | |
amh: 'amharic', | |
arb: 'arabic', | |
asm: 'assamese', | |
azj: 'azerbaijani', | |
bak: 'bashkir', | |
bel: 'belarusian', | |
ben: 'bengali', | |
bod: 'tibetan', | |
bos: 'bosnian', | |
bre: 'breton', | |
bul: 'bulgarian', | |
cat: 'catalan', | |
ces: 'czech', | |
cmn: 'chinese', | |
cym: 'welsh', | |
dan: 'danish', | |
deu: 'german', | |
ell: 'greek', | |
eng: 'english', | |
est: 'estonian', | |
eus: 'basque', | |
fao: 'faroese', | |
fin: 'finnish', | |
fra: 'french', | |
glg: 'galician', | |
guj: 'gujarati', | |
hat: 'haitian creole', | |
hau: 'hausa', | |
haw: 'hawaiian', | |
heb: 'hebrew', | |
hin: 'hindi', | |
hrv: 'croatian', | |
hun: 'hungarian', | |
hye: 'armenian', | |
ind: 'indonesian', | |
isl: 'icelandic', | |
ita: 'italian', | |
jav: 'javanese', | |
jpn: 'japanese', | |
kan: 'kannada', | |
kat: 'georgian', | |
kaz: 'kazakh', | |
khk: 'mongolian', | |
khm: 'khmer', | |
kor: 'korean', | |
lao: 'lao', | |
lat: 'latin', | |
lin: 'lingala', | |
lit: 'lithuanian', | |
ltz: 'luxembourgish', | |
lvs: 'latvian', | |
mal: 'malayalam', | |
mar: 'marathi', | |
mkd: 'macedonian', | |
mlg: 'malagasy', | |
mlt: 'maltese', | |
mri: 'maori', | |
mya: 'myanmar', | |
nld: 'dutch', | |
nno: 'nynorsk', | |
nob: 'norwegian', | |
npi: 'nepali', | |
oci: 'occitan', | |
pan: 'punjabi', | |
pbt: 'pashto', | |
pes: 'persian', | |
pol: 'polish', | |
por: 'portuguese', | |
ron: 'romanian', | |
rus: 'russian', | |
san: 'sanskrit', | |
sin: 'sinhala', | |
slk: 'slovak', | |
slv: 'slovenian', | |
sna: 'shona', | |
snd: 'sindhi', | |
som: 'somali', | |
spa: 'spanish', | |
sqi: 'albanian', | |
srp: 'serbian', | |
sun: 'sundanese', | |
swe: 'swedish', | |
swh: 'swahili', | |
tam: 'tamil', | |
tat: 'tatar', | |
tel: 'telugu', | |
tgk: 'tajik', | |
tgl: 'tagalog', | |
tha: 'thai', | |
tuk: 'turkmen', | |
tur: 'turkish', | |
ukr: 'ukrainian', | |
urd: 'urdu', | |
uzn: 'uzbek', | |
vie: 'vietnamese', | |
yid: 'yiddish', | |
yor: 'yoruba', | |
zlm: 'malay', | |
}; | |
export function getLanguageFromThreeLetterCode( | |
lang3Code: string, | |
): string | null { | |
try { | |
const name = LANG3_TO_NAME[lang3Code] ?? null; | |
if (name == null) { | |
return null; | |
} | |
const capitalizedWords = name | |
.split(' ') | |
.map((word: string) => word[0].toUpperCase() + word.slice(1)); | |
return capitalizedWords.join(' '); | |
} catch (e) { | |
console.warn(`Unable to get language name for code ${lang3Code}: ${e}`); | |
} | |
return null; | |
} | |