From 83c5408f8f0d1552105ee351e323a13fd2e1714c Mon Sep 17 00:00:00 2001 From: karwosts <32912880+karwosts@users.noreply.github.com> Date: Wed, 17 Jan 2024 11:40:58 -0800 Subject: [PATCH] Minor form localizations (#19434) * Minor form localizations * missing imports --- src/auth/ha-auth-form-string.ts | 2 +- src/components/ha-form/ha-form-float.ts | 7 ++++++- src/components/ha-form/ha-form-integer.ts | 7 ++++++- src/components/ha-form/ha-form-string.ts | 4 +++- src/translations/en.json | 1 + 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/auth/ha-auth-form-string.ts b/src/auth/ha-auth-form-string.ts index a586f8cf4e..da47353aa6 100644 --- a/src/auth/ha-auth-form-string.ts +++ b/src/auth/ha-auth-form-string.ts @@ -59,7 +59,7 @@ export class HaAuthFormString extends HaFormString { html`
` : this.schema.description?.suffix } - .validationMessage=${this.schema.required ? "Required" : undefined} + .validationMessage=${this.schema.required ? this.localize?.("ui.panel.page-authorize.form.error_required") : undefined} @input=${this._valueChanged} @change=${this._valueChanged} > diff --git a/src/components/ha-form/ha-form-float.ts b/src/components/ha-form/ha-form-float.ts index 2ed59db428..cfee72ebe1 100644 --- a/src/components/ha-form/ha-form-float.ts +++ b/src/components/ha-form/ha-form-float.ts @@ -4,9 +4,12 @@ import { fireEvent } from "../../common/dom/fire_event"; import type { HaTextField } from "../ha-textfield"; import "../ha-textfield"; import { HaFormElement, HaFormFloatData, HaFormFloatSchema } from "./types"; +import { LocalizeFunc } from "../../common/translations/localize"; @customElement("ha-form-float") export class HaFormFloat extends LitElement implements HaFormElement { + @property({ attribute: false }) public localize?: LocalizeFunc; + @property({ attribute: false }) public schema!: HaFormFloatSchema; @property({ attribute: false }) public data!: HaFormFloatData; @@ -38,7 +41,9 @@ export class HaFormFloat extends LitElement implements HaFormElement { .required=${this.schema.required} .autoValidate=${this.schema.required} .suffix=${this.schema.description?.suffix} - .validationMessage=${this.schema.required ? "Required" : undefined} + .validationMessage=${this.schema.required + ? this.localize?.("ui.common.error_required") + : undefined} @input=${this._valueChanged} > `; diff --git a/src/components/ha-form/ha-form-integer.ts b/src/components/ha-form/ha-form-integer.ts index 1b311769db..2ce103b6bd 100644 --- a/src/components/ha-form/ha-form-integer.ts +++ b/src/components/ha-form/ha-form-integer.ts @@ -12,9 +12,12 @@ import { HaCheckbox } from "../ha-checkbox"; import "../ha-slider"; import { HaTextField } from "../ha-textfield"; import { HaFormElement, HaFormIntegerData, HaFormIntegerSchema } from "./types"; +import { LocalizeFunc } from "../../common/translations/localize"; @customElement("ha-form-integer") export class HaFormInteger extends LitElement implements HaFormElement { + @property({ attribute: false }) public localize?: LocalizeFunc; + @property({ attribute: false }) public schema!: HaFormIntegerSchema; @property({ attribute: false }) public data?: HaFormIntegerData; @@ -85,7 +88,9 @@ export class HaFormInteger extends LitElement implements HaFormElement { .required=${this.schema.required} .autoValidate=${this.schema.required} .suffix=${this.schema.description?.suffix} - .validationMessage=${this.schema.required ? "Required" : undefined} + .validationMessage=${this.schema.required + ? this.localize?.("ui.common.error_required") + : undefined} @input=${this._valueChanged} > `; diff --git a/src/components/ha-form/ha-form-string.ts b/src/components/ha-form/ha-form-string.ts index 83b4c69f39..a0a1757b80 100644 --- a/src/components/ha-form/ha-form-string.ts +++ b/src/components/ha-form/ha-form-string.ts @@ -70,7 +70,9 @@ export class HaFormString extends LitElement implements HaFormElement { ? // reserve some space for the icon. html`
` : this.schema.description?.suffix} - .validationMessage=${this.schema.required ? "Required" : undefined} + .validationMessage=${this.schema.required + ? this.localize?.("ui.common.error_required") + : undefined} @input=${this._valueChanged} @change=${this._valueChanged} > diff --git a/src/translations/en.json b/src/translations/en.json index df0409ca76..acd757020c 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -5894,6 +5894,7 @@ "previous": "Previous", "start_over": "Start over", "error": "Error: {error}", + "error_required": "[%key:ui::common::error_required%]", "hide_password": "Hide password", "show_password": "Show password", "providers": {