我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用babel.UnknownLocaleError()。
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
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
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)
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."))