mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-08 11:46:35 +00:00
port-ui reads per-language content catalogs from i18n/content/<code>.yaml,
mapping each English text to its translation. The new i18n_content lookup
builds them from the core catalogs for every message whose msgctxt starts
with role: or menu:, for each language that translates at least one of
them. The role renders one file per language through
render_replicated_templates, so swarm peers carry the same catalogs, and
mounts the directory at /app/i18n/content.
The German Playwright test compares / with /de/ and expects at least one
translated card description and one translated menu category. Its expected
cards are the deployed roles (group_names) rather than
roles_with_service('dashboard'): the minimal variant switches the dashboard
flag off on the apps, which emptied the expectation while the page still
showed their cards.
to_nice_yaml already passes allow_unicode=True to yaml.dump; passing it
again raised "got multiple values for keyword argument 'allow_unicode'".
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from utils.i18n.catalog import catalog_path, new_catalog, write_catalog
|
|
from utils.i18n.keyed import source_keyed_catalogues
|
|
from utils.i18n.languages import LANGUAGES_FILE
|
|
|
|
LANGUAGES = """\
|
|
en: {name: English, native: English, direction: ltr, libretranslate: true}
|
|
de: {name: German, native: Deutsch, direction: ltr, libretranslate: true}
|
|
fr: {name: French, native: Français, direction: ltr, libretranslate: true}
|
|
"""
|
|
|
|
|
|
def _catalog(root: Path, code: str, entries: dict[tuple[str, str], str]) -> None:
|
|
catalog = new_catalog("core", code)
|
|
for (context, msgid), msgstr in entries.items():
|
|
catalog.add(msgid, msgstr, context=context)
|
|
path = catalog_path(root, code, "core")
|
|
path.parent.mkdir(parents=True)
|
|
write_catalog(path, catalog)
|
|
|
|
|
|
class TestSourceKeyedCatalogues(unittest.TestCase):
|
|
def test_only_prefixed_translations_are_keyed_by_their_english_source(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
(root / LANGUAGES_FILE).parent.mkdir()
|
|
(root / LANGUAGES_FILE).write_text(LANGUAGES, encoding="utf-8")
|
|
_catalog(
|
|
root,
|
|
"de",
|
|
{
|
|
("role:web-app-x:description", "A wiki"): "Ein Wiki",
|
|
("menu:help:title", "Help"): "Hilfe",
|
|
("logout:checking", "Checking"): "Prüfe",
|
|
},
|
|
)
|
|
_catalog(root, "fr", {("role:web-app-x:description", "A wiki"): ""})
|
|
|
|
catalogues = source_keyed_catalogues(root, ("role:", "menu:"))
|
|
|
|
self.assertEqual(catalogues, {"de": {"A wiki": "Ein Wiki", "Help": "Hilfe"}})
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|