mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-17 14:26:35 +00:00
Add localization to service call exceptions (#18447)
This commit is contained in:
parent
8bdbe8c6a6
commit
fd9c24d05e
@ -61,6 +61,7 @@ export type TranslationCategory =
|
|||||||
| "state"
|
| "state"
|
||||||
| "entity"
|
| "entity"
|
||||||
| "entity_component"
|
| "entity_component"
|
||||||
|
| "exceptions"
|
||||||
| "config"
|
| "config"
|
||||||
| "config_panel"
|
| "config_panel"
|
||||||
| "options"
|
| "options"
|
||||||
|
@ -122,18 +122,27 @@ export const connectionMixin = <T extends Constructor<HassBaseEl>>(
|
|||||||
}
|
}
|
||||||
if (notifyOnError) {
|
if (notifyOnError) {
|
||||||
forwardHaptic("failure");
|
forwardHaptic("failure");
|
||||||
|
const lokalize = await this.hass!.loadBackendTranslation(
|
||||||
|
"exceptions",
|
||||||
|
err.translation_domain
|
||||||
|
);
|
||||||
|
const localizedErrorMessage = lokalize(
|
||||||
|
`component.${err.translation_domain}.exceptions.${err.translation_key}.message`,
|
||||||
|
err.translation_placeholders
|
||||||
|
);
|
||||||
const message =
|
const message =
|
||||||
|
localizedErrorMessage ||
|
||||||
(this as any).hass.localize(
|
(this as any).hass.localize(
|
||||||
"ui.notification_toast.service_call_failed",
|
"ui.notification_toast.service_call_failed",
|
||||||
"service",
|
"service",
|
||||||
`${domain}/${service}`
|
`${domain}/${service}`
|
||||||
) +
|
) +
|
||||||
` ${
|
` ${
|
||||||
err.message ||
|
err.message ||
|
||||||
(err.error?.code === ERR_CONNECTION_LOST
|
(err.error?.code === ERR_CONNECTION_LOST
|
||||||
? "connection lost"
|
? "connection lost"
|
||||||
: "unknown error")
|
: "unknown error")
|
||||||
}`;
|
}`;
|
||||||
fireEvent(this as any, "hass-notification", { message });
|
fireEvent(this as any, "hass-notification", { message });
|
||||||
}
|
}
|
||||||
throw err;
|
throw err;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user