diff --git a/src/components/ha-selector/ha-selector-choose.ts b/src/components/ha-selector/ha-selector-choose.ts index 253b36efcc..6f93a18689 100644 --- a/src/components/ha-selector/ha-selector-choose.ts +++ b/src/components/ha-selector/ha-selector-choose.ts @@ -20,6 +20,9 @@ export class HaChooseSelector extends LitElement { @property() public helper?: string; + @property({ attribute: false }) + public localizeValue?: (key: string) => string; + @property({ type: Boolean }) public disabled = false; @property({ type: Boolean }) public required = true; @@ -50,7 +53,7 @@ export class HaChooseSelector extends LitElement { size="small" .buttons=${this._toggleButtons( this.selector.choose.choices, - this.hass.localize + this.selector.choose.translation_key )} .active=${this._activeChoice} @value-changed=${this._choiceChanged} @@ -68,12 +71,12 @@ export class HaChooseSelector extends LitElement { } private _toggleButtons = memoizeOne( - ( - choices: ChooseSelector["choose"]["choices"], - localize: HomeAssistant["localize"] - ) => + (choices: ChooseSelector["choose"]["choices"], translationKey?: string) => Object.keys(choices).map((choice) => ({ - label: localize("") || choice, + label: + this.localizeValue && translationKey + ? this.localizeValue(`${translationKey}.choices.${choice}`) + : choice, value: choice, })) ); diff --git a/src/data/selector.ts b/src/data/selector.ts index c9e707db08..4a662490e9 100644 --- a/src/data/selector.ts +++ b/src/data/selector.ts @@ -120,6 +120,7 @@ export interface ButtonToggleSelector { export interface ChooseSelector { choose: { choices: Record; + translation_key?: string; }; }