mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-25 08:26:21 +02:00
Native CLI i18n: The TrustGraph CLI has built-in translation support that dynamically loads language strings. You can test and use different languages by simply passing the --lang flag (e.g., --lang es for Spanish, --lang ru for Russian) or by configuring your environment's LANG variable. Automated Docs Translations: This PR introduces autonomously translated Markdown documentation into several target languages, including Spanish, Swahili, Portuguese, Turkish, Hindi, Hebrew, Arabic, Simplified Chinese, and Russian.
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
from trustgraph.i18n import get_language_pack, get_translator, normalize_language
|
|
|
|
|
|
def test_normalize_language_handles_regions_and_accept_language():
|
|
assert normalize_language(None) == "en"
|
|
assert normalize_language("") == "en"
|
|
|
|
assert normalize_language("es-ES") == "es"
|
|
assert normalize_language("pt-BR") == "pt"
|
|
assert normalize_language("zh") == "zh-cn"
|
|
|
|
assert normalize_language("es-ES,es;q=0.9,en;q=0.8") == "es"
|
|
assert normalize_language("unknown") == "en"
|
|
|
|
|
|
def test_language_pack_loads_from_resources():
|
|
pack = get_language_pack("en")
|
|
assert isinstance(pack, dict)
|
|
|
|
# Key should exist and map to a non-empty string.
|
|
title = pack.get("cli.verify_system_status.title")
|
|
assert isinstance(title, str)
|
|
assert title.strip() != ""
|
|
|
|
|
|
def test_translator_formats_placeholders():
|
|
tr = get_translator("en")
|
|
out = tr.t(
|
|
"cli.verify_system_status.checking_attempt",
|
|
name="Pulsar",
|
|
attempt=2,
|
|
)
|
|
|
|
assert "Pulsar" in out
|
|
assert "2" in out
|
|
|
|
|
|
def test_translator_falls_back_to_key_for_unknown_keys():
|
|
tr = get_translator("en")
|
|
assert tr.t("missing.key") == "missing.key"
|