From 3f05712c18e21c9d883552ed57fa836b47cd6946 Mon Sep 17 00:00:00 2001 From: Simon Lamon <32477463+silamon@users.noreply.github.com> Date: Mon, 14 Aug 2023 09:48:53 +0200 Subject: [PATCH] Make some conditions translatable (#17234) --- src/data/automation_i18n.ts | 51 ++++++++++++++++++++++++++++--------- src/translations/en.json | 24 ++++++++++++++--- 2 files changed, 59 insertions(+), 16 deletions(-) diff --git a/src/data/automation_i18n.ts b/src/data/automation_i18n.ts index 2a513936f2..e06c1bd4ad 100644 --- a/src/data/automation_i18n.ts +++ b/src/data/automation_i18n.ts @@ -26,6 +26,8 @@ import { FrontendLocaleData } from "./translation"; const triggerTranslationBaseKey = "ui.panel.config.automation.editor.triggers.type"; +const conditionsTranslationBaseKey = + "ui.panel.config.automation.editor.conditions.type"; const describeDuration = (forTime: number | string | ForDict) => { let duration: string | null; @@ -714,34 +716,53 @@ const tryDescribeCondition = ( const conditions = ensureArray(condition.conditions); if (!conditions || conditions.length === 0) { - return "Test if any condition matches"; + return hass.localize( + `${conditionsTranslationBaseKey}.or.description.no_conditions` + ); } const count = conditions.length; - return `Test if any of ${count} condition${count === 1 ? "" : "s"} matches`; + return hass.localize( + `${conditionsTranslationBaseKey}.or.description.full`, + { + count: count, + } + ); } if (condition.condition === "and") { const conditions = ensureArray(condition.conditions); if (!conditions || conditions.length === 0) { - return "Test if multiple conditions match"; + return hass.localize( + `${conditionsTranslationBaseKey}.and.description.no_conditions` + ); } const count = conditions.length; - return `Test if ${count} condition${count === 1 ? "" : "s"} match${ - count === 1 ? "es" : "" - }`; + return hass.localize( + `${conditionsTranslationBaseKey}.and.description.full`, + { + count: count, + } + ); } if (condition.condition === "not") { const conditions = ensureArray(condition.conditions); if (!conditions || conditions.length === 0) { - return "Test if no condition matches"; + return hass.localize( + `${conditionsTranslationBaseKey}.not.description.no_conditions` + ); } if (conditions.length === 1) { - return "Test if 1 condition does not match"; + return hass.localize( + `${conditionsTranslationBaseKey}.not.description.one_condition` + ); } - return `Test if none of ${conditions.length} conditions match`; + return hass.localize( + `${conditionsTranslationBaseKey}.not.description.full`, + { count: conditions.length } + ); } // State Condition @@ -1018,9 +1039,15 @@ const tryDescribeCondition = ( const entitiesString = disjunctionFormatter.format(entities); const zonesString = disjunctionFormatter.format(zones); - return `Confirm ${entitiesString} ${ - entities.length > 1 ? "are" : "is" - } in ${zonesString} ${zones.length > 1 ? "zones" : "zone"}`; + return hass.localize( + `${conditionsTranslationBaseKey}.zone.description.full`, + { + entity: entitiesString, + numberOfEntities: entities.length, + zone: zonesString, + numberOfZones: zones.length, + } + ); } if (condition.condition === "device") { diff --git a/src/translations/en.json b/src/translations/en.json index b105f95d70..116d8f3238 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -2504,7 +2504,11 @@ "type_select": "Condition type", "type": { "and": { - "label": "And" + "label": "And", + "description": { + "no_conditions": "Test if multiple conditions match", + "full": "Test if any of {count} {count, plural,\n one {condition match}\n other {conditions matches}\n}" + } }, "device": { "label": "Device", @@ -2518,7 +2522,12 @@ } }, "not": { - "label": "Not" + "label": "Not", + "description": { + "no_conditions": "Test if no condition matches", + "one_condition": "Test if 1 condition does not match", + "full": "Test if none of {count} conditions match" + } }, "numeric_state": { "type_value": "[%key:ui::panel::config::automation::editor::triggers::type::numeric_state::type_value%]", @@ -2531,7 +2540,11 @@ "value_template": "[%key:ui::panel::config::automation::editor::triggers::type::numeric_state::value_template%]" }, "or": { - "label": "Or" + "label": "Or", + "description": { + "no_conditions": "Test if any condition matches", + "full": "Test if any of {count} {count, plural,\n one {condition}\n other {conditions}\n} matches" + } }, "state": { "label": "[%key:ui::panel::config::automation::editor::triggers::type::state::label%]", @@ -2577,7 +2590,10 @@ "zone": { "label": "[%key:ui::panel::config::automation::editor::triggers::type::zone::label%]", "entity": "[%key:ui::panel::config::automation::editor::triggers::type::zone::entity%]", - "zone": "[%key:ui::panel::config::automation::editor::triggers::type::zone::label%]" + "zone": "[%key:ui::panel::config::automation::editor::triggers::type::zone::label%]", + "description": { + "full": "Confirm {entity} {numberOfEntities, plural,\n one {is}\n other {are}\n} in {zone} {numberOfZones, plural,\n one {zone} \n other {zones}\n} " + } } } },