mirror of
https://github.com/home-assistant/frontend.git
synced 2025-08-01 13:37:47 +00:00
Add language picker to onboarding (#17668)
This commit is contained in:
parent
e8f1a86005
commit
a8e17da9f3
@ -35,6 +35,8 @@ export class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
|
|||||||
|
|
||||||
@property() public oauth2State?: string;
|
@property() public oauth2State?: string;
|
||||||
|
|
||||||
|
@property() public translationFragment = "page-authorize";
|
||||||
|
|
||||||
@state() private _authProvider?: AuthProvider;
|
@state() private _authProvider?: AuthProvider;
|
||||||
|
|
||||||
@state() private _authProviders?: AuthProvider[];
|
@state() private _authProviders?: AuthProvider[];
|
||||||
@ -45,7 +47,6 @@ export class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.translationFragment = "page-authorize";
|
|
||||||
const query = extractSearchParamsObject() as AuthUrlSearchParams;
|
const query = extractSearchParamsObject() as AuthUrlSearchParams;
|
||||||
if (query.client_id) {
|
if (query.client_id) {
|
||||||
this.clientId = query.client_id;
|
this.clientId = query.client_id;
|
||||||
@ -102,7 +103,6 @@ export class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
|
|||||||
: nothing}
|
: nothing}
|
||||||
|
|
||||||
<ha-auth-flow
|
<ha-auth-flow
|
||||||
.resources=${this.resources}
|
|
||||||
.clientId=${this.clientId}
|
.clientId=${this.clientId}
|
||||||
.redirectUri=${this.redirectUri}
|
.redirectUri=${this.redirectUri}
|
||||||
.oauth2State=${this.oauth2State}
|
.oauth2State=${this.oauth2State}
|
||||||
|
@ -14,24 +14,9 @@
|
|||||||
padding: 64px 0;
|
padding: 64px 0;
|
||||||
}
|
}
|
||||||
.content {
|
.content {
|
||||||
box-sizing: border-box;
|
|
||||||
padding: 20px 16px;
|
|
||||||
border-radius: var(--ha-card-border-radius, 12px);
|
|
||||||
max-width: 432px;
|
max-width: 432px;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
box-shadow: var(
|
box-sizing: border-box;
|
||||||
--ha-card-box-shadow,
|
|
||||||
rgba(0, 0, 0, 0.25) 0px 54px 55px,
|
|
||||||
rgba(0, 0, 0, 0.12) 0px -12px 30px,
|
|
||||||
rgba(0, 0, 0, 0.12) 0px 4px 6px,
|
|
||||||
rgba(0, 0, 0, 0.17) 0px 12px 13px,
|
|
||||||
rgba(0, 0, 0, 0.09) 0px -3px 5px
|
|
||||||
);
|
|
||||||
background: var(
|
|
||||||
--ha-card-background,
|
|
||||||
var(--card-background-color, white)
|
|
||||||
);
|
|
||||||
color: var(--primary-text-color, #212121);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.header {
|
.header {
|
||||||
@ -41,6 +26,8 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
font-weight: 300;
|
font-weight: 300;
|
||||||
|
color: var(--text-primary-color, #fff);
|
||||||
|
margin-bottom: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.header img {
|
.header img {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { LitElement, PropertyValues } from "lit";
|
import { LitElement, PropertyValues } from "lit";
|
||||||
import { property } from "lit/decorators";
|
import { property, state } from "lit/decorators";
|
||||||
import { computeLocalize, LocalizeFunc } from "../common/translations/localize";
|
import { computeLocalize, LocalizeFunc } from "../common/translations/localize";
|
||||||
import { Constructor, Resources } from "../types";
|
import { Constructor, Resources } from "../types";
|
||||||
import { getLocalLanguage, getTranslation } from "../util/common-translation";
|
import { getLocalLanguage, getTranslation } from "../util/common-translation";
|
||||||
@ -15,13 +15,13 @@ export const litLocalizeLiteMixin = <T extends Constructor<LitElement>>(
|
|||||||
// Initialized to empty will prevent undefined errors if called before connected to DOM.
|
// Initialized to empty will prevent undefined errors if called before connected to DOM.
|
||||||
@property() public localize: LocalizeFunc = empty;
|
@property() public localize: LocalizeFunc = empty;
|
||||||
|
|
||||||
@property() public resources?: Resources;
|
|
||||||
|
|
||||||
// Use browser language setup before login.
|
// Use browser language setup before login.
|
||||||
@property() public language?: string = getLocalLanguage();
|
@property() public language?: string = getLocalLanguage();
|
||||||
|
|
||||||
@property() public translationFragment?: string;
|
@property() public translationFragment?: string;
|
||||||
|
|
||||||
|
@state() private _resources?: Resources;
|
||||||
|
|
||||||
public connectedCallback(): void {
|
public connectedCallback(): void {
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
this._initializeLocalizeLite();
|
this._initializeLocalizeLite();
|
||||||
@ -35,22 +35,27 @@ export const litLocalizeLiteMixin = <T extends Constructor<LitElement>>(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected updated(changedProperties: PropertyValues) {
|
protected willUpdate(changedProperties: PropertyValues) {
|
||||||
super.updated(changedProperties);
|
super.willUpdate(changedProperties);
|
||||||
|
if (changedProperties.get("language")) {
|
||||||
|
this._resources = undefined;
|
||||||
|
this._initializeLocalizeLite();
|
||||||
|
}
|
||||||
|
|
||||||
if (changedProperties.get("translationFragment")) {
|
if (changedProperties.get("translationFragment")) {
|
||||||
this._initializeLocalizeLite();
|
this._initializeLocalizeLite();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this.language &&
|
this.language &&
|
||||||
this.resources &&
|
this._resources &&
|
||||||
(changedProperties.has("language") ||
|
(changedProperties.has("language") ||
|
||||||
changedProperties.has("resources"))
|
changedProperties.has("_resources"))
|
||||||
) {
|
) {
|
||||||
computeLocalize(
|
computeLocalize(
|
||||||
this.constructor.prototype,
|
this.constructor.prototype,
|
||||||
this.language,
|
this.language,
|
||||||
this.resources
|
this._resources
|
||||||
).then((localize) => {
|
).then((localize) => {
|
||||||
this.localize = localize;
|
this.localize = localize;
|
||||||
});
|
});
|
||||||
@ -58,7 +63,7 @@ export const litLocalizeLiteMixin = <T extends Constructor<LitElement>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected async _initializeLocalizeLite() {
|
protected async _initializeLocalizeLite() {
|
||||||
if (this.resources) {
|
if (this._resources) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +73,7 @@ export const litLocalizeLiteMixin = <T extends Constructor<LitElement>>(
|
|||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
setTimeout(
|
setTimeout(
|
||||||
() =>
|
() =>
|
||||||
!this.resources &&
|
!this._resources &&
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
console.error(
|
console.error(
|
||||||
"Forgot to pass in resources or set translationFragment for",
|
"Forgot to pass in resources or set translationFragment for",
|
||||||
@ -84,7 +89,7 @@ export const litLocalizeLiteMixin = <T extends Constructor<LitElement>>(
|
|||||||
this.translationFragment!,
|
this.translationFragment!,
|
||||||
this.language!
|
this.language!
|
||||||
);
|
);
|
||||||
this.resources = {
|
this._resources = {
|
||||||
[this.language!]: data,
|
[this.language!]: data,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import {
|
|||||||
getAuth,
|
getAuth,
|
||||||
subscribeConfig,
|
subscribeConfig,
|
||||||
} from "home-assistant-js-websocket";
|
} from "home-assistant-js-websocket";
|
||||||
import { html, PropertyValues, nothing } from "lit";
|
import { html, PropertyValues, nothing, css } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { applyThemesOnElement } from "../common/dom/apply_themes_on_element";
|
import { applyThemesOnElement } from "../common/dom/apply_themes_on_element";
|
||||||
import { HASSDomEvent } from "../common/dom/fire_event";
|
import { HASSDomEvent } from "../common/dom/fire_event";
|
||||||
@ -27,6 +27,9 @@ import { registerServiceWorker } from "../util/register-service-worker";
|
|||||||
import "./onboarding-analytics";
|
import "./onboarding-analytics";
|
||||||
import "./onboarding-create-user";
|
import "./onboarding-create-user";
|
||||||
import "./onboarding-loading";
|
import "./onboarding-loading";
|
||||||
|
import "../components/ha-language-picker";
|
||||||
|
import "../components/ha-card";
|
||||||
|
import { storeState } from "../util/ha-pref-storage";
|
||||||
import {
|
import {
|
||||||
enableWrite,
|
enableWrite,
|
||||||
loadTokens,
|
loadTokens,
|
||||||
@ -74,6 +77,21 @@ class HaOnboarding extends litLocalizeLiteMixin(HassElement) {
|
|||||||
@state() private _steps?: OnboardingStep[];
|
@state() private _steps?: OnboardingStep[];
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
|
return html`<ha-card>
|
||||||
|
<div class="card-content">${this._renderStep()}</div>
|
||||||
|
</ha-card>
|
||||||
|
${this.hass
|
||||||
|
? html`<ha-language-picker
|
||||||
|
.hass=${this.hass}
|
||||||
|
.value=${this.language}
|
||||||
|
.label=${this.localize("ui.panel.page-onboarding.language")}
|
||||||
|
nativeName
|
||||||
|
@value-changed=${this._languageChanged}
|
||||||
|
></ha-language-picker>`
|
||||||
|
: nothing} `;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _renderStep() {
|
||||||
const step = this._curStep()!;
|
const step = this._curStep()!;
|
||||||
|
|
||||||
if (this._loading || !step) {
|
if (this._loading || !step) {
|
||||||
@ -114,7 +132,6 @@ class HaOnboarding extends litLocalizeLiteMixin(HassElement) {
|
|||||||
></onboarding-analytics>
|
></onboarding-analytics>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (step.step === "integration") {
|
if (step.step === "integration") {
|
||||||
return html`
|
return html`
|
||||||
<onboarding-integrations
|
<onboarding-integrations
|
||||||
@ -338,6 +355,31 @@ class HaOnboarding extends litLocalizeLiteMixin(HassElement) {
|
|||||||
setTimeout(resolve, 0);
|
setTimeout(resolve, 0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _languageChanged(ev: CustomEvent) {
|
||||||
|
const language = ev.detail.value;
|
||||||
|
this.language = language;
|
||||||
|
this._updateHass({
|
||||||
|
locale: { ...this.hass!.locale, language },
|
||||||
|
language,
|
||||||
|
selectedLanguage: language,
|
||||||
|
});
|
||||||
|
storeState(this.hass!);
|
||||||
|
}
|
||||||
|
|
||||||
|
static styles = css`
|
||||||
|
ha-language-picker {
|
||||||
|
display: block;
|
||||||
|
width: 200px;
|
||||||
|
margin-top: 8px;
|
||||||
|
--mdc-select-fill-color: none;
|
||||||
|
--mdc-select-label-ink-color: var(--text-primary-color, #fff);
|
||||||
|
--mdc-select-ink-color: var(--text-primary-color, #fff);
|
||||||
|
--mdc-select-idle-line-color: var(--text-primary-color, #fff);
|
||||||
|
--mdc-select-hover-line-color: var(--text-primary-color, #fff);
|
||||||
|
--mdc-select-dropdown-icon-color: var(--text-primary-color, #fff);
|
||||||
|
}
|
||||||
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
@ -5687,6 +5687,7 @@
|
|||||||
"intro": "Are you ready to awaken your home, reclaim your privacy and join a worldwide community of tinkerers?",
|
"intro": "Are you ready to awaken your home, reclaim your privacy and join a worldwide community of tinkerers?",
|
||||||
"next": "Next",
|
"next": "Next",
|
||||||
"finish": "Finish",
|
"finish": "Finish",
|
||||||
|
"language": "Language",
|
||||||
"user": {
|
"user": {
|
||||||
"intro": "Let's get started by creating a user account.",
|
"intro": "Let's get started by creating a user account.",
|
||||||
"required_field": "Required",
|
"required_field": "Required",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user