From 512fee47b65be4f2e3a7a574219275a4609efb7a Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Thu, 5 Dec 2024 17:01:04 +0100 Subject: [PATCH] Improve trigger and action description for conversation (#23141) --- src/data/automation_i18n.ts | 20 ++++++++++++++------ src/data/script_i18n.ts | 5 +++++ src/translations/en.json | 6 ++++-- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/data/automation_i18n.ts b/src/data/automation_i18n.ts index 94c2946346..616659e682 100644 --- a/src/data/automation_i18n.ts +++ b/src/data/automation_i18n.ts @@ -682,19 +682,27 @@ const tryDescribeTrigger = ( // Conversation Trigger if (trigger.trigger === "conversation") { - if (!trigger.command) { + if (!trigger.command || !trigger.command.length) { return hass.localize( `${triggerTranslationBaseKey}.conversation.description.empty` ); } + const commands = ensureArray(trigger.command); + + if (commands.length === 1) { + return hass.localize( + `${triggerTranslationBaseKey}.conversation.description.single`, + { + sentence: commands[0], + } + ); + } return hass.localize( - `${triggerTranslationBaseKey}.conversation.description.full`, + `${triggerTranslationBaseKey}.conversation.description.multiple`, { - sentence: formatListWithOrs( - hass.locale, - ensureArray(trigger.command).map((cmd) => `'${cmd}'`) - ), + sentence: commands[0], + count: commands.length - 1, } ); } diff --git a/src/data/script_i18n.ts b/src/data/script_i18n.ts index 81cd488236..a459d23ff4 100644 --- a/src/data/script_i18n.ts +++ b/src/data/script_i18n.ts @@ -486,6 +486,11 @@ const tryDescribeAction = ( if (actionType === "set_conversation_response") { const config = action as SetConversationResponseAction; + if (isTemplate(config.set_conversation_response)) { + return hass.localize( + `${actionTranslationBaseKey}.set_conversation_response.description.template` + ); + } return hass.localize( `${actionTranslationBaseKey}.set_conversation_response.description.full`, { response: config.set_conversation_response } diff --git a/src/translations/en.json b/src/translations/en.json index 7bb4165b44..cfadf1b5a2 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -3125,7 +3125,8 @@ "description": { "picker": "When Assist matches a sentence from a voice assistant.", "empty": "When a sentence is said", - "full": "When the sentence {sentence} is said" + "single": "When the sentence ''{sentence}'' is said", + "multiple": "When the sentence ''{sentence}'' or {count, plural,\n one {another}\n other {{count} others}\n} are said" } }, "tag": { @@ -3599,7 +3600,8 @@ "label": "Set conversation response", "description": { "picker": "Set response of conversation if automation was triggered by conversation trigger.", - "full": "Set response of conversation to {response}" + "template": "Set response of conversation to a template", + "full": "Set response of conversation to ''{response}''" } }, "unknown": {