mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 15:26:36 +00:00
Support translating number selector UoM (#26070)
This commit is contained in:
parent
257769cdc7
commit
4d932f0b4a
@ -23,6 +23,9 @@ export class HaNumberSelector extends LitElement {
|
|||||||
|
|
||||||
@property() public helper?: string;
|
@property() public helper?: string;
|
||||||
|
|
||||||
|
@property({ attribute: false })
|
||||||
|
public localizeValue?: (key: string) => string;
|
||||||
|
|
||||||
@property({ type: Boolean }) public required = true;
|
@property({ type: Boolean }) public required = true;
|
||||||
|
|
||||||
@property({ type: Boolean }) public disabled = false;
|
@property({ type: Boolean }) public disabled = false;
|
||||||
@ -60,6 +63,14 @@ export class HaNumberSelector extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const translationKey = this.selector.number?.translation_key;
|
||||||
|
let unit = this.selector.number?.unit_of_measurement;
|
||||||
|
if (isBox && unit && this.localizeValue && translationKey) {
|
||||||
|
unit =
|
||||||
|
this.localizeValue(`${translationKey}.unit_of_measurement.${unit}`) ||
|
||||||
|
unit;
|
||||||
|
}
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
${this.label && !isBox
|
${this.label && !isBox
|
||||||
? html`${this.label}${this.required ? "*" : ""}`
|
? html`${this.label}${this.required ? "*" : ""}`
|
||||||
@ -97,7 +108,7 @@ export class HaNumberSelector extends LitElement {
|
|||||||
.helper=${isBox ? this.helper : undefined}
|
.helper=${isBox ? this.helper : undefined}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
.required=${this.required}
|
.required=${this.required}
|
||||||
.suffix=${this.selector.number?.unit_of_measurement}
|
.suffix=${unit}
|
||||||
type="number"
|
type="number"
|
||||||
autoValidate
|
autoValidate
|
||||||
?no-spinner=${!isBox}
|
?no-spinner=${!isBox}
|
||||||
|
@ -333,6 +333,7 @@ export interface NumberSelector {
|
|||||||
mode?: "box" | "slider";
|
mode?: "box" | "slider";
|
||||||
unit_of_measurement?: string;
|
unit_of_measurement?: string;
|
||||||
slider_ticks?: boolean;
|
slider_ticks?: boolean;
|
||||||
|
translation_key?: string;
|
||||||
} | null;
|
} | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user