Module

compiler.statements.i18n

i18n statement compilation for Kida compiler.

Compiles Trans nodes to gettext/ngettext calls with proper HTML escaping via Markup %-formatting.

Uses inline TYPE_CHECKING declarations for host attributes. See: plan/rfc-mixin-protocol-typing.md

Classes

I18nStatementMixin 1
Mixin for compiling {% trans %} blocks. Host attributes and cross-mixin dependencies are declared …

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…
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]