Skip to content

Commit 4333b0f

Browse files
committed
Add translations
1 parent 4ed42ef commit 4333b0f

File tree

2 files changed

+50
-18
lines changed

2 files changed

+50
-18
lines changed

src/common/datetime/weekday.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,13 @@ export const WEEKDAY_MAP: Record<WeekdayIndex, WeekdayShort> = {
4747
5: "fri",
4848
6: "sat",
4949
};
50+
51+
export const WEEKDAY_SHORT_TO_LONG: Record<WeekdayShort, WeekdayLong> = {
52+
sun: "sunday",
53+
mon: "monday",
54+
tue: "tuesday",
55+
wed: "wednesday",
56+
thu: "thursday",
57+
fri: "friday",
58+
sat: "saturday",
59+
};

src/panels/lovelace/editor/conditions/types/ha-card-condition-time.ts

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,19 @@ import {
99
assert,
1010
enums,
1111
} from "superstruct";
12+
import memoizeOne from "memoize-one";
1213
import type { HomeAssistant } from "../../../../../types";
14+
import type { LocalizeFunc } from "../../../../../common/translations/localize";
15+
import {
16+
WEEKDAY_SHORT_TO_LONG,
17+
WEEKDAYS_SHORT,
18+
} from "../../../../../common/datetime/weekday";
1319
import type { TimeCondition } from "../../../common/validate-condition";
14-
import { WEEKDAYS_SHORT } from "../../../../../common/datetime/weekday";
15-
import type { HaFormSchema } from "../../../../../components/ha-form/types";
1620
import { fireEvent } from "../../../../../common/dom/fire_event";
21+
import type {
22+
HaFormSchema,
23+
SchemaUnion,
24+
} from "../../../../../components/ha-form/types";
1725

1826
const timeConditionStruct = object({
1927
condition: literal("time"),
@@ -22,21 +30,6 @@ const timeConditionStruct = object({
2230
weekdays: optional(array(enums(WEEKDAYS_SHORT))),
2331
});
2432

25-
const SCHEMA = [
26-
{ name: "after", selector: { time: {} } },
27-
{ name: "before", selector: { time: {} } },
28-
{
29-
name: "weekdays",
30-
selector: {
31-
select: {
32-
mode: "list",
33-
multiple: true,
34-
options: WEEKDAYS_SHORT,
35-
},
36-
},
37-
},
38-
] as const satisfies HaFormSchema[];
39-
4033
@customElement("ha-card-condition-time")
4134
export class HaCardConditionTime extends LitElement {
4235
@property({ attribute: false }) public hass!: HomeAssistant;
@@ -53,12 +46,34 @@ export class HaCardConditionTime extends LitElement {
5346
return assert(condition, timeConditionStruct);
5447
}
5548

49+
private _schema = memoizeOne(
50+
(localize: LocalizeFunc) =>
51+
[
52+
{ name: "after", selector: { time: {} } },
53+
{ name: "before", selector: { time: {} } },
54+
{
55+
name: "weekdays",
56+
selector: {
57+
select: {
58+
mode: "list",
59+
multiple: true,
60+
options: WEEKDAYS_SHORT.map((day) => ({
61+
value: day,
62+
label: localize(`ui.weekdays.${WEEKDAY_SHORT_TO_LONG[day]}`),
63+
})),
64+
},
65+
},
66+
},
67+
] as const satisfies HaFormSchema[]
68+
);
69+
5670
protected render() {
5771
return html`
5872
<ha-form
5973
.hass=${this.hass}
6074
.data=${this.condition}
61-
.schema=${SCHEMA}
75+
.computeLabel=${this._computeLabelCallback}
76+
.schema=${this._schema(this.hass.localize)}
6277
.disabled=${this.disabled}
6378
@value-changed=${this._valueChanged}
6479
></ha-form>
@@ -70,6 +85,13 @@ export class HaCardConditionTime extends LitElement {
7085
const data = ev.detail.value as TimeCondition;
7186
fireEvent(this, "value-changed", { value: data });
7287
}
88+
89+
private _computeLabelCallback = (
90+
schema: SchemaUnion<ReturnType<typeof this._schema>>
91+
): string =>
92+
this.hass.localize(
93+
`ui.panel.lovelace.editor.condition-editor.condition.time.${schema.name}`
94+
);
7395
}
7496

7597
declare global {

0 commit comments

Comments
 (0)