Locale#
- quart_babel.get_locale() Locale | None#
Returns the locale that should be used for this request as babel.Locale object. This returns None if used outside a request.
- quart_babel.force_locale(locale: str) Generator[None, Any, None]#
Temporarily overrides the currently selected locale.
Sometimes it is useful to switch the current locale to different one, do some tasks and then revert back to the original one. For example, if the user uses German on the website, but you want to email them in English, you can use this function as a context manager:
with force_locale('en_US'): send_email(gettext('Hello!'), ...)
- Parameters:
locale – The locale to temporary switch to (ex: ‘en_US’).