mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Use translations for all fields in recurrence rule editor (#14940)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
parent
afcd45a780
commit
e3ac2c149d
@ -6,6 +6,7 @@ import type { Options, WeekdayStr } from "rrule";
|
|||||||
import { ByWeekday, RRule, Weekday } from "rrule";
|
import { ByWeekday, RRule, Weekday } from "rrule";
|
||||||
import { firstWeekdayIndex } from "../../common/datetime/first_weekday";
|
import { firstWeekdayIndex } from "../../common/datetime/first_weekday";
|
||||||
import { stopPropagation } from "../../common/dom/stop_propagation";
|
import { stopPropagation } from "../../common/dom/stop_propagation";
|
||||||
|
import { LocalizeKeys } from "../../common/translations/localize";
|
||||||
import "../../components/ha-chip";
|
import "../../components/ha-chip";
|
||||||
import "../../components/ha-list-item";
|
import "../../components/ha-list-item";
|
||||||
import "../../components/ha-select";
|
import "../../components/ha-select";
|
||||||
@ -19,12 +20,10 @@ import {
|
|||||||
getWeekday,
|
getWeekday,
|
||||||
getWeekdays,
|
getWeekdays,
|
||||||
getMonthlyRepeatItems,
|
getMonthlyRepeatItems,
|
||||||
intervalSuffix,
|
|
||||||
RepeatEnd,
|
RepeatEnd,
|
||||||
RepeatFrequency,
|
RepeatFrequency,
|
||||||
ruleByWeekDay,
|
ruleByWeekDay,
|
||||||
untilValue,
|
untilValue,
|
||||||
WEEKDAY_NAME,
|
|
||||||
MonthlyRepeatItem,
|
MonthlyRepeatItem,
|
||||||
getMonthlyRepeatWeekdayFromRule,
|
getMonthlyRepeatWeekdayFromRule,
|
||||||
getMonthdayRepeatFromRule,
|
getMonthdayRepeatFromRule,
|
||||||
@ -174,18 +173,36 @@ export class RecurrenceRuleEditor extends LitElement {
|
|||||||
return html`
|
return html`
|
||||||
<ha-select
|
<ha-select
|
||||||
id="freq"
|
id="freq"
|
||||||
label="Repeat"
|
label=${this.hass.localize("ui.components.calendar.event.repeat.label")}
|
||||||
@selected=${this._onRepeatSelected}
|
@selected=${this._onRepeatSelected}
|
||||||
@closed=${stopPropagation}
|
@closed=${stopPropagation}
|
||||||
fixedMenuPosition
|
fixedMenuPosition
|
||||||
naturalMenuWidth
|
naturalMenuWidth
|
||||||
.value=${this._freq}
|
.value=${this._freq}
|
||||||
>
|
>
|
||||||
<ha-list-item value="none">None</ha-list-item>
|
<ha-list-item value="none">
|
||||||
<ha-list-item value="yearly">Yearly</ha-list-item>
|
${this.hass.localize("ui.components.calendar.event.repeat.freq.none")}
|
||||||
<ha-list-item value="monthly">Monthly</ha-list-item>
|
</ha-list-item>
|
||||||
<ha-list-item value="weekly">Weekly</ha-list-item>
|
<ha-list-item value="yearly">
|
||||||
<ha-list-item value="daily">Daily</ha-list-item>
|
${this.hass.localize(
|
||||||
|
"ui.components.calendar.event.repeat.freq.yearly"
|
||||||
|
)}
|
||||||
|
</ha-list-item>
|
||||||
|
<ha-list-item value="monthly">
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.components.calendar.event.repeat.freq.monthly"
|
||||||
|
)}
|
||||||
|
</ha-list-item>
|
||||||
|
<ha-list-item value="weekly">
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.components.calendar.event.repeat.freq.weekly"
|
||||||
|
)}
|
||||||
|
</ha-list-item>
|
||||||
|
<ha-list-item value="daily">
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.components.calendar.event.repeat.freq.daily"
|
||||||
|
)}
|
||||||
|
</ha-list-item>
|
||||||
</ha-select>
|
</ha-select>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@ -196,7 +213,9 @@ export class RecurrenceRuleEditor extends LitElement {
|
|||||||
${this._monthlyRepeatItems.length > 0
|
${this._monthlyRepeatItems.length > 0
|
||||||
? html`<ha-select
|
? html`<ha-select
|
||||||
id="monthly"
|
id="monthly"
|
||||||
label="Repeat Monthly"
|
label=${this.hass.localize(
|
||||||
|
"ui.components.calendar.event.repeat.monthly.label"
|
||||||
|
)}
|
||||||
@selected=${this._onMonthlyDetailSelected}
|
@selected=${this._onMonthlyDetailSelected}
|
||||||
.value=${this._monthlyRepeat || this._monthlyRepeatItems[0]?.value}
|
.value=${this._monthlyRepeat || this._monthlyRepeatItems[0]?.value}
|
||||||
@closed=${stopPropagation}
|
@closed=${stopPropagation}
|
||||||
@ -225,7 +244,11 @@ export class RecurrenceRuleEditor extends LitElement {
|
|||||||
.value=${item}
|
.value=${item}
|
||||||
class=${classMap({ active: this._weekday.has(item) })}
|
class=${classMap({ active: this._weekday.has(item) })}
|
||||||
@click=${this._onWeekdayToggle}
|
@click=${this._onWeekdayToggle}
|
||||||
>${WEEKDAY_NAME[item]}</ha-chip
|
>${this.hass.localize(
|
||||||
|
`ui.components.calendar.event.repeat.weekly.weekday.${
|
||||||
|
item.toLowerCase() as Lowercase<WeekdayStr>
|
||||||
|
}`
|
||||||
|
)}</ha-chip
|
||||||
>
|
>
|
||||||
`
|
`
|
||||||
)}
|
)}
|
||||||
@ -241,11 +264,16 @@ export class RecurrenceRuleEditor extends LitElement {
|
|||||||
return html`
|
return html`
|
||||||
<ha-textfield
|
<ha-textfield
|
||||||
id="interval"
|
id="interval"
|
||||||
label="Repeat interval"
|
label=${this.hass.localize(
|
||||||
|
"ui.components.calendar.event.repeat.interval.label"
|
||||||
|
)}
|
||||||
type="number"
|
type="number"
|
||||||
min="1"
|
min="1"
|
||||||
.value=${this._interval}
|
.value=${this._interval}
|
||||||
.suffix=${intervalSuffix(this._freq!)}
|
.suffix=${this.hass.localize(
|
||||||
|
`ui.components.calendar.event.repeat.interval.${this
|
||||||
|
._freq!}` as LocalizeKeys
|
||||||
|
)}
|
||||||
@change=${this._onIntervalChange}
|
@change=${this._onIntervalChange}
|
||||||
></ha-textfield>
|
></ha-textfield>
|
||||||
`;
|
`;
|
||||||
@ -255,26 +283,38 @@ export class RecurrenceRuleEditor extends LitElement {
|
|||||||
return html`
|
return html`
|
||||||
<ha-select
|
<ha-select
|
||||||
id="end"
|
id="end"
|
||||||
label="Ends"
|
label=${this.hass.localize(
|
||||||
|
"ui.components.calendar.event.repeat.end.label"
|
||||||
|
)}
|
||||||
.value=${this._end}
|
.value=${this._end}
|
||||||
@selected=${this._onEndSelected}
|
@selected=${this._onEndSelected}
|
||||||
@closed=${stopPropagation}
|
@closed=${stopPropagation}
|
||||||
fixedMenuPosition
|
fixedMenuPosition
|
||||||
naturalMenuWidth
|
naturalMenuWidth
|
||||||
>
|
>
|
||||||
<ha-list-item value="never">Never</ha-list-item>
|
<ha-list-item value="never">
|
||||||
<ha-list-item value="after">After</ha-list-item>
|
${this.hass.localize("ui.components.calendar.event.repeat.end.never")}
|
||||||
<ha-list-item value="on">On</ha-list-item>
|
</ha-list-item>
|
||||||
|
<ha-list-item value="after">
|
||||||
|
${this.hass.localize("ui.components.calendar.event.repeat.end.after")}
|
||||||
|
</ha-list-item>
|
||||||
|
<ha-list-item value="on">
|
||||||
|
${this.hass.localize("ui.components.calendar.event.repeat.end.on")}
|
||||||
|
</ha-list-item>
|
||||||
</ha-select>
|
</ha-select>
|
||||||
${this._end === "after"
|
${this._end === "after"
|
||||||
? html`
|
? html`
|
||||||
<ha-textfield
|
<ha-textfield
|
||||||
id="after"
|
id="after"
|
||||||
label="End after"
|
label=${this.hass.localize(
|
||||||
|
"ui.components.calendar.event.repeat.end_after.label"
|
||||||
|
)}
|
||||||
type="number"
|
type="number"
|
||||||
min="1"
|
min="1"
|
||||||
.value=${this._count!}
|
.value=${this._count!}
|
||||||
suffix="ocurrences"
|
suffix=${this.hass.localize(
|
||||||
|
"ui.components.calendar.event.repeat.end_after.ocurrences"
|
||||||
|
)}
|
||||||
@change=${this._onCountChange}
|
@change=${this._onCountChange}
|
||||||
></ha-textfield>
|
></ha-textfield>
|
||||||
`
|
`
|
||||||
@ -283,7 +323,9 @@ export class RecurrenceRuleEditor extends LitElement {
|
|||||||
? html`
|
? html`
|
||||||
<ha-date-input
|
<ha-date-input
|
||||||
id="on"
|
id="on"
|
||||||
label="End on"
|
label=${this.hass.localize(
|
||||||
|
"ui.components.calendar.event.repeat.end_on.label"
|
||||||
|
)}
|
||||||
.locale=${this.locale}
|
.locale=${this.locale}
|
||||||
.value=${this._until!.toISOString()}
|
.value=${this._until!.toISOString()}
|
||||||
@value-changed=${this._onUntilChange}
|
@value-changed=${this._onUntilChange}
|
||||||
|
@ -42,16 +42,6 @@ export interface MonthlyRepeatItem {
|
|||||||
label: string;
|
label: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function intervalSuffix(freq: RepeatFrequency) {
|
|
||||||
if (freq === "monthly") {
|
|
||||||
return "months";
|
|
||||||
}
|
|
||||||
if (freq === "weekly") {
|
|
||||||
return "weeks";
|
|
||||||
}
|
|
||||||
return "days";
|
|
||||||
}
|
|
||||||
|
|
||||||
export function untilValue(freq: RepeatFrequency): Date {
|
export function untilValue(freq: RepeatFrequency): Date {
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
const increment = DEFAULT_COUNT[freq];
|
const increment = DEFAULT_COUNT[freq];
|
||||||
@ -102,16 +92,6 @@ export const convertRepeatFrequency = (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const WEEKDAY_NAME = {
|
|
||||||
SU: "Sun",
|
|
||||||
MO: "Mon",
|
|
||||||
TU: "Tue",
|
|
||||||
WE: "Wed",
|
|
||||||
TH: "Thu",
|
|
||||||
FR: "Fri",
|
|
||||||
SA: "Sat",
|
|
||||||
};
|
|
||||||
|
|
||||||
export const WEEKDAYS = [
|
export const WEEKDAYS = [
|
||||||
RRule.SU,
|
RRule.SU,
|
||||||
RRule.MO,
|
RRule.MO,
|
||||||
|
@ -644,6 +644,33 @@
|
|||||||
"monthly": "months",
|
"monthly": "months",
|
||||||
"weekly": "weeks",
|
"weekly": "weeks",
|
||||||
"daily": "days"
|
"daily": "days"
|
||||||
|
},
|
||||||
|
"monthly": {
|
||||||
|
"label": "Repeat Monthly"
|
||||||
|
},
|
||||||
|
"weekly": {
|
||||||
|
"weekday": {
|
||||||
|
"su": "Sun",
|
||||||
|
"mo": "Mon",
|
||||||
|
"tu": "Tue",
|
||||||
|
"we": "Wed",
|
||||||
|
"th": "Thu",
|
||||||
|
"fr": "Fri",
|
||||||
|
"sa": "Sat"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"label": "End",
|
||||||
|
"never": "Never",
|
||||||
|
"after": "After",
|
||||||
|
"on": "On"
|
||||||
|
},
|
||||||
|
"end_on": {
|
||||||
|
"label": "End On"
|
||||||
|
},
|
||||||
|
"end_after": {
|
||||||
|
"label": "End After",
|
||||||
|
"ocurrences": "ocurrences"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"rrule": {
|
"rrule": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user