Python babel 模块,UnknownLocaleError() 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用babel.UnknownLocaleError()

项目:reahl    作者:reahl    | 项目源码 | 文件源码
def with_languages(self):
        """Populates this Menu with a MenuItem for each available language.

           Answers the same Menu.

           .. versionadded: 3.2
        """
        context = ExecutionContext.get_context()
        supported_locales = ReahlEgg.get_languages_supported_by_all(context.config.reahlsystem.root_egg)
        for locale in supported_locales:
            try:
                language_name = Locale.parse(locale).display_name
            except UnknownLocaleError:
                language_name = locale

            bookmark = self.view.as_bookmark(description=language_name, locale=locale)
            bookmark.exact = True
            self.add_bookmark(bookmark)
        return self
项目:deb-python-django-babel    作者:openstack    | 项目源码 | 文件源码
def process_request(self, request):
        try:
            code = getattr(request, 'LANGUAGE_CODE', get_language())
            locale = Locale.parse(code, sep='-')
        except (ValueError, UnknownLocaleError):
            pass
        else:
            _thread_locals.locale = request.locale = locale
项目:smartformat    作者:what-studio    | 项目源码 | 文件源码
def format(self, locale, *args, **kwargs):
        try:
            locale = Locale.parse(locale)
        except (ValueError, UnknownLocaleError):
            args = (locale,) + args
            locale = None
        formatter = self.formatter_class(locale)
        return formatter.format(*args, **kwargs)
项目:railgun    作者:xin-xinhanggao    | 项目源码 | 文件源码
def validate_locale(form, field):
        """Validate whether the user provided locale is a valid locale."""
        try:
            Locale(field.data)
        except UnknownLocaleError:
            raise ValidationError(
                _("Please select a valid locale from above."))