Module

parser.blocks.i18n

i18n block parsing for Kida parser.

Provides mixin for parsing {% trans %} blocks with variable bindings, pluralization via {% plural %}, and message ID extraction.

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

Classes

I18nParsingMixin 3
Mixin for parsing {% trans %}...{% endtrans %} blocks. Host attributes and cross-mixin dependencie…

Mixin for parsing {% trans %}...{% endtrans %} blocks.

Host attributes and cross-mixin dependencies are declared via inline TYPE_CHECKING blocks.

Methods

Internal Methods 3
_parse_trans 0 Trans
Parse {% trans [var=expr, ...] %}...{% endtrans %}. Syntax: {% trans %}lit…
def _parse_trans(self) -> Trans

Parse {% trans [var=expr, ...] %}...{% endtrans %}.

Syntax:

{% trans %}literal body{% endtrans %}
{% trans name=expr %}Hello, {{ name }}!{% endtrans %}
{% trans count=expr %}One item.{% plural %}{{ count }} items.{% endtrans %}

Body restrictions:

  • Only {{ name }} references allowed (simple names)
  • No filters, attribute access, or method calls
  • All referenced names must be declared in the {% trans %} tag
Returns
Trans
_parse_trans_body 1 tuple[list[str], list[st…
Parse trans block body, returning singular parts, plural parts, and has_plural …
def _parse_trans_body(self, declared_names: set[str]) -> tuple[list[str], list[str], bool]

Parse trans block body, returning singular parts, plural parts, and has_plural flag.

Parameters
Name Type Description
declared_names
Returns
tuple[list[str], list[str], bool]
_normalize_message 1 str
Normalize whitespace in a message ID. Strips leading/trailing whitespace and c…
staticmethod
def _normalize_message(msg: str) -> str

Normalize whitespace in a message ID.

Strips leading/trailing whitespace and collapses internal whitespace to single spaces. This ensures consistent message IDs regardless of template formatting.

Parameters
Name Type Description
msg
Returns
str