Skip to content

Commit

Permalink
Add translation to integration setup failures (#19128)
Browse files Browse the repository at this point in the history
  • Loading branch information
gjohansson-ST authored Apr 20, 2024
1 parent c7444a2 commit 697bbf4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 2 additions & 0 deletions gallery/src/pages/misc/integration-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const createConfigEntry = (
pref_disable_new_entities: false,
pref_disable_polling: false,
reason: null,
error_reason_translation_key: null,
error_reason_translation_placeholders: null,
...override,
});

Expand Down
2 changes: 2 additions & 0 deletions src/data/config_entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export interface ConfigEntry {
pref_disable_polling: boolean;
disabled_by: "user" | null;
reason: string | null;
error_reason_translation_key: string | null;
error_reason_translation_placeholders: Record<string, string> | null;
}

export type ConfigEntryMutableParams = Partial<
Expand Down
23 changes: 19 additions & 4 deletions src/panels/config/integrations/ha-config-integration-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
} from "lit";
import { customElement, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import { until } from "lit/directives/until";
import memoizeOne from "memoize-one";
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
import { isDevVersion } from "../../../common/config/version";
Expand Down Expand Up @@ -550,10 +551,24 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
`ui.panel.config.integrations.config_entry.state.${item.state}`,
];
if (item.reason) {
this.hass.loadBackendTranslation("config", item.domain);
stateTextExtra = html`${this.hass.localize(
`component.${item.domain}.config.error.${item.reason}`
) || item.reason}`;
if (item.error_reason_translation_key) {
const lokalisePromExc = this.hass
.loadBackendTranslation("exceptions", item.domain)
.then((localize) =>
localize(
`component.${item.domain}.exceptions.${item.error_reason_translation_key}.message`,
item.error_reason_translation_placeholders ?? undefined
)
);
stateTextExtra = html`${until(lokalisePromExc)}`;
} else {
const lokalisePromError = this.hass
.loadBackendTranslation("config", item.domain)
.then((localize) =>
localize(`component.${item.domain}.config.error.${item.reason}`)
);
stateTextExtra = html`${until(lokalisePromError, item.reason)}`;
}
} else {
stateTextExtra = html`
<br />
Expand Down

0 comments on commit 697bbf4

Please sign in to comment.