Skip to content

Commit 857dae7

Browse files
authored
Allow adding translations for nested fields to support home-assistant/frontend#26997 (#6180)
1 parent d2ddd95 commit 857dae7

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

supervisor/addons/validate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
ATTR_DISCOVERY,
3333
ATTR_DOCKER_API,
3434
ATTR_ENVIRONMENT,
35+
ATTR_FIELDS,
3536
ATTR_FULL_ACCESS,
3637
ATTR_GPIO,
3738
ATTR_HASSIO_API,
@@ -454,6 +455,7 @@ def _migrate(config: dict[str, Any]):
454455
{
455456
vol.Required(ATTR_NAME): str,
456457
vol.Optional(ATTR_DESCRIPTON): vol.Maybe(str),
458+
vol.Optional(ATTR_FIELDS): {str: vol.Self},
457459
},
458460
extra=vol.REMOVE_EXTRA,
459461
)

supervisor/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@
189189
ATTR_EXCLUDE_DATABASE = "exclude_database"
190190
ATTR_EXTRA = "extra"
191191
ATTR_FEATURES = "features"
192+
ATTR_FIELDS = "fields"
192193
ATTR_FILENAME = "filename"
193194
ATTR_FLAGS = "flags"
194195
ATTR_FOLDERS = "folders"

tests/store/test_translation_load.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,16 @@ def test_loading_traslations(coresys: CoreSys, tmp_path: Path):
2020
for file in ("en.json", "es.json"):
2121
write_json_or_yaml_file(
2222
tmp_path / "translations" / file,
23-
{"configuration": {"test": {"name": "test", "test": "test"}}},
23+
{
24+
"configuration": {
25+
"test": {
26+
"name": "test",
27+
"description": "test",
28+
"test": "test",
29+
"fields": {"test2": {"name": "test2"}},
30+
}
31+
}
32+
},
2433
)
2534

2635
for file in ("no.yaml", "de.yaml"):
@@ -39,6 +48,18 @@ def test_loading_traslations(coresys: CoreSys, tmp_path: Path):
3948
assert translations["no"]["configuration"]["test"]["name"] == "test"
4049
assert translations["de"]["configuration"]["test"]["name"] == "test"
4150

51+
assert translations["en"]["configuration"]["test"]["description"] == "test"
52+
assert translations["es"]["configuration"]["test"]["description"] == "test"
53+
54+
assert (
55+
translations["en"]["configuration"]["test"]["fields"]["test2"]["name"]
56+
== "test2"
57+
)
58+
assert (
59+
translations["es"]["configuration"]["test"]["fields"]["test2"]["name"]
60+
== "test2"
61+
)
62+
4263
assert "test" not in translations["en"]["configuration"]["test"]
4364

4465
assert translations["no"]["network"]["80/tcp"] == "Webserver port"

0 commit comments

Comments
 (0)