mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Allow for translating service examples (#97141)
This commit is contained in:
parent
0c4e341189
commit
b655b9d530
@ -666,6 +666,10 @@ async def async_get_all_descriptions(
|
|||||||
f"component.{domain}.services.{service_name}.fields.{field_name}.description"
|
f"component.{domain}.services.{service_name}.fields.{field_name}.description"
|
||||||
):
|
):
|
||||||
field_schema["description"] = desc
|
field_schema["description"] = desc
|
||||||
|
if example := translations.get(
|
||||||
|
f"component.{domain}.services.{service_name}.fields.{field_name}.example"
|
||||||
|
):
|
||||||
|
field_schema["example"] = example
|
||||||
|
|
||||||
if "target" in yaml_description:
|
if "target" in yaml_description:
|
||||||
description["target"] = yaml_description["target"]
|
description["target"] = yaml_description["target"]
|
||||||
|
@ -334,6 +334,7 @@ def gen_strings_schema(config: Config, integration: Integration) -> vol.Schema:
|
|||||||
{
|
{
|
||||||
vol.Required("name"): str,
|
vol.Required("name"): str,
|
||||||
vol.Required("description"): translation_value_validator,
|
vol.Required("description"): translation_value_validator,
|
||||||
|
vol.Optional("example"): translation_value_validator,
|
||||||
},
|
},
|
||||||
slug_validator=translation_key_validator,
|
slug_validator=translation_key_validator,
|
||||||
),
|
),
|
||||||
|
@ -573,6 +573,7 @@ async def test_async_get_all_descriptions(hass: HomeAssistant) -> None:
|
|||||||
f"{translation_key_prefix}.description": "Translated description",
|
f"{translation_key_prefix}.description": "Translated description",
|
||||||
f"{translation_key_prefix}.fields.level.name": "Field name",
|
f"{translation_key_prefix}.fields.level.name": "Field name",
|
||||||
f"{translation_key_prefix}.fields.level.description": "Field description",
|
f"{translation_key_prefix}.fields.level.description": "Field description",
|
||||||
|
f"{translation_key_prefix}.fields.level.example": "Field example",
|
||||||
}
|
}
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
@ -599,6 +600,10 @@ async def test_async_get_all_descriptions(hass: HomeAssistant) -> None:
|
|||||||
]
|
]
|
||||||
== "Field description"
|
== "Field description"
|
||||||
)
|
)
|
||||||
|
assert (
|
||||||
|
descriptions[logger.DOMAIN]["set_default_level"]["fields"]["level"]["example"]
|
||||||
|
== "Field example"
|
||||||
|
)
|
||||||
|
|
||||||
hass.services.async_register(logger.DOMAIN, "new_service", lambda x: None, None)
|
hass.services.async_register(logger.DOMAIN, "new_service", lambda x: None, None)
|
||||||
service.async_set_service_schema(
|
service.async_set_service_schema(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user