Add checks for flow title/description placeholders (#129140)

* Add checks for title placeholders

* Check both title and description

* Improve comment
This commit is contained in:
epenet 2024-11-08 13:33:19 +01:00 committed by GitHub
parent 24b47b50ea
commit 94d597fd41
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -569,6 +569,8 @@ async def _ensure_translation_exists(
component: str, component: str,
key: str, key: str,
description_placeholders: dict[str, str] | None, description_placeholders: dict[str, str] | None,
*,
translation_required: bool = True,
) -> None: ) -> None:
"""Raise if translation doesn't exist.""" """Raise if translation doesn't exist."""
full_key = f"component.{component}.{category}.{key}" full_key = f"component.{component}.{category}.{key}"
@ -579,6 +581,9 @@ async def _ensure_translation_exists(
) )
return return
if not translation_required:
return
if full_key in ignore_translations: if full_key in ignore_translations:
ignore_translations[full_key] = "used" ignore_translations[full_key] = "used"
return return
@ -626,6 +631,20 @@ def check_config_translations(ignore_translations: str | list[str]) -> Generator
setattr(flow, "__flow_seen_before", hasattr(flow, "__flow_seen_before")) setattr(flow, "__flow_seen_before", hasattr(flow, "__flow_seen_before"))
if result["type"] is FlowResultType.FORM: if result["type"] is FlowResultType.FORM:
if step_id := result.get("step_id"):
# neither title nor description are required
# - title defaults to integration name
# - description is optional
for header in ("title", "description"):
await _ensure_translation_exists(
flow.hass,
_ignore_translations,
category,
component,
f"step.{step_id}.{header}",
result["description_placeholders"],
translation_required=False,
)
if errors := result.get("errors"): if errors := result.get("errors"):
for error in errors.values(): for error in errors.values():
await _ensure_translation_exists( await _ensure_translation_exists(