How to use the pycountry.pycountry.languages.get function in pycountry

To help you get started, we鈥檝e selected a few pycountry examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openpaperwork / paperwork / paperwork-backend / paperwork_backend / util.py View on Github external
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)
github openpaperwork / paperwork / paperwork-backend / paperwork_backend / util.py View on Github external
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)
github openpaperwork / paperwork / paperwork-backend / paperwork_backend / util.py View on Github external
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)
github openpaperwork / paperwork / paperwork-backend / paperwork_backend / util.py View on Github external
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)
github openpaperwork / paperwork / paperwork-backend / paperwork_backend / util.py View on Github external
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')
github openpaperwork / paperwork / paperwork-backend / paperwork_backend / util.py View on Github external
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(
github openpaperwork / paperwork / paperwork-backend / paperwork_backend / util.py View on Github external
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)
github openpaperwork / paperwork / paperwork-backend / paperwork_backend / util.py View on Github external
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)
github openpaperwork / paperwork / paperwork-backend / paperwork_backend / util.py View on Github external
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')
github openpaperwork / paperwork / paperwork-backend / paperwork_backend / util.py View on Github external
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))