Skip to content

Commit

Permalink
Add localization to service call exceptions (#18447)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbouwh authored Nov 7, 2023
1 parent 8bdbe8c commit fd9c24d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/data/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export type TranslationCategory =
| "state"
| "entity"
| "entity_component"
| "exceptions"
| "config"
| "config_panel"
| "options"
Expand Down
21 changes: 15 additions & 6 deletions src/state/connection-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,27 @@ export const connectionMixin = <T extends Constructor<HassBaseEl>>(
}
if (notifyOnError) {
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 =
localizedErrorMessage ||
(this as any).hass.localize(
"ui.notification_toast.service_call_failed",
"service",
`${domain}/${service}`
) +
` ${
err.message ||
(err.error?.code === ERR_CONNECTION_LOST
? "connection lost"
: "unknown error")
}`;
` ${
err.message ||
(err.error?.code === ERR_CONNECTION_LOST
? "connection lost"
: "unknown error")
}`;
fireEvent(this as any, "hass-notification", { message });
}
throw err;
Expand Down

0 comments on commit fd9c24d

Please sign in to comment.