Skip to content

linexcel.i18n

linexcel.i18n

Supported languages for the viewer UI and the AI documentation.

The set is deliberately closed. language selects a stored system prompt and is interpolated into the generated viewer, so it is validated against this allowlist rather than escaped or passed through: an arbitrary string would let a caller steer the model's instructions or reach the generated JavaScript.

Adding a language means adding an entry here and in :mod:linexcel.aidoc's two prompt registries. tests/test_lineage.py asserts the three stay in sync, so a partial addition fails the suite instead of surfacing as raw keys in the report or a KeyError at generation time.

Provenance: en and fr were written by hand. The other seven languages, here and in the prompt registries, were produced with AI assistance and have not been reviewed by native speakers — corrections welcome.

validate_language

validate_language(language: str) -> str

Return language if it is supported, else raise ValueError.

validate_language("ja") 'ja' validate_language("klingon") Traceback (most recent call last): ... ValueError: Unsupported language: 'klingon'. Use one of ('en', 'fr', 'es', 'de', 'it', 'pt', 'nl', 'ja', 'zh')

Source code in src/linexcel/i18n.py
def validate_language(language: str) -> str:
    """Return ``language`` if it is supported, else raise ``ValueError``.

    >>> validate_language("ja")
    'ja'
    >>> validate_language("klingon")
    Traceback (most recent call last):
        ...
    ValueError: Unsupported language: 'klingon'. Use one of
    ('en', 'fr', 'es', 'de', 'it', 'pt', 'nl', 'ja', 'zh')
    """
    if language not in LANGUAGES:
        raise ValueError(f"Unsupported language: {language!r}. Use one of {LANGUAGES}")
    return language

ui_payload

ui_payload(language: str) -> dict[str, Any]

Interface strings to embed for language.

Only the requested language and the English fallback are shipped: the viewer resolves a missing key through I18N.en, so embedding the other seven locales in every report would be dead weight.

Source code in src/linexcel/i18n.py
def ui_payload(language: str) -> dict[str, Any]:
    """Interface strings to embed for ``language``.

    Only the requested language and the English fallback are shipped: the
    viewer resolves a missing key through ``I18N.en``, so embedding the other
    seven locales in every report would be dead weight.
    """
    validate_language(language)
    payload: dict[str, Any] = {DEFAULT_LANGUAGE: UI_STRINGS[DEFAULT_LANGUAGE]}
    payload[language] = UI_STRINGS[language]
    return payload