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
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
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]
For Python3 its:
countries = [country.alpha_2 for country in pycountry.countries]