Make time condition translatable (#18298)

This commit is contained in:
Simon Lamon 2023-10-23 17:02:51 +02:00 committed by GitHub
parent 82a464f50f
commit 0ff5bffd0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 19 deletions

View File

@ -937,32 +937,35 @@ const tryDescribeCondition = (
}`
: localizeTimeString(condition.after, hass.locale, hass.config);
let result = "Confirm the ";
if (after || before) {
result += "time is ";
}
if (after) {
result += "after " + after;
}
if (before && after) {
result += " and ";
}
if (before) {
result += "before " + before;
}
if ((after || before) && validWeekdays) {
result += " and the ";
}
let localizedDays: string[] = [];
if (validWeekdays) {
const localizedDays = weekdaysArray.map((d) =>
localizedDays = weekdaysArray.map((d) =>
hass.localize(
`ui.panel.config.automation.editor.conditions.type.time.weekdays.${d}`
)
);
result += " day is " + formatListWithOrs(hass.locale, localizedDays);
}
return result;
let hasTime = "";
if (after !== undefined && before !== undefined) {
hasTime = "after_before";
} else if (after !== undefined) {
hasTime = "after";
} else if (before !== undefined) {
hasTime = "before";
}
return hass.localize(
`${conditionsTranslationBaseKey}.time.description.full`,
{
hasTime: hasTime,
hasTimeAndDay: (after || before) && validWeekdays,
hasDay: validWeekdays,
time_before: before,
time_after: after,
day: formatListWithOrs(hass.locale, localizedDays),
}
);
}
}

View File

@ -2663,6 +2663,9 @@
"fri": "Friday",
"sat": "Saturday",
"sun": "Sunday"
},
"description": {
"full": "Confirm the {hasTime, select, \n after {time is after {time_after}}\n before {time is before {time_before}}\n after_before {time is after {time_after} and before {time_before}} \n other {}\n }{hasTimeAndDay, select, \n true { and the }\n other {}\n}{hasDay, select, \n true { day is {day}}\n other {}\n}"
}
},
"trigger": {