Repository: home-assistant/core
File: script/hassfest/translations.py (Python)

Code before:
                vol.Optional("sections"): {
                    str: {
                        vol.Optional("data"): {str: translation_value_validator},
                        vol.Optional("data_description"): {
                            str: translation_value_validator
                        },
                        vol.Optional("description"): translation_value_validator,
                        vol.Optional("name"): translation_value_validator,
                    },
                },
            }
        },
        vol.Optional("error"): {str: translation_value_validator},
        vol.Optional("abort"): {str: translation_value_validator},
        vol.Optional("progress"): {str: translation_value_validator},
        vol.Optional("create_entry"): {str: translation_value_validator},
    }
    if subentry_flow:
        schema[vol.Required("entry_type")] = translation_value_validator
        schema[vol.Required("initiate_flow")] = {
            vol.Required("user"): translation_value_validator,
            str: translation_value_validator,
        }
    if flow_title == REQUIRED:
        schema[vol.Required("title")] = translation_value_validator
    elif flow_title == REMOVED:
        schema[vol.Optional("title", msg=REMOVED_TITLE_MSG)] = partial(
            removed_title_validator, config, integration
        )

    def data_description_validator(value: dict[str, Any]) -> dict[str, Any]:
        """Validate data description."""
        for step_info in value["step"].values():
            if "data_description" not in step_info:
                continue

            for key in step_info["data_description"]:
                if key not in step_info["data"]:
                    raise vol.Invalid(f"data_description key {key} is not in data")

        return value

    validators = [vol.Schema(schema), data_description_validator]

    if mandatory_description is not None:

        def validate_description_set(value: dict[str, Any]) -> dict[str, Any]:
            """Validate description is set."""
            steps = value["step"]
            if mandatory_description not in steps:
                raise vol.Invalid(f"{mandatory_description} needs to be defined")

Review comment (suggestion):
I wish we could enforce the use of references because there probably won't be more than like 5-10 unique strings.

Code after:
                vol.Optional("sections"): {
                    str: {
                        vol.Optional("data"): {str: translation_value_validator},
                        vol.Optional("data_description"): {
                            str: translation_value_validator
                        },
                        vol.Optional("description"): translation_value_validator,
                        vol.Optional("name"): translation_value_validator,
                    },
                },
            }
        },
        vol.Optional("error"): {str: translation_value_validator},
        vol.Optional("abort"): {str: translation_value_validator},
        vol.Optional("progress"): {str: translation_value_validator},
        vol.Optional("create_entry"): {str: translation_value_validator},
    }
    if subentry_flow:
        schema[vol.Required("entry_type")] = translation_value_validator
        schema[vol.Required("initiate_flow")] = {
            vol.Required("user"): translation_value_validator,
            str: translation_value_validator,
        }
    else:
        schema[vol.Optional("initiate_flow")] = {
            vol.Required("user"): translation_value_validator,
        }
    if flow_title == REQUIRED:
        schema[vol.Required("title")] = translation_value_validator
    elif flow_title == REMOVED:
        schema[vol.Optional("title", msg=REMOVED_TITLE_MSG)] = partial(
            removed_title_validator, config, integration
        )

    def data_description_validator(value: dict[str, Any]) -> dict[str, Any]:
        """Validate data description."""
        for step_info in value["step"].values():
            if "data_description" not in step_info:
                continue

            for key in step_info["data_description"]:
                if key not in step_info["data"]:
                    raise vol.Invalid(f"data_description key {key} is not in data")

        return value

    validators = [vol.Schema(schema), data_description_validator]

    if mandatory_description is not None:

        def validate_description_set(value: dict[str, Any]) -> dict[str, Any]: