Allow adding translations for nested fields to support home-assistant/frontend#26997 (#6180)

This commit is contained in:
Lukas Waslowski 2025-09-16 11:36:45 +02:00 committed by GitHub
parent d2ddd9579c
commit 857dae7736
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 1 deletions

View File

@ -32,6 +32,7 @@ from ..const import (
ATTR_DISCOVERY,
ATTR_DOCKER_API,
ATTR_ENVIRONMENT,
ATTR_FIELDS,
ATTR_FULL_ACCESS,
ATTR_GPIO,
ATTR_HASSIO_API,
@ -454,6 +455,7 @@ SCHEMA_TRANSLATION_CONFIGURATION = vol.Schema(
{
vol.Required(ATTR_NAME): str,
vol.Optional(ATTR_DESCRIPTON): vol.Maybe(str),
vol.Optional(ATTR_FIELDS): {str: vol.Self},
},
extra=vol.REMOVE_EXTRA,
)

View File

@ -189,6 +189,7 @@ ATTR_EVENT = "event"
ATTR_EXCLUDE_DATABASE = "exclude_database"
ATTR_EXTRA = "extra"
ATTR_FEATURES = "features"
ATTR_FIELDS = "fields"
ATTR_FILENAME = "filename"
ATTR_FLAGS = "flags"
ATTR_FOLDERS = "folders"

View File

@ -20,7 +20,16 @@ def test_loading_traslations(coresys: CoreSys, tmp_path: Path):
for file in ("en.json", "es.json"):
write_json_or_yaml_file(
tmp_path / "translations" / file,
{"configuration": {"test": {"name": "test", "test": "test"}}},
{
"configuration": {
"test": {
"name": "test",
"description": "test",
"test": "test",
"fields": {"test2": {"name": "test2"}},
}
}
},
)
for file in ("no.yaml", "de.yaml"):
@ -39,6 +48,18 @@ def test_loading_traslations(coresys: CoreSys, tmp_path: Path):
assert translations["no"]["configuration"]["test"]["name"] == "test"
assert translations["de"]["configuration"]["test"]["name"] == "test"
assert translations["en"]["configuration"]["test"]["description"] == "test"
assert translations["es"]["configuration"]["test"]["description"] == "test"
assert (
translations["en"]["configuration"]["test"]["fields"]["test2"]["name"]
== "test2"
)
assert (
translations["es"]["configuration"]["test"]["fields"]["test2"]["name"]
== "test2"
)
assert "test" not in translations["en"]["configuration"]["test"]
assert translations["no"]["network"]["80/tcp"] == "Webserver port"