Created
August 31, 2016 07:51
-
-
Save vanadium23/5ec22b02d173206dde7089cd8c05afe5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from babel import Locale, UnknownLocaleError | |
def guess_lang_by_country(country): | |
try: | |
locale_string = 'und_{}'.format(country.upper()) | |
locale = Locale.parse(locale_string) | |
return locale.language | |
except (UnknownLocaleError, ValueError): | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment