diff --git a/src/components/ha-selector/ha-selector-number.ts b/src/components/ha-selector/ha-selector-number.ts index 66fed152d9..f4aff5a7d5 100644 --- a/src/components/ha-selector/ha-selector-number.ts +++ b/src/components/ha-selector/ha-selector-number.ts @@ -23,6 +23,9 @@ export class HaNumberSelector extends LitElement { @property() public helper?: string; + @property({ attribute: false }) + public localizeValue?: (key: string) => string; + @property({ type: Boolean }) public required = true; @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` ${this.label && !isBox ? html`${this.label}${this.required ? "*" : ""}` @@ -97,7 +108,7 @@ export class HaNumberSelector extends LitElement { .helper=${isBox ? this.helper : undefined} .disabled=${this.disabled} .required=${this.required} - .suffix=${this.selector.number?.unit_of_measurement} + .suffix=${unit} type="number" autoValidate ?no-spinner=${!isBox} diff --git a/src/data/selector.ts b/src/data/selector.ts index abac290475..dacd2c0c56 100644 --- a/src/data/selector.ts +++ b/src/data/selector.ts @@ -333,6 +333,7 @@ export interface NumberSelector { mode?: "box" | "slider"; unit_of_measurement?: string; slider_ticks?: boolean; + translation_key?: string; } | null; }