Skip to content

Instantly share code, notes, and snippets.

@vanadium23
Created August 31, 2016 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanadium23/5ec22b02d173206dde7089cd8c05afe5 to your computer and use it in GitHub Desktop.
Save vanadium23/5ec22b02d173206dde7089cd8c05afe5 to your computer and use it in GitHub Desktop.
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