Domain#

class quart_babel.Domain(translation_directories: str | List[str] | None = None, domain: str | List[str] = 'messages')#

Localization domain. By default, it will look for translations in the Quart application directory and “messages” domain - all message catalogs should be called messages.mo.

Additional domains are supported passing a list of domain names to the domain argument, but note that in this case they must match a list passed to translation_directories, eg:

Domain(
    translation_directories=[
        "/path/to/translations/with/messages/domain",
        "/another/path/to/translations/with/another/domain",
    ],
    domains=[
        "messages",
        "myapp",
    ]
)
property translation_directories: List[str]#

Returns the translation directories.

as_default() None#

Set this domain as default for the current request.

get_translations_cache() Dict[Tuple[str, str], Translations]#

Returns dictionary-like object for translation caching.

get_translations() NullTranslations | Translations#

Gets the translations for the Domain.

gettext(string: str, **variables: Any) str#

Translates a string with the current locale and passes in the given keyword arguments as mapping to a string formatting string.

gettext(u'Hello World!')
gettext(u'Hello %(name)s!', name='World')
ngettext(singular: str, plural: str, num: int, **variables: Any) str#

ranslates a string with the current locale and passes in the given keyword arguments as mapping to a string formatting string. The num parameter is used to dispatch between singular and various plural forms of the message. It is available in the format string as %(num)d or %(num)s. The source language should be English or a similar language which only has one plural form.

ngettext(u'%(num)d Apple', u'%(num)d Apples', num=len(apples))
pgettext(context: str, string: str, **variables: Any) str#

Like gettext() but with a context.

npgettext(context: str, singular: str, plurarl: str, num: int, **variables: Any) str#

Like ngettext() but with a context.

lazy_gettext(string: str, **variables: Any) LazyString#

Like gettext() but the string returned is lazy which means it will be translated when it is used as an actual string.

Example:

hello = lazy_gettext(u'Hello World')

@app.route('/')
def index():
    return unicode(hello)
lazy_ngettext(singular: str, plural: str, num: int, **variables: Any) LazyString#

Like ngettext() but the string returned is lazy which means it will be translated when it is used as an actual string.

Example:

apples = lazy_ngettext(
    u'%(num)d Apple',
    u'%(num)d Apples',
    num=len(apples)
)

@app.route('/')
def index():
    return unicode(apples)
lazy_pgettext(context: str, string: str, **variables: Any) LazyString#

Like pgettext() but the string returned is lazy which means it will be translated when it is used as an actual string.

quart_babel.gettext(*args: str, **kwargs: Any) str#

Shortcut to gettext() for the default Quart domain.

quart_babel.ngettext(*args: Any, **kwargs: Any) str#

Shortcut to ngettext() for the default Quart domain.

quart_babel.npgettext(*args: Any, **kwargs: Any) str#

Shortcut to npgettext() for the default Quart domain.

quart_babel.pgettext(*args: str, **kwargs: Any) str#

Shortcut to pgettext() for the default Quart domain.

quart_babel.lazy_gettext(*args: str, **kwargs: Any) LazyString#

Shortcut to gettext() for a LazyString using the default Quart domain.

Returns:

LazyString.

quart_babel.lazy_ngettext(*args: Any, **kwargs: Any) LazyString#

Shortcut to ngettext() for a LazyString using the default Quart domain.

Returns:

LazyString.

quart_babel.lazy_pgettext(*args: str, **kwargs: Any) LazyString#

Shortcut to pgettext() for a LazyString using the default Quart domain.

Returns:

LazyString.