diff --git a/demo/src/html/index.html.template b/demo/src/html/index.html.template index efd18b224fe3..a9decd45029d 100644 --- a/demo/src/html/index.html.template +++ b/demo/src/html/index.html.template @@ -1,5 +1,5 @@ - + diff --git a/src/auth/ha-authorize.ts b/src/auth/ha-authorize.ts index bf8feb268509..48567ccd3e2d 100644 --- a/src/auth/ha-authorize.ts +++ b/src/auth/ha-authorize.ts @@ -123,6 +123,13 @@ class HaAuthorize extends litLocalizeLiteMixin(LitElement) { } } + protected updated(changedProps: PropertyValues) { + super.updated(changedProps); + if (changedProps.has("language")) { + document.querySelector("html")!.setAttribute("lang", this.language!); + } + } + private async _fetchAuthProviders() { // Fetch auth providers try { diff --git a/src/html/authorize.html.template b/src/html/authorize.html.template index 9b057978f9bc..719a01479987 100644 --- a/src/html/authorize.html.template +++ b/src/html/authorize.html.template @@ -1,5 +1,5 @@ - + Home Assistant diff --git a/src/html/index.html.template b/src/html/index.html.template index de55383946cd..befab7158678 100644 --- a/src/html/index.html.template +++ b/src/html/index.html.template @@ -1,5 +1,5 @@ - + - + Home Assistant diff --git a/src/mixins/lit-localize-lite-mixin.ts b/src/mixins/lit-localize-lite-mixin.ts index c99d32c5a81f..60d8f192af63 100644 --- a/src/mixins/lit-localize-lite-mixin.ts +++ b/src/mixins/lit-localize-lite-mixin.ts @@ -19,23 +19,24 @@ export const litLocalizeLiteMixin = >( public connectedCallback(): void { super.connectedCallback(); this._initializeLocalizeLite(); - this.localize = computeLocalize( - this.constructor.prototype, - this.language!, - this.resources! - ); } protected updated(changedProperties: PropertyValues) { super.updated(changedProperties); + if (changedProperties.get("translationFragment")) { + this._initializeLocalizeLite(); + } + if ( - changedProperties.has("language") || - changedProperties.has("resources") + this.language && + this.resources && + (changedProperties.has("language") || + changedProperties.has("resources")) ) { this.localize = computeLocalize( this.constructor.prototype, - this.language!, - this.resources! + this.language, + this.resources ); } } diff --git a/src/onboarding/ha-onboarding.ts b/src/onboarding/ha-onboarding.ts index 9fa2cb8d75cf..3781e724cacb 100644 --- a/src/onboarding/ha-onboarding.ts +++ b/src/onboarding/ha-onboarding.ts @@ -95,6 +95,13 @@ class HaOnboarding extends litLocalizeLiteMixin(HassElement) { this.addEventListener("onboarding-step", (ev) => this._handleStepDone(ev)); } + protected updated(changedProps: PropertyValues) { + super.updated(changedProps); + if (changedProps.has("language")) { + document.querySelector("html")!.setAttribute("lang", this.language!); + } + } + private _curStep() { return this._steps ? this._steps.find((stp) => !stp.done) : undefined; } diff --git a/src/state/translations-mixin.ts b/src/state/translations-mixin.ts index da7c3f2f3fd0..1ab6bc48055a 100644 --- a/src/state/translations-mixin.ts +++ b/src/state/translations-mixin.ts @@ -68,11 +68,11 @@ export default >(superClass: T) => if (saveToBackend) { saveTranslationPreferences(this.hass, { language }); } - this._applyTranslations(this.hass); } private _applyTranslations(hass: HomeAssistant) { + document.querySelector("html")!.setAttribute("lang", hass.language); this.style.direction = computeRTL(hass) ? "rtl" : "ltr"; this._loadCoreTranslations(hass.language); this._loadHassTranslations(hass.language);