From 697bbf428e6e6bb0a3105c95874d0b055cfed567 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Sat, 20 Apr 2024 09:16:36 +0200 Subject: [PATCH] Add translation to integration setup failures (#19128) --- gallery/src/pages/misc/integration-card.ts | 2 ++ src/data/config_entries.ts | 2 ++ .../ha-config-integration-page.ts | 23 +++++++++++++++---- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/gallery/src/pages/misc/integration-card.ts b/gallery/src/pages/misc/integration-card.ts index ca1e83c0b6a0..72a99c7c28e7 100644 --- a/gallery/src/pages/misc/integration-card.ts +++ b/gallery/src/pages/misc/integration-card.ts @@ -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, }); diff --git a/src/data/config_entries.ts b/src/data/config_entries.ts index ab3d7480fd1d..37af47885d83 100644 --- a/src/data/config_entries.ts +++ b/src/data/config_entries.ts @@ -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 | null; } export type ConfigEntryMutableParams = Partial< diff --git a/src/panels/config/integrations/ha-config-integration-page.ts b/src/panels/config/integrations/ha-config-integration-page.ts index 5f0b01f2a0a4..674a720c056b 100644 --- a/src/panels/config/integrations/ha-config-integration-page.ts +++ b/src/panels/config/integrations/ha-config-integration-page.ts @@ -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"; @@ -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`