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:
@@ -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,
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -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;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user