Spaces:
Running
Running
File size: 726 Bytes
f5cf172 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import pycountry
iso_encoder = {"English":"eng",
"French":"fra",
"Moore": "mos"}
iso_decoder = dict((v,k) for k,v in iso_encoder.items())
def encode_iso(lang:str)-> str:
''' Takes the name of a language and returns its ISO-3 code. '''
return iso_encoder[lang]
def decode_iso(iso:str)-> str:
''' Takes an ISO-3 code and returns the name of the language. '''
if "-" in iso:
iso, suffix = iso.split("-", 1)
else:
suffix = None
name = pycountry.languages.get(alpha_3 = iso).name
name = name.replace("Mossi", "Mooré").replace("Swahili (individual language)", "Swahili")
if suffix is not None:
name+= f" - {suffix}"
return name |