Classes
I18nStatementMixin
1
▼
Mixin for compiling {% trans %} blocks.
Host attributes and cross-mixin dependencies are declared …
I18nStatementMixin
1
▼
Mixin for compiling {% trans %} blocks.
Host attributes and cross-mixin dependencies are declared via inline TYPE_CHECKING blocks.
Methods
Internal Methods 1 ▼
_compile_trans
1
list[ast.stmt]
▼
Compile {% trans %}...{% endtrans %} to gettext/ngettext calls.
Singular (no v…
_compile_trans
1
list[ast.stmt]
▼
def _compile_trans(self, node: Trans) -> list[ast.stmt]
Compile {% trans %}...{% endtrans %} to gettext/ngettext calls.
Singular (no variables): _append(_escape(_gettext("Hello, world!")))
Singular with variables:
_append(_Markup(_gettext("Hello, %(name)s!")) % {"name": name_value})
Plural:
_append(_Markup(_ngettext("One item.", "%(count)s items.", count))
% {"count": count_value})
HTML escaping strategy:
1. Call gettext/ngettext with raw message ID (no escaping)
2. Wrap result in Markup() for %-formatting
3. Markup.__mod__ auto-escapes non-Markup variable values
4. No-variable case: escape translated string via _escape()
optimize_translations: When enabled and the identity gettext is still installed at compile time, constant trans blocks (no variables, no plural) are compiled to a pre-escaped string append, bypassing the gettext call.
Parameters
| Name | Type | Description |
|---|---|---|
node |
— |
Returns
list[ast.stmt]