Core#
- class quart_babel.Babel(app: Quart | None = None, default_locale: str = DEFAULT_LOCALE, default_timezone: str = DEFAULT_TIMEZONE, date_formats: Quart | t.Dict = None, configure_jinja: bool = True, default_domain: Domain | None = None, locale_selector: LocaleSelectorFunc | None = None, timezone_selector: TimezoneSelectorFunc | None = None)#
The core class of Quart Babel. It is used to configure how babel is used with your quart.Quart application.
- locale_selector#
Custom locale selector function. Defaults to
None.- Type:
Callable[[asgi_tools.request.Request], Awaitable[str | None]] | None
- timezone_selector#
Custom timezone selector function. Defaults to
None.- Type:
Callable[[asgi_tools.request.Request], Awaitable[str | None]] | None
- init_app(app: Quart, default_locale: str = DEFAULT_LOCALE, default_timezone: str = DEFAULT_TIMEZONE, date_formats: t.Dict | None = None, configure_jinja: bool = True, default_domain: Domain | None = None, locale_selector: LocaleSelectorFunc | None = None, timezone_selector: TimezoneSelectorFunc | None = None) None#
Initialize the Quart-Babel extension with the application.
- Parameters:
app – The Quart application to use. Defaults to
None.default_locale – The default locale to be used, defaults to ‘en’.
default_timezone – The default timezone to be used, defaults to ‘UTC’.
date_formats – A mapping of Babel datetime form strings. Defaults to
None.configure_jinja – Sets if Jinja2 filters are added to the app. Defaults to
True.default_domain – The default translation domain. Defaults to
None.locale_selector – The custom locale selector. Defaults to
None.timezone_selector – The custom timezone selector. Defaults to
None.
- property translations: Translations | NullTranslations#
Get the translations to use in the template. It will get the domain and return Domain.translations.
- static load_locale(locale: str) Locale#
Load locale by name and cache it.
- Parameters:
locale – String value of the locale.
- property default_locale: Locale#
The default locale from the configuration as instance of a babel.Locale object.
- property default_timezone: BaseTzInfo#
The default timezone from the configuration as instance of a pytz.BaseTzInfo object.
- property current_locale: Locale#
The current locale from context.
- property current_language: str#
Returns the current language as a string using the current locale.
- property current_timezone: BaseTzInfo | None#
The current timezone from context.
- list_translations() list#
Returns a list of all the locales translations exist for. The list returned will be filled with actual locale objects and not just strings.