mirror of
https://github.com/home-assistant/frontend.git
synced 2025-12-19 18:28:42 +00:00
add support for translation
This commit is contained in:
@@ -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,
|
||||
}))
|
||||
);
|
||||
|
||||
@@ -120,6 +120,7 @@ export interface ButtonToggleSelector {
|
||||
export interface ChooseSelector {
|
||||
choose: {
|
||||
choices: Record<string, { selector: Selector }>;
|
||||
translation_key?: string;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user