Core#
- class quart_babel.BabelConfiguration(default_locale: str, default_timezone: str, default_domain: str | List[str], default_directories: List[str], translation_directories: List[str], instance: Babel, locale_selector: Callable | None = None, timezone_selector: Callable | None = None)#
Application configuration for Babel.
- class quart_babel.Babel(app: Quart | None = None, date_formats: Dict[str, Any] | None = None, configure_jinja: bool = True, default_locale: str = 'en', default_domain: str = 'messages', default_translation_directories: str | List[str] = 'translations', default_timezone: str = 'UTC', locale_selector: Callable | None = None, timezone_selector: Callable | None = None)#
Central controller class that can be used to configure how Quart-Babel behaves. Each application that wants to use Quart-Babel has to create, or run
init_app()on, an instance of this class after the configuration was initialized.- init_app(app: Quart, default_locale: str = 'en', default_domain: str = 'messages', default_translation_directories: str | List[str] = 'translations', default_timezone: str = 'UTC', locale_selector: Callable | None = None, timezone_selector: Callable | None = None) None#
Initializes the Babel instance for use with this specific application.
- Parameters:
app – The application to configure
default_locale – The default locale to use for this application
default_domain – The default domain to use for this application
default_translation_directories – The default translation directories to use for this application
default_timezone – The default timezone to use for this application
locale_selector – The function to use to select the locale for a request
timezone_selector – The function to use to select the timezone for a request
- list_translations() List[Locale]#
Returns a list of all the locales translations exist for. The list returned will be filled with actual locale objects and not just strings.
Note
The default locale will always be returned, even if no translation files exist for it.
- property default_locale: Locale#
The default locale from the configuration as an instance of a babel.Locale object.
- property default_timezone: BaseTzInfo#
The default timezone from the configuration as an instance of a pytz.timezone object.
- property domain: str | List[str]#
The message domain for the translations as a string