From d762a9365f8989c44e4473fd7b02e4a2515bbfbf Mon Sep 17 00:00:00 2001 From: Simon Lamon <32477463+silamon@users.noreply.github.com> Date: Mon, 18 Dec 2023 15:06:41 +0100 Subject: [PATCH] Automation traces localization (#18862) --- src/components/trace/ha-trace-path-details.ts | 128 +++++++++++++----- .../config/automation/ha-automation-trace.ts | 49 ++++--- src/translations/en.json | 26 +++- 3 files changed, 147 insertions(+), 56 deletions(-) diff --git a/src/components/trace/ha-trace-path-details.ts b/src/components/trace/ha-trace-path-details.ts index 46f4a7a23e..f87d9006ef 100644 --- a/src/components/trace/ha-trace-path-details.ts +++ b/src/components/trace/ha-trace-path-details.ts @@ -1,5 +1,12 @@ import { dump } from "js-yaml"; -import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; +import { + css, + CSSResultGroup, + html, + LitElement, + nothing, + TemplateResult, +} from "lit"; import { customElement, property, state } from "lit/decorators"; import { classMap } from "lit/directives/class-map"; import { formatDateTimeWithSeconds } from "../../common/datetime/format_date_time"; @@ -18,6 +25,12 @@ import { traceTabStyles } from "./trace-tab-styles"; import { HomeAssistant } from "../../types"; import type { NodeInfo } from "./hat-script-graph"; +const TRACE_PATH_TABS = [ + "step_config", + "changed_variables", + "logbook", +] as const; + @customElement("ha-trace-path-details") export class HaTracePathDetails extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; @@ -34,7 +47,7 @@ export class HaTracePathDetails extends LitElement { @property() public trackedNodes!: Record; - @state() private _view: "config" | "changed_variables" | "logbook" = "config"; + @state() private _view: (typeof TRACE_PATH_TABS)[number] = "step_config"; protected render(): TemplateResult { return html` @@ -43,23 +56,21 @@ export class HaTracePathDetails extends LitElement {
- ${[ - ["config", "Step Config"], - ["changed_variables", "Changed Variables"], - ["logbook", "Related logbook entries"], - ].map( - ([view, label]) => html` + ${TRACE_PATH_TABS.map( + (view) => html` ` )}
- ${this._view === "config" + ${this._view === "step_config" ? this._renderSelectedConfig() : this._view === "changed_variables" ? this._renderChangedVars() @@ -71,7 +82,9 @@ export class HaTracePathDetails extends LitElement { const paths = this.trace.trace; if (!this.selected?.path) { - return "Select a node on the left for more information."; + return this.hass!.localize( + "ui.panel.config.automation.trace.path.choose" + ); } // HACK: default choice node is not part of paths. We filter them out here by checking parent. @@ -82,12 +95,16 @@ export class HaTracePathDetails extends LitElement { ] as ChooseActionTraceStep[]; if (parentTraceInfo && parentTraceInfo[0]?.result?.choice === "default") { - return "The default action was executed because no options matched."; + return this.hass!.localize( + "ui.panel.config.automation.trace.path.default_action_executed" + ); } } if (!(this.selected.path in paths)) { - return "This node was not executed and so no further trace information is available."; + return this.hass!.localize( + "ui.panel.config.automation.trace.path.no_further_execution" + ); } const parts: TemplateResult[][] = []; @@ -115,29 +132,53 @@ export class HaTracePathDetails extends LitElement { trace as any; if (result?.enabled === false) { - return html`This node was disabled and skipped during execution so - no further trace information is available.`; + return html`${this.hass!.localize( + "ui.panel.config.automation.trace.path.disabled_node" + )}`; } return html` ${curPath === this.selected.path ? "" - : html`

${curPath.substr(this.selected.path.length + 1)}

`} - ${data.length === 1 ? "" : html`

Iteration ${idx + 1}

`} - Executed: - ${formatDateTimeWithSeconds( - new Date(timestamp), - this.hass.locale, - this.hass.config - )}
+ : html`

+ ${curPath.substring(this.selected.path.length + 1)} +

`} + ${data.length === 1 + ? nothing + : html`

+ ${this.hass!.localize( + "ui.panel.config.automation.trace.path.iteration", + { number: idx + 1 } + )} +

`} + ${this.hass!.localize( + "ui.panel.config.automation.trace.path.executed", + { + time: formatDateTimeWithSeconds( + new Date(timestamp), + this.hass.locale, + this.hass.config + ), + } + )} +
${result - ? html`Result: + ? html`${this.hass!.localize( + "ui.panel.config.automation.trace.path.result" + )}
${dump(result)}
` : error - ? html`
Error: ${error}
` - : ""} + ? html`
+ ${this.hass!.localize( + "ui.panel.config.automation.trace.path.error", + { + error: error, + } + )} +
` + : nothing} ${Object.keys(rest).length === 0 - ? "" + ? nothing : html`
${dump(rest)}
`} `; }) @@ -149,16 +190,18 @@ export class HaTracePathDetails extends LitElement { private _renderSelectedConfig() { if (!this.selected?.path) { - return ""; + return nothing; } const config = getDataFromPath(this.trace!.config, this.selected.path); return config ? html`` - : "Unable to find config"; + : this.hass!.localize( + "ui.panel.config.automation.trace.path.unable_to_find_config" + ); } private _renderChangedVars() { @@ -169,10 +212,19 @@ export class HaTracePathDetails extends LitElement {
${data.map( (trace, idx) => html` - ${idx > 0 ? html`

Iteration ${idx + 1}

` : ""} + ${idx > 0 + ? html`

+ ${this.hass!.localize( + "ui.panel.config.automation.trace.path.iteration", + { number: idx + 1 } + )} +

` + : ""} ${Object.keys(trace.changed_variables || {}).length === 0 - ? "No variables changed" - : html`
${dump(trace.changed_variables).trimRight()}
`} + ? this.hass!.localize( + "ui.panel.config.automation.trace.path.no_variables_changed" + ) + : html`
${dump(trace.changed_variables).trimEnd()}
`} ` )}
@@ -186,7 +238,11 @@ export class HaTracePathDetails extends LitElement { const index = trackedPaths.indexOf(this.selected.path); if (index === -1) { - return html`
Node not tracked.
`; + return html`
+ ${this.hass!.localize( + "ui.panel.config.automation.trace.path.node_not_tracked" + )} +
`; } let entries: LogbookEntry[]; @@ -234,7 +290,9 @@ export class HaTracePathDetails extends LitElement { ` : html`
- No Logbook entries found for this step. + ${this.hass!.localize( + "ui.panel.config.automation.trace.path.no_logbook_entries" + )}
`; } diff --git a/src/panels/config/automation/ha-automation-trace.ts b/src/panels/config/automation/ha-automation-trace.ts index af20da030a..868f4a8feb 100644 --- a/src/panels/config/automation/ha-automation-trace.ts +++ b/src/panels/config/automation/ha-automation-trace.ts @@ -7,7 +7,14 @@ import { mdiRayStartArrow, mdiRefresh, } from "@mdi/js"; -import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; +import { + css, + CSSResultGroup, + html, + LitElement, + nothing, + TemplateResult, +} from "lit"; import { customElement, property, query, state } from "lit/decorators"; import { classMap } from "lit/directives/class-map"; import { repeat } from "lit/directives/repeat"; @@ -41,6 +48,8 @@ import { haStyle } from "../../../resources/styles"; import { HomeAssistant, Route } from "../../../types"; import { computeRTL } from "../../../common/util/compute_rtl"; +const TABS = ["details", "automation_config", "timeline", "logbook"] as const; + @customElement("ha-automation-trace") export class HaAutomationTrace extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; @@ -67,12 +76,7 @@ export class HaAutomationTrace extends LitElement { @state() private _logbookEntries?: LogbookEntry[]; - @state() private _view: - | "details" - | "config" - | "timeline" - | "logbook" - | "blueprint" = "details"; + @state() private _view: (typeof TABS)[number] | "blueprint" = "details"; @query("hat-script-graph") private _graph?: HatScriptGraph; @@ -213,9 +217,15 @@ export class HaAutomationTrace extends LitElement { ${this._traces === undefined - ? html`
Loading…
` + ? html`
+ ${this.hass!.localize("ui.common.loading")} +
` : this._traces.length === 0 - ? html`
No traces found
` + ? html`
+ ${this.hass!.localize( + "ui.panel.config.automation.trace.no_traces_found" + )} +
` : this._trace === undefined ? "" : html` @@ -230,20 +240,17 @@ export class HaAutomationTrace extends LitElement {
- ${[ - ["details", "Step Details"], - ["timeline", "Trace Timeline"], - ["logbook", "Related logbook entries"], - ["config", "Automation Config"], - ].map( - ([view, label]) => html` + ${TABS.map( + (view) => html` ` )} @@ -257,7 +264,9 @@ export class HaAutomationTrace extends LitElement { })} @click=${this._showTab} > - Blueprint Config + ${this.hass!.localize( + `ui.panel.config.automation.trace.tabs.blueprint_config` + )} ` : ""} @@ -265,7 +274,7 @@ export class HaAutomationTrace extends LitElement { ${this._selected === undefined || this._logbookEntries === undefined || trackedNodes === undefined - ? "" + ? nothing : this._view === "details" ? html` ` - : this._view === "config" + : this._view === "automation_config" ? html`