Set correct lang attribute (#5479)

* Set correct lang attribute

* Update lit-localize-lite-mixin.ts

* Update translations-mixin.ts

* Remove lang=""

* Move logic out of mixin
This commit is contained in:
Bram Kragten 2020-04-08 12:36:06 +02:00 committed by GitHub
parent a71f42366a
commit 4f70ec7dc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 29 additions and 14 deletions

View File

@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html>
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<link rel="manifest" href="/manifest.json" crossorigin="use-credentials" /> <link rel="manifest" href="/manifest.json" crossorigin="use-credentials" />

View File

@ -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() { private async _fetchAuthProviders() {
// Fetch auth providers // Fetch auth providers
try { try {

View File

@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html>
<head> <head>
<title>Home Assistant</title> <title>Home Assistant</title>
<link rel="preload" href="<%= latestPageJS %>" as="script" crossorigin="use-credentials" /> <link rel="preload" href="<%= latestPageJS %>" as="script" crossorigin="use-credentials" />

View File

@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html>
<head> <head>
<link rel="preload" href="<%= latestCoreJS %>" as="script" crossorigin="use-credentials" /> <link rel="preload" href="<%= latestCoreJS %>" as="script" crossorigin="use-credentials" />
<link <link

View File

@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html>
<head> <head>
<title>Home Assistant</title> <title>Home Assistant</title>
<link rel="preload" href="<%= latestPageJS %>" as="script" crossorigin="use-credentials" /> <link rel="preload" href="<%= latestPageJS %>" as="script" crossorigin="use-credentials" />

View File

@ -19,23 +19,24 @@ export const litLocalizeLiteMixin = <T extends Constructor<LitElement>>(
public connectedCallback(): void { public connectedCallback(): void {
super.connectedCallback(); super.connectedCallback();
this._initializeLocalizeLite(); this._initializeLocalizeLite();
this.localize = computeLocalize(
this.constructor.prototype,
this.language!,
this.resources!
);
} }
protected updated(changedProperties: PropertyValues) { protected updated(changedProperties: PropertyValues) {
super.updated(changedProperties); super.updated(changedProperties);
if (changedProperties.get("translationFragment")) {
this._initializeLocalizeLite();
}
if ( if (
changedProperties.has("language") || this.language &&
changedProperties.has("resources") this.resources &&
(changedProperties.has("language") ||
changedProperties.has("resources"))
) { ) {
this.localize = computeLocalize( this.localize = computeLocalize(
this.constructor.prototype, this.constructor.prototype,
this.language!, this.language,
this.resources! this.resources
); );
} }
} }

View File

@ -95,6 +95,13 @@ class HaOnboarding extends litLocalizeLiteMixin(HassElement) {
this.addEventListener("onboarding-step", (ev) => this._handleStepDone(ev)); 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() { private _curStep() {
return this._steps ? this._steps.find((stp) => !stp.done) : undefined; return this._steps ? this._steps.find((stp) => !stp.done) : undefined;
} }

View File

@ -68,11 +68,11 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
if (saveToBackend) { if (saveToBackend) {
saveTranslationPreferences(this.hass, { language }); saveTranslationPreferences(this.hass, { language });
} }
this._applyTranslations(this.hass); this._applyTranslations(this.hass);
} }
private _applyTranslations(hass: HomeAssistant) { private _applyTranslations(hass: HomeAssistant) {
document.querySelector("html")!.setAttribute("lang", hass.language);
this.style.direction = computeRTL(hass) ? "rtl" : "ltr"; this.style.direction = computeRTL(hass) ? "rtl" : "ltr";
this._loadCoreTranslations(hass.language); this._loadCoreTranslations(hass.language);
this._loadHassTranslations(hass.language); this._loadHassTranslations(hass.language);