From 954147561a7d9166041b309bedf096d7d9a3f6dc Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Wed, 26 Jun 2024 10:28:33 +0200 Subject: [PATCH] Add translations and catch error --- .../config/automation/ha-automation-editor.ts | 76 +++++++++++-------- src/panels/config/script/ha-script-editor.ts | 76 +++++++++++-------- src/translations/en.json | 10 +++ 3 files changed, 98 insertions(+), 64 deletions(-) diff --git a/src/panels/config/automation/ha-automation-editor.ts b/src/panels/config/automation/ha-automation-editor.ts index ef6aa5bb0b9c..939c00af531c 100644 --- a/src/panels/config/automation/ha-automation-editor.ts +++ b/src/panels/config/automation/ha-automation-editor.ts @@ -222,6 +222,23 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) { ` : nothing} + + + ${this.hass.localize( + this._readOnly + ? "ui.panel.config.automation.editor.migrate" + : "ui.panel.config.automation.editor.duplicate" + )} + + + ${useBlueprint ? html` - ${this.hass.localize( - this._readOnly - ? "ui.panel.config.automation.editor.migrate" - : "ui.panel.config.automation.editor.duplicate" - )} - - -
  • @@ -651,28 +652,39 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) { const config = this._config as BlueprintAutomationConfig; const confirmation = await showConfirmationDialog(this, { - title: "Take control of automation?", - text: "This automation is using a blueprint. By taking control, you will be able to edit it directly. Are you sure you want to take control?", + title: this.hass!.localize( + "ui.panel.config.automation.editor.take_control_confirmation.title" + ), + text: this.hass!.localize( + "ui.panel.config.automation.editor.take_control_confirmation.text" + ), + confirmText: this.hass!.localize( + "ui.panel.config.automation.editor.take_control_confirmation.action" + ), }); if (!confirmation) return; - const result = await substituteBlueprint( - this.hass, - "automation", - config.use_blueprint.path, - config.use_blueprint.input || {} - ); + try { + const result = await substituteBlueprint( + this.hass, + "automation", + config.use_blueprint.path, + config.use_blueprint.input || {} + ); - const newConfig = { - ...normalizeAutomationConfig(result.substituted_config), - alias: config.alias, - description: config.description, - }; + const newConfig = { + ...normalizeAutomationConfig(result.substituted_config), + alias: config.alias, + description: config.description, + }; - this._config = newConfig; - this._dirty = true; - this._errors = undefined; + this._config = newConfig; + this._dirty = true; + this._errors = undefined; + } catch (err: any) { + this._errors = err.message; + } } private async _duplicate() { diff --git a/src/panels/config/script/ha-script-editor.ts b/src/panels/config/script/ha-script-editor.ts index db2ab9510f72..c11a0dc524eb 100644 --- a/src/panels/config/script/ha-script-editor.ts +++ b/src/panels/config/script/ha-script-editor.ts @@ -214,6 +214,23 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { ` : nothing} + + + ${this.hass.localize( + this._readOnly + ? "ui.panel.config.script.editor.migrate" + : "ui.panel.config.script.editor.duplicate" + )} + + + ${useBlueprint ? html` - ${this.hass.localize( - this._readOnly - ? "ui.panel.config.script.editor.migrate" - : "ui.panel.config.script.editor.duplicate" - )} - - -
  • @@ -625,28 +626,39 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { const config = this._config as BlueprintScriptConfig; const confirmation = await showConfirmationDialog(this, { - title: "Take control of automation?", - text: "This automation is using a blueprint. By taking control, you will be able to edit it directly. Are you sure you want to take control?", + title: this.hass!.localize( + "ui.panel.config.script.editor.take_control_confirmation.title" + ), + text: this.hass!.localize( + "ui.panel.config.script.editor.take_control_confirmation.text" + ), + confirmText: this.hass!.localize( + "ui.panel.config.script.editor.take_control_confirmation.action" + ), }); if (!confirmation) return; - const result = await substituteBlueprint( - this.hass, - "script", - config.use_blueprint.path, - config.use_blueprint.input || {} - ); + try { + const result = await substituteBlueprint( + this.hass, + "script", + config.use_blueprint.path, + config.use_blueprint.input || {} + ); - const newConfig = { - ...this._normalizeConfig(result.substituted_config), - alias: config.alias, - description: config.description, - }; + const newConfig = { + ...this._normalizeConfig(result.substituted_config), + alias: config.alias, + description: config.description, + }; - this._config = newConfig; - this._dirty = true; - this._errors = undefined; + this._config = newConfig; + this._dirty = true; + this._errors = undefined; + } catch (err: any) { + this._errors = err.message; + } } private async _duplicate() { diff --git a/src/translations/en.json b/src/translations/en.json index 630d21a37d68..fb5d2927c3df 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -2760,6 +2760,11 @@ "migrate": "Migrate", "duplicate": "[%key:ui::common::duplicate%]", "take_control": "Take control", + "take_control_confirmation": { + "title": "Take control of automation?", + "text": "This automation is using a blueprint. By taking control, your automation will be converted into a regular automation using triggers, conditions and actions. You will be able to edit it directly and you won't be able to convert it back to a blueprint.", + "action": "Take control" + }, "run": "[%key:ui::panel::config::automation::editor::actions::run%]", "rename": "[%key:ui::panel::config::automation::editor::triggers::rename%]", "show_trace": "Traces", @@ -3631,6 +3636,11 @@ "rename": "[%key:ui::panel::config::automation::editor::triggers::rename%]", "change_mode": "[%key:ui::panel::config::automation::editor::change_mode%]", "take_control": "[%key:ui::panel::config::automation::editor::take_control%]", + "take_control_confirmation": { + "title": "Take control of script?", + "text": "This script is using a blueprint. By taking control, your script will be converted into a regular automation using actions. You will be able to edit it directly and you won't be able to convert it back to a blueprint.", + "action": "[%key:ui::panel::config::automation::editor::take_control_confirmation::action%]" + }, "read_only": "This script cannot be edited from the UI, because it is not stored in the ''scripts.yaml'' file.", "unavailable": "Script is unavailable", "migrate": "Migrate",