Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return None
lang_str = lang_str.lower()
if "_" in lang_str:
lang_str = lang_str.split("_")[0]
try:
return pycountry.pycountry.languages.get(name=lang_str.title())
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(iso_639_3_code=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(iso639_3_code=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(iso639_2T_code=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(iso639_1_code=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(terminology=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(bibliographic=lang_str)
def find_language(lang_str=None, allow_none=False):
if lang_str is None:
lang_str = locale.getdefaultlocale()[0]
if lang_str is None and not allow_none:
logger.warning("Unable to figure out locale. Assuming english !")
return find_language('eng')
if lang_str is None:
logger.warning("Unable to figure out locale !")
return None
lang_str = lang_str.lower()
if "_" in lang_str:
lang_str = lang_str.split("_")[0]
try:
return pycountry.pycountry.languages.get(name=lang_str.title())
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(iso_639_3_code=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(iso639_3_code=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(iso639_2T_code=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(iso639_1_code=lang_str)
lang_str = lang_str.split("_")[0]
try:
return pycountry.pycountry.languages.get(name=lang_str.title())
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(iso_639_3_code=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(iso639_3_code=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(iso639_2T_code=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(iso639_1_code=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(terminology=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(bibliographic=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(alpha_3=lang_str)
logger.warning("Unable to figure out locale. Assuming english !")
return find_language('eng')
if lang_str is None:
logger.warning("Unable to figure out locale !")
return None
lang_str = lang_str.lower()
if "_" in lang_str:
lang_str = lang_str.split("_")[0]
try:
return pycountry.pycountry.languages.get(name=lang_str.title())
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(iso_639_3_code=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(iso639_3_code=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(iso639_2T_code=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(iso639_1_code=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(terminology=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(bibliographic=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(alpha_3=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(alpha_2=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(alpha2=lang_str)
except (KeyError, UnicodeDecodeError):
pass
if allow_none:
logger.warning("Unknown language [{}]".format(lang_str))
return None
if lang_str is not None and lang_str == 'eng':
raise Exception("Unable to find language !")
logger.warning("Unknown language [{}]. Switching back to english".format(
lang_str
))
return find_language('eng')
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(iso639_1_code=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(terminology=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(bibliographic=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(alpha_3=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(alpha_2=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(alpha2=lang_str)
except (KeyError, UnicodeDecodeError):
pass
if allow_none:
logger.warning("Unknown language [{}]".format(lang_str))
return None
if lang_str is not None and lang_str == 'eng':
raise Exception("Unable to find language !")
logger.warning("Unknown language [{}]. Switching back to english".format(
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(iso_639_3_code=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(iso639_3_code=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(iso639_2T_code=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(iso639_1_code=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(terminology=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(bibliographic=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(alpha_3=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(alpha_2=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(iso639_3_code=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(iso639_2T_code=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(iso639_1_code=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(terminology=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(bibliographic=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(alpha_3=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(alpha_2=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(alpha2=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(terminology=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(bibliographic=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(alpha_3=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(alpha_2=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(alpha2=lang_str)
except (KeyError, UnicodeDecodeError):
pass
if allow_none:
logger.warning("Unknown language [{}]".format(lang_str))
return None
if lang_str is not None and lang_str == 'eng':
raise Exception("Unable to find language !")
logger.warning("Unknown language [{}]. Switching back to english".format(
lang_str
))
return find_language('eng')
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(iso639_2T_code=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(iso639_1_code=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(terminology=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(bibliographic=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(alpha_3=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(alpha_2=lang_str)
except (KeyError, UnicodeDecodeError):
pass
try:
return pycountry.pycountry.languages.get(alpha2=lang_str)
except (KeyError, UnicodeDecodeError):
pass
if allow_none:
logger.warning("Unknown language [{}]".format(lang_str))