The core speaks English only; every other language is a kind: "translation" plugin
(translation-<lang>; the French one is translation-fr in ai-agent-plugins, seeded once at start).
- plugins: kind translation (typed_manifest.parse_translation: lang, name, englishName, flag,
locale, promptLine, ui/backend JSON dictionaries — strict, operator-only, in the fingerprint);
a top-level "languages" field on any plugin (default ["en"]) shown on its page; seeding takes
translation-*; plugins/translations.py reads the enabled ones (first by id wins a code).
- core/i18n: tr / langs / localized / clean_pref / effective_lang read the installed
translations; a pick whose translation is gone reads English and is kept; browserLang records
any base code. core/i18n_fr.py and FRENCH_LINE are gone (language_line = the plugin's promptLine).
- The owner picks a language too (users.json ownerLang, PUT /api/me {lang}; English by default).
- Public GET /api/i18n/languages and /api/i18n/{lang} (ETag/304), guest host and sign-in included.
- Coverage: backend/core/i18n_keys/{ui,backend}.json (kept by the two i18n tests,
UPDATE_I18N_KEYS=1); a translation's page shows translated / missing / stale / placeholder
mismatches.
- Frontend: frontend/src/i18n/fr removed; the dictionary comes from the hub, cached in
localStorage and revalidated in the background (first boot in a language waits <= 4 s, any
failure is English); Lang is a string; number/currency style from the translation's locale;
LanguageSelect lists English + installed translations (hidden when none); Settings → Plugins
has a Translations kind (tab, catalog filter, group) and a Translation section with the
missing-strings count; mock is English only.
- Tests: test_i18n.py rewritten on a made-up translation; i18n_testkit.speaking() for the
tests that need a second language. authz golden, openapi.json + src/generated regenerated;
docs/plugins.md (Translations), CLAUDE.md, i18n README, docs/settings.md.
Changelog
- Added: languages are plugins — Settings → Plugins → Translations; the owner can pick a language.
- Changed: French moved to the translation-fr plugin (seeded at start: nothing changes for guests).
- Removed: the core's built-in French dictionaries.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
71 lines
3.2 KiB
Python
71 lines
3.2 KiB
Python
"""A translation plugin for tests (the core holds no language but English).
|
|
|
|
``install(store, "fr")`` installs ``translation-fr`` built from the core's own
|
|
key lists (``core/i18n_keys``): every entry is the English wrapped in
|
|
``⟦…⟧`` (:func:`wrap`), so a test sees whether a text went through the
|
|
translation without the core carrying any French. Pass ``backend=`` / ``ui=``
|
|
for other entries. Not a test module (no ``test_`` prefix): imported by them.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import pathlib
|
|
import tempfile
|
|
|
|
from plugins.store import OWNER_UID
|
|
|
|
|
|
def wrap(english: str) -> str:
|
|
return f"⟦{english}⟧"
|
|
|
|
|
|
def make(root: pathlib.Path | None = None, lang: str = "fr", *, backend: dict | None = None,
|
|
ui: dict | None = None, prompt_line: str | None = None) -> pathlib.Path:
|
|
from plugins import translations
|
|
root = root or pathlib.Path(tempfile.mkdtemp())
|
|
keys = translations.core_keys()
|
|
d = root / f"translation-{lang}"
|
|
(d / "i18n").mkdir(parents=True, exist_ok=True)
|
|
(d / "i18n" / "ui.json").write_text(json.dumps(
|
|
ui if ui is not None else {k: wrap(k) for k in keys["ui"]}), encoding="utf-8")
|
|
(d / "i18n" / "backend.json").write_text(json.dumps(
|
|
backend if backend is not None else {k: wrap(k) for k in keys["backend"]}), encoding="utf-8")
|
|
(d / "plugin.json").write_text(json.dumps({
|
|
"schema": 1, "id": f"translation-{lang}", "name": f"Test {lang}", "version": "1.0.0",
|
|
"kind": "translation", "description": "a test translation", "icon": "languages",
|
|
"translation": {"lang": lang, "name": f"Test {lang}", "englishName": f"Test {lang}",
|
|
"locale": f"{lang}-ZZ" if len(lang) == 2 else lang,
|
|
"promptLine": prompt_line or f"- **Language: {{name}} reads {lang}.**",
|
|
"ui": "i18n/ui.json", "backend": "i18n/backend.json"}}), encoding="utf-8")
|
|
return d
|
|
|
|
|
|
def install(store, lang: str = "fr", **kw) -> str:
|
|
"""Install (or re-enable) the test translation for ``lang``; its id."""
|
|
pid = f"translation-{lang}"
|
|
if not any(r["id"] == pid for r in store.list_for(OWNER_UID)):
|
|
store.install(OWNER_UID, str(make(lang=lang, **kw)), is_owner=True, approve=True)
|
|
store.update(OWNER_UID, pid, enabled=True)
|
|
return pid
|
|
|
|
|
|
def translations_for(*langs: str):
|
|
"""A :class:`plugins.translations.Translations` speaking ``langs``, every
|
|
core key :func:`wrap`ped — for :func:`speaking`."""
|
|
from plugins import translations
|
|
keys = translations.core_keys()
|
|
return translations.Translations([translations.Translation(
|
|
lang=lang, plugin_id=f"translation-{lang}", name=f"Test {lang}",
|
|
english_name=f"Test {lang}", flag=None, locale=f"{lang}-ZZ",
|
|
prompt_line=f"- **Language: {{name}} reads {lang}.**",
|
|
ui={k: wrap(k) for k in keys["ui"]}, backend={k: wrap(k) for k in keys["backend"]},
|
|
etag=f"test-{lang}") for lang in langs])
|
|
|
|
|
|
def speaking(*langs: str):
|
|
"""``with speaking("fr"):`` — the hub speaks those languages (as if their
|
|
translation plugins were installed and enabled), whatever the store says."""
|
|
from unittest.mock import patch
|
|
return patch("plugins.translations.current", return_value=translations_for(*langs))
|