Skip to content

Commit

Permalink
Improve trigger and action description for conversation (#23141)
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya authored Dec 5, 2024
1 parent 4092f56 commit 512fee4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
20 changes: 14 additions & 6 deletions src/data/automation_i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
);
}
Expand Down
5 changes: 5 additions & 0 deletions src/data/script_i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,11 @@ const tryDescribeAction = <T extends ActionType>(

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 }
Expand Down
6 changes: 4 additions & 2 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down

0 comments on commit 512fee4

Please sign in to comment.