Skip to content

Messages

liquid2.Translations

Bases: Protocol

Message catalog interface.

An object implementing this protocol is expected to be available in a render context.

Could be a GNUTranslations instance from the gettext module, a Babel Translations object, or any object implementing gettext, ngettext, pgettext and npgettext methods.

gettext

gettext(message: str) -> str

Lookup the message in the catalog.

ngettext

ngettext(singular: str, plural: str, n: int) -> str

Do plural-forms message lookup.

npgettext

npgettext(
    context: str, singular: str, plural: str, n: int
) -> str

Do plural-forms context and message lookup.

pgettext

pgettext(context: str, message: str) -> str

Lookup the context and message in the catalog.

liquid2.MessageTuple

Bases: NamedTuple

The tuple expected to be returned from babel extraction methods.

liquid2.extract_from_template

extract_from_template(
    template: Template,
    keywords: Union[list[str], dict[str, Any], None] = None,
    comment_tags: list[str] | None = None,
) -> Iterator[MessageTuple]

Extract translation messages from a Liquid template.