Skip to content

Commit

Permalink
Set correct lang attribute (home-assistant#5479)
Browse files Browse the repository at this point in the history
* Set correct lang attribute

* Update lit-localize-lite-mixin.ts

* Update translations-mixin.ts

* Remove lang=""

* Move logic out of mixin
  • Loading branch information
bramkragten authored Apr 8, 2020
1 parent a71f423 commit 4f70ec7
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 14 deletions.
2 changes: 1 addition & 1 deletion demo/src/html/index.html.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<meta charset="utf-8" />
<link rel="manifest" href="/manifest.json" crossorigin="use-credentials" />
Expand Down
7 changes: 7 additions & 0 deletions src/auth/ha-authorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/html/authorize.html.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<title>Home Assistant</title>
<link rel="preload" href="<%= latestPageJS %>" as="script" crossorigin="use-credentials" />
Expand Down
2 changes: 1 addition & 1 deletion src/html/index.html.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<link rel="preload" href="<%= latestCoreJS %>" as="script" crossorigin="use-credentials" />
<link
Expand Down
2 changes: 1 addition & 1 deletion src/html/onboarding.html.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<title>Home Assistant</title>
<link rel="preload" href="<%= latestPageJS %>" as="script" crossorigin="use-credentials" />
Expand Down
19 changes: 10 additions & 9 deletions src/mixins/lit-localize-lite-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,24 @@ export const litLocalizeLiteMixin = <T extends Constructor<LitElement>>(
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
);
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/onboarding/ha-onboarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/state/translations-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ export default <T extends Constructor<HassBaseEl>>(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);
Expand Down

0 comments on commit 4f70ec7

Please sign in to comment.