Skip to content

Commit

Permalink
Add localization to service call exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
jbouwh committed Oct 27, 2023
1 parent f1748e4 commit 043abbb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 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
3 changes: 3 additions & 0 deletions src/layouts/home-assistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
// @ts-ignore
this._loadHassTranslations(this.hass!.language, "state");

// @ts-ignore
this._loadHassTranslations(this.hass!.language, "exceptions");

document.addEventListener(
"visibilitychange",
() => this._checkVisibility(),
Expand Down
5 changes: 5 additions & 0 deletions src/state/connection-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,18 @@ export const connectionMixin = <T extends Constructor<HassBaseEl>>(
}
if (notifyOnError) {
forwardHaptic("failure");
const lokalizedErrorMessage = (this as any).hass.localize(
`component.${err.translation_domain}.exceptions.${err.translation_key}.message`,
err.translation_placeholders
);
const message =
(this as any).hass.localize(
"ui.notification_toast.service_call_failed",
"service",
`${domain}/${service}`
) +
` ${
lokalizedErrorMessage ||
err.message ||
(err.error?.code === ERR_CONNECTION_LOST
? "connection lost"
Expand Down

0 comments on commit 043abbb

Please sign in to comment.