mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Make automation editor card headers translateable (triggers partly) (#16969)
This commit is contained in:
parent
221f4f34a7
commit
386ed2167f
@ -24,6 +24,9 @@ import { EntityRegistryEntry } from "./entity_registry";
|
||||
import "../resources/intl-polyfill";
|
||||
import { FrontendLocaleData } from "./translation";
|
||||
|
||||
const triggerTranslationBaseKey =
|
||||
"ui.panel.config.automation.editor.triggers.type";
|
||||
|
||||
const describeDuration = (forTime: number | string | ForDict) => {
|
||||
let duration: string | null;
|
||||
if (typeof forTime === "number") {
|
||||
@ -101,14 +104,19 @@ export const describeTrigger = (
|
||||
}
|
||||
|
||||
const eventTypesString = disjunctionFormatter.format(eventTypes);
|
||||
return `When ${eventTypesString} event is fired`;
|
||||
return hass.localize(
|
||||
`${triggerTranslationBaseKey}.event.description.full`,
|
||||
{ eventTypes: eventTypesString }
|
||||
);
|
||||
}
|
||||
|
||||
// Home Assistant Trigger
|
||||
if (trigger.platform === "homeassistant" && trigger.event) {
|
||||
return `When Home Assistant is ${
|
||||
trigger.event === "start" ? "started" : "shutdown"
|
||||
}`;
|
||||
return hass.localize(
|
||||
trigger.event === "start"
|
||||
? `${triggerTranslationBaseKey}.homeassistant.description.started`
|
||||
: `${triggerTranslationBaseKey}.homeassistant.description.shutdown`
|
||||
);
|
||||
}
|
||||
|
||||
// Numeric State Trigger
|
||||
@ -329,29 +337,28 @@ export const describeTrigger = (
|
||||
|
||||
// Sun Trigger
|
||||
if (trigger.platform === "sun" && trigger.event) {
|
||||
let base = `When the sun ${trigger.event === "sunset" ? "sets" : "rises"}`;
|
||||
|
||||
let duration = "";
|
||||
if (trigger.offset) {
|
||||
let duration = "";
|
||||
|
||||
if (trigger.offset) {
|
||||
if (typeof trigger.offset === "number") {
|
||||
duration = ` offset by ${secondsToDuration(trigger.offset)!}`;
|
||||
} else if (typeof trigger.offset === "string") {
|
||||
duration = ` offset by ${trigger.offset}`;
|
||||
} else {
|
||||
duration = ` offset by ${JSON.stringify(trigger.offset)}`;
|
||||
}
|
||||
if (typeof trigger.offset === "number") {
|
||||
duration = secondsToDuration(trigger.offset)!;
|
||||
} else if (typeof trigger.offset === "string") {
|
||||
duration = trigger.offset;
|
||||
} else {
|
||||
duration = JSON.stringify(trigger.offset);
|
||||
}
|
||||
base += duration;
|
||||
}
|
||||
|
||||
return base;
|
||||
return hass.localize(
|
||||
trigger.event === "sunset"
|
||||
? `${triggerTranslationBaseKey}.sun.description.sets`
|
||||
: `${triggerTranslationBaseKey}.sun.description.rises`,
|
||||
{ hasDuration: duration !== "", duration: duration }
|
||||
);
|
||||
}
|
||||
|
||||
// Tag Trigger
|
||||
if (trigger.platform === "tag") {
|
||||
return "When a tag is scanned";
|
||||
return hass.localize(`${triggerTranslationBaseKey}.tag.description.full`);
|
||||
}
|
||||
|
||||
// Time Trigger
|
||||
@ -364,10 +371,9 @@ export const describeTrigger = (
|
||||
: localizeTimeString(at, hass.locale, hass.config)
|
||||
);
|
||||
|
||||
const last = result.splice(-1, 1)[0];
|
||||
return `When the time is equal to ${
|
||||
result.length ? `${result.join(", ")} or ` : ""
|
||||
}${last}`;
|
||||
return hass.localize(`${triggerTranslationBaseKey}.time.description.full`, {
|
||||
time: disjunctionFormatter.format(result),
|
||||
});
|
||||
}
|
||||
|
||||
// Time Pattern Trigger
|
||||
@ -561,24 +567,27 @@ export const describeTrigger = (
|
||||
|
||||
// MQTT Trigger
|
||||
if (trigger.platform === "mqtt") {
|
||||
return "When an MQTT message has been received";
|
||||
return hass.localize(`${triggerTranslationBaseKey}.mqtt.description.full`);
|
||||
}
|
||||
|
||||
// Template Trigger
|
||||
if (trigger.platform === "template") {
|
||||
let base = "When a template triggers";
|
||||
let duration = "";
|
||||
if (trigger.for) {
|
||||
const duration = describeDuration(trigger.for);
|
||||
if (duration) {
|
||||
base += ` for ${duration}`;
|
||||
}
|
||||
duration = describeDuration(trigger.for) ?? "";
|
||||
}
|
||||
return base;
|
||||
|
||||
return hass.localize(
|
||||
`${triggerTranslationBaseKey}.template.description.full`,
|
||||
{ hasDuration: duration !== "", duration: duration }
|
||||
);
|
||||
}
|
||||
|
||||
// Webhook Trigger
|
||||
if (trigger.platform === "webhook") {
|
||||
return "When a Webhook payload has been received";
|
||||
return hass.localize(
|
||||
`${triggerTranslationBaseKey}.webhook.description.full`
|
||||
);
|
||||
}
|
||||
|
||||
if (trigger.platform === "device") {
|
||||
|
@ -2292,7 +2292,10 @@
|
||||
"event_data": "Event data",
|
||||
"context_users": "Limit to events triggered by",
|
||||
"context_user_picked": "User firing event",
|
||||
"context_user_pick": "Select user"
|
||||
"context_user_pick": "Select user",
|
||||
"description": {
|
||||
"full": "When {eventTypes} event is fired"
|
||||
}
|
||||
},
|
||||
"geo_location": {
|
||||
"label": "Geolocation",
|
||||
@ -2314,12 +2317,19 @@
|
||||
"label": "Home Assistant",
|
||||
"event": "Event:",
|
||||
"start": "Start",
|
||||
"shutdown": "Shutdown"
|
||||
"shutdown": "Shutdown",
|
||||
"description": {
|
||||
"started": "When Home Assistant is started",
|
||||
"shutdown": "When Home Assistant is shutdown"
|
||||
}
|
||||
},
|
||||
"mqtt": {
|
||||
"label": "MQTT",
|
||||
"topic": "Topic",
|
||||
"payload": "Payload (optional)"
|
||||
"payload": "Payload (optional)",
|
||||
"description": {
|
||||
"full": "When an MQTT message has been received"
|
||||
}
|
||||
},
|
||||
"numeric_state": {
|
||||
"label": "Numeric state",
|
||||
@ -2336,22 +2346,35 @@
|
||||
"event": "[%key:ui::panel::config::automation::editor::triggers::type::homeassistant::event%]",
|
||||
"sunrise": "Sunrise",
|
||||
"sunset": "Sunset",
|
||||
"offset": "Offset (optional)"
|
||||
"offset": "Offset (optional)",
|
||||
"description": {
|
||||
"sets": "When the sun sets{hasDuration, select, \n true { offset by {duration}} \n other {}\n }",
|
||||
"rises": "When the sun rises{hasDuration, select, \n true { offset by {duration}} \n other {}\n }"
|
||||
}
|
||||
},
|
||||
"tag": {
|
||||
"label": "Tag"
|
||||
"label": "Tag",
|
||||
"description": {
|
||||
"full": "When a tag is scanned"
|
||||
}
|
||||
},
|
||||
"template": {
|
||||
"label": "Template",
|
||||
"value_template": "Value template",
|
||||
"for": "For"
|
||||
"for": "For",
|
||||
"description": {
|
||||
"full": "When a template triggers{hasDuration, select, \n true { for {duration}} \n other {}\n }"
|
||||
}
|
||||
},
|
||||
"time": {
|
||||
"type_value": "Fixed time",
|
||||
"type_input": "Value of a date/time helper or timestamp-class sensor",
|
||||
"label": "Time",
|
||||
"at": "At time",
|
||||
"mode": "Mode"
|
||||
"mode": "Mode",
|
||||
"description": {
|
||||
"full": "When the time is equal to {time}"
|
||||
}
|
||||
},
|
||||
"time_pattern": {
|
||||
"label": "Time Pattern",
|
||||
@ -2365,7 +2388,10 @@
|
||||
"local_only": "Only accessible from the local network",
|
||||
"webhook_id": "Webhook ID",
|
||||
"webhook_id_helper": "Treat this ID like a password: keep it secret, and make it hard to guess.",
|
||||
"webhook_settings": "Webhook Settings"
|
||||
"webhook_settings": "Webhook Settings",
|
||||
"description": {
|
||||
"full": "When a Webhook payload has been received"
|
||||
}
|
||||
},
|
||||
"zone": {
|
||||
"label": "Zone",
|
||||
|
Loading…
x
Reference in New Issue
Block a user