# i18n

URL: /kida/api/compiler/statements/i18n/
Section: statements
Description: 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

---

> For a complete page index, fetch /kida/llms.txt.

Open LLM text
(/kida/api/compiler/statements/i18n/index.txt)

Share with AI

Ask Claude
(https://claude.ai/new?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Fcompiler%2Fstatements%2Fi18n%2Findex.txt)

Ask ChatGPT
(https://chatgpt.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Fcompiler%2Fstatements%2Fi18n%2Findex.txt)

Ask Gemini
(https://gemini.google.com/app?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Fcompiler%2Fstatements%2Fi18n%2Findex.txt)

Ask Copilot
(https://copilot.microsoft.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Fcompiler%2Fstatements%2Fi18n%2Findex.txt)

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

1Class

## 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]`
