Is it possible to get the list of all ISO639-1 language codes from pycountry 1.15? For example, ['en','it','el','fr',...]? If yes then how?
The following doesn't work I am afraid:
import pycountry
pycountry.languages
ISO 639 is a standardized nomenclature used to classify languages. Each language is assigned a two-letter (639-1) and three-letter (639-2 and 639-3) lowercase abbreviation, amended in later versions of the nomenclature.
There are 58 languages in ISO 639-2 which are considered, for the purposes of the standard, to be "macrolanguages" in ISO 639-3.
This will give you a list of two-digit ISO3166-1 country codes:
countries = [country.alpha2 for country in pycountry.countries]
#countries = [country.alpha_2 for country in pycountry.countries] # for python3
This will give you a list of two-digit ISO639-1 language codes:
langs = [lang.iso639_1_code
for lang in pycountry.languages
if hasattr(lang, 'iso639_1_code')]
This will give you a list of all of the language codes:
langs = [getattr(lang, 'iso639_1_code', None) or
getattr(lang, 'iso639_2T_code', None) or
getattr(lang, 'iso639_3_code')
for lang in pycountry.languages]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With