fix: ship translations/en.json, missing since the component was vendored

Every label, description and error in this integration's UI renders
untranslated in a live Home Assistant. homeassistant.helpers.translation
loads `<integration>/translations/<lang>.json` and nothing else (there is
no fallback to strings.json -- see translation.py's
`integration.file_path / "translations" / file_name`), and this component
has no translations/ directory at all.

Core integrations get away with shipping only strings.json because core
generates translations/ as a release step, resolving the `[%key:...%]`
references strings.json uses to avoid duplicating text. Vendoring the
source tree copies the input and leaves out the generated output, so the
defect arrived with commit 48195c9 and would hit anyone who installs
this from HACS.

Rather than hand-write the file once and let it rot on the next upstream
re-sync, scripts/generate_translations.py regenerates it:

- `common::...` references resolve against the *installed* homeassistant
  package's own strings.json, so the text matches what core would have
  produced for that HA version.
- `component::openai_compatible::...` self-references resolve against
  strings.json itself, repeatedly, since a reference can point at another
  reference.
- Anything it cannot resolve (an unknown namespace, a reference to a
  different integration, a path that does not exist, a marker surviving
  the final pass) is a hard error rather than a raw `[%key:...%]` marker
  shipped into a label.

All 70 references in strings.json resolve; the generated file carries
config, config_subentries, exceptions, issues, selector and services.

tests/test_translations.py locks it down: en.json must exist, must equal
what the generator produces, and must contain no surviving markers.
Verified the check actually catches drift rather than passing vacuously
-- perturbing one label fails it, and deleting the file fails it.

Local: 141 passed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NxJYWgGJtCw13qUHZtG8ki
This commit is contained in:
Adam SmithandClaude Opus 5 committed 2026-09-17 22:18:33 -04:00
1 parent 9d8d1970f7
commit 13c60c242a
3 files changed
+485

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
"""The shipped translations/en.json must exist and match strings.json.
Home Assistant only reads translations/<lang>.json, so a stale or missing
en.json silently degrades every label in the config flow rather than failing
loudly. strings.json is the file that gets edited (and re-synced from core),
so this guards against the two drifting apart.
"""
import json
from scripts.generate_translations import OUTPUT, build
def test_en_json_exists() -> None:
"""A vendored core integration ships no translations/ dir of its own."""
assert OUTPUT.is_file(), (
f"{OUTPUT} is missing -- run: python scripts/generate_translations.py"
)
def test_en_json_matches_strings() -> None:
"""en.json must be exactly what the generator produces from strings.json."""
shipped = json.loads(OUTPUT.read_text(encoding="utf-8"))
assert shipped == build(), (
"translations/en.json is out of sync with strings.json -- run: "
"python scripts/generate_translations.py"
)
def test_no_unresolved_key_references_shipped() -> None:
"""A surviving [%key:...%] marker would render literally in the UI."""
assert "[%key:" not in OUTPUT.read_text(encoding="utf-8")