1
0
mirror of https://github.com/home-assistant/frontend.git synced 2025-12-20 02:38:53 +00:00

add support for translation

This commit is contained in:
Bram Kragten
2025-12-19 12:56:22 +01:00
parent 999c671cb9
commit f61b2818be
2 changed files with 10 additions and 6 deletions

View File

@@ -20,6 +20,9 @@ export class HaChooseSelector extends LitElement {
@property() public helper?: string; @property() public helper?: string;
@property({ attribute: false })
public localizeValue?: (key: string) => string;
@property({ type: Boolean }) public disabled = false; @property({ type: Boolean }) public disabled = false;
@property({ type: Boolean }) public required = true; @property({ type: Boolean }) public required = true;
@@ -50,7 +53,7 @@ export class HaChooseSelector extends LitElement {
size="small" size="small"
.buttons=${this._toggleButtons( .buttons=${this._toggleButtons(
this.selector.choose.choices, this.selector.choose.choices,
this.hass.localize this.selector.choose.translation_key
)} )}
.active=${this._activeChoice} .active=${this._activeChoice}
@value-changed=${this._choiceChanged} @value-changed=${this._choiceChanged}
@@ -68,12 +71,12 @@ export class HaChooseSelector extends LitElement {
} }
private _toggleButtons = memoizeOne( private _toggleButtons = memoizeOne(
( (choices: ChooseSelector["choose"]["choices"], translationKey?: string) =>
choices: ChooseSelector["choose"]["choices"],
localize: HomeAssistant["localize"]
) =>
Object.keys(choices).map((choice) => ({ Object.keys(choices).map((choice) => ({
label: localize("") || choice, label:
this.localizeValue && translationKey
? this.localizeValue(`${translationKey}.choices.${choice}`)
: choice,
value: choice, value: choice,
})) }))
); );

View File

@@ -120,6 +120,7 @@ export interface ButtonToggleSelector {
export interface ChooseSelector { export interface ChooseSelector {
choose: { choose: {
choices: Record<string, { selector: Selector }>; choices: Record<string, { selector: Selector }>;
translation_key?: string;
}; };
} }