Add translation support for script errors (#18786)

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
Jan Bouwhuis 2023-11-29 11:14:29 +01:00 committed by GitHub
parent 93158bb3af
commit 3876c67588
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -423,7 +423,20 @@ class HaPanelDevService extends LitElement {
}
forwardHaptic("failure");
button.actionError();
let localizedErrorMessage: string | undefined;
if (err.translation_domain && err.translation_key) {
const lokalize = await this.hass.loadBackendTranslation(
"exceptions",
err.translation_domain
);
localizedErrorMessage = lokalize(
`component.${err.translation_domain}.exceptions.${err.translation_key}.message`,
err.translation_placeholders
);
}
this._error =
localizedErrorMessage ||
this.hass.localize("ui.notification_toast.service_call_failed", {
service: this._serviceData!.service!,
}) + ` ${err.message}`;