Python babel.UnknownLocaleError() Examples

The following are 3 code examples of babel.UnknownLocaleError(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module babel , or try the search function .
Example #1
Source File: strlocale.py    From strsync with GNU General Public License v3.0 6 votes vote down vote up
def get_locale(locale_code):
    locale = None

    try:
        locale = Locale.parse(locale_code)
    except (UnknownLocaleError, ValueError) as e:
        try:
            locale = Locale.parse(locale_code, sep='-')
        except (UnknownLocaleError, ValueError) as e:
            pass

    if locale_code in _cached_locale_:
        locale = _cached_locale_[locale_code]

    if locale:
        _cached_locale_[locale_code] = locale

    return locale 
Example #2
Source File: commands.py    From critics with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def setup_languages(settings):
    if not settings['language']:
        settings['language'] = [get_locale()[:2]]

    languages = []
    language_names = []
    for lang_code in settings['language']:
        try:
            language_names.append(Locale(lang_code).english_name)
            languages.append(lang_code)
        except UnknownLocaleError:
            raise click.ClickException('Unknown language code: %s' % lang_code)

    logger.info('Languages: %s', ', '.join(language_names))
    return settings 
Example #3
Source File: utils.py    From personfinder with Apache License 2.0 5 votes vote down vote up
def __get_env_language_for_babel(self):
        language_code = self.env.lang
        try:
            return babel.Locale.parse(language_code, sep='-')
        except babel.UnknownLocaleError as e:
            # fallback language
            return babel.Locale('en')