python类UnknownLocaleError()的实例源码

navs.py 文件源码 项目:reahl 作者: reahl 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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
middleware.py 文件源码 项目:deb-python-django-babel 作者: openstack 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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
test.py 文件源码 项目:smartformat 作者: what-studio 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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)
forms.py 文件源码 项目:railgun 作者: xin-xinhanggao 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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."))


问题


面经


文章

微信
公众号

扫码关注公众号