Skip to content

Commit

Permalink
Use trigger and condition type translation labels (#18413)
Browse files Browse the repository at this point in the history
Co-authored-by: Bram Kragten <[email protected]>
  • Loading branch information
silamon and bramkragten authored Oct 30, 2023
1 parent c0ff24b commit 36f7b34
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
35 changes: 17 additions & 18 deletions src/data/automation_i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -642,10 +642,7 @@ const tryDescribeTrigger = (
}

// Device Trigger
if (trigger.platform === "device") {
if (!trigger.device_id) {
return "Device trigger";
}
if (trigger.platform === "device" && trigger.device_id) {
const config = trigger as DeviceTrigger;
const localized = localizeDeviceAutomationTrigger(
hass,
Expand All @@ -661,9 +658,12 @@ const tryDescribeTrigger = (
}`;
}

return `${
trigger.platform ? trigger.platform.replace(/_/g, " ") : "Unknown"
} trigger`;
return (
hass.localize(
`ui.panel.config.automation.editor.triggers.type.${trigger.platform}.label`
) ||
hass.localize(`ui.panel.config.automation.editor.triggers.unknown_trigger`)
);
};

export const describeCondition = (
Expand Down Expand Up @@ -1074,10 +1074,7 @@ const tryDescribeCondition = (
);
}

if (condition.condition === "device") {
if (!condition.device_id) {
return "Device condition";
}
if (condition.condition === "device" && condition.device_id) {
const config = condition as DeviceCondition;
const localized = localizeDeviceAutomationCondition(
hass,
Expand All @@ -1093,14 +1090,16 @@ const tryDescribeCondition = (
}`;
}

if (condition.condition === "trigger") {
if (!condition.id) {
return "Trigger condition";
}
if (condition.condition === "trigger" && condition.id) {
return `When triggered by ${condition.id}`;
}

return `${
condition.condition ? condition.condition.replace(/_/g, " ") : "Unknown"
} condition`;
return (
hass.localize(
`ui.panel.config.automation.editor.conditions.type.${condition.condition}.label`
) ||
hass.localize(
`ui.panel.config.automation.editor.conditions.unknown_condition`
)
);
};
2 changes: 2 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2401,6 +2401,7 @@
"delete_confirm_text": "It will be permanently deleted.",
"unsupported_platform": "No visual editor support for platform: {platform}",
"type_select": "Trigger type",
"unknown_trigger": "[%key:ui::panel::config::devices::automation::triggers::unknown_trigger%]",
"type": {
"calendar": {
"label": "Calendar",
Expand Down Expand Up @@ -2596,6 +2597,7 @@
"delete_confirm_text": "[%key:ui::panel::config::automation::editor::triggers::delete_confirm_text%]",
"unsupported_condition": "No visual editor support for condition: {condition}",
"type_select": "Condition type",
"unknown_condition": "[%key:ui::panel::config::devices::automation::conditions::unknown_condition%]",
"type": {
"and": {
"label": "And",
Expand Down

0 comments on commit 36f7b34

Please sign in to comment.