Translate theme settings (#16053)

This commit is contained in:
Paul Bottein 2023-04-04 14:04:05 +02:00 committed by GitHub
parent 6e35f841cc
commit 32bbc9421b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 26 additions and 11 deletions

View File

@ -93,7 +93,6 @@ export class HuiViewEditor extends LitElement {
const schema = this._schema(this.hass.localize); const schema = this._schema(this.hass.localize);
const data = { const data = {
theme: "Backend-selected",
...this._config, ...this._config,
type: this._type, type: this._type,
}; };

View File

@ -37,6 +37,7 @@ class HaPickDashboardRow extends LitElement {
.disabled=${!this._dashboards?.length} .disabled=${!this._dashboards?.length}
.value=${this.hass.defaultPanel} .value=${this.hass.defaultPanel}
@selected=${this._dashboardChanged} @selected=${this._dashboardChanged}
naturalMenuWidth
> >
<mwc-list-item value="lovelace"> <mwc-list-item value="lovelace">
${this.hass.localize( ${this.hass.localize(

View File

@ -30,6 +30,7 @@ class FirstWeekdayRow extends LitElement {
.disabled=${this.hass.locale === undefined} .disabled=${this.hass.locale === undefined}
.value=${this.hass.locale.first_weekday} .value=${this.hass.locale.first_weekday}
@selected=${this._handleFormatSelection} @selected=${this._handleFormatSelection}
naturalMenuWidth
> >
${[ ${[
FirstWeekday.language, FirstWeekday.language,

View File

@ -39,6 +39,7 @@ export class HaPickLanguageRow extends LitElement {
)} )}
.value=${this.hass.locale.language} .value=${this.hass.locale.language}
@selected=${this._languageSelectionChanged} @selected=${this._languageSelectionChanged}
naturalMenuWidth
> >
${this._languages.map( ${this._languages.map(
(language) => html`<mwc-list-item (language) => html`<mwc-list-item

View File

@ -31,6 +31,7 @@ class NumberFormatRow extends LitElement {
.disabled=${this.hass.locale === undefined} .disabled=${this.hass.locale === undefined}
.value=${this.hass.locale.number_format} .value=${this.hass.locale.number_format}
@selected=${this._handleFormatSelection} @selected=${this._handleFormatSelection}
naturalMenuWidth
> >
${Object.values(NumberFormat).map((format) => { ${Object.values(NumberFormat).map((format) => {
const formattedNumber = formatNumber(1234567.89, { const formattedNumber = formatNumber(1234567.89, {

View File

@ -23,6 +23,9 @@ import {
import { HomeAssistant } from "../../types"; import { HomeAssistant } from "../../types";
import { documentationUrl } from "../../util/documentation-url"; import { documentationUrl } from "../../util/documentation-url";
const BACKEND_SELECTED_THEME = "Backend-selected";
const DEFAULT_THEME = "default";
@customElement("ha-pick-theme-row") @customElement("ha-pick-theme-row")
export class HaPickThemeRow extends LitElement { export class HaPickThemeRow extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@ -65,16 +68,24 @@ export class HaPickThemeRow extends LitElement {
<ha-select <ha-select
.label=${this.hass.localize("ui.panel.profile.themes.dropdown_label")} .label=${this.hass.localize("ui.panel.profile.themes.dropdown_label")}
.disabled=${!hasThemes} .disabled=${!hasThemes}
.value=${this.hass.selectedTheme?.theme || "Backend-selected"} .value=${this.hass.selectedTheme?.theme || BACKEND_SELECTED_THEME}
@selected=${this._handleThemeSelection} @selected=${this._handleThemeSelection}
naturalMenuWidth
> >
<mwc-list-item .value=${BACKEND_SELECTED_THEME}>
${this.hass.localize("ui.panel.profile.themes.backend-selected")}
</mwc-list-item>
<mwc-list-item .value=${DEFAULT_THEME}>
${this.hass.localize("ui.panel.profile.themes.default")}
</mwc-list-item>
${this._themeNames.map( ${this._themeNames.map(
(theme) => (theme) => html`
html`<mwc-list-item .value=${theme}>${theme}</mwc-list-item>` <mwc-list-item .value=${theme}>${theme}</mwc-list-item>
`
)} )}
</ha-select> </ha-select>
</ha-settings-row> </ha-settings-row>
${curTheme === "default" || this._supportsModeSelection(curTheme) ${curTheme === DEFAULT_THEME || this._supportsModeSelection(curTheme)
? html` <div class="inputs"> ? html` <div class="inputs">
<ha-formfield <ha-formfield
.label=${this.hass.localize( .label=${this.hass.localize(
@ -114,7 +125,7 @@ export class HaPickThemeRow extends LitElement {
> >
</ha-radio> </ha-radio>
</ha-formfield> </ha-formfield>
${curTheme === "default" ${curTheme === DEFAULT_THEME
? html`<div class="color-pickers"> ? html`<div class="color-pickers">
<ha-textfield <ha-textfield
.value=${themeSettings?.primaryColor || .value=${themeSettings?.primaryColor ||
@ -154,9 +165,7 @@ export class HaPickThemeRow extends LitElement {
(!oldHass || oldHass.themes.themes !== this.hass.themes.themes); (!oldHass || oldHass.themes.themes !== this.hass.themes.themes);
if (themesChanged) { if (themesChanged) {
this._themeNames = ["Backend-selected", "default"].concat( this._themeNames = Object.keys(this.hass.themes.themes).sort();
Object.keys(this.hass.themes.themes).sort()
);
} }
} }
@ -198,7 +207,7 @@ export class HaPickThemeRow extends LitElement {
return; return;
} }
if (theme === "Backend-selected") { if (theme === BACKEND_SELECTED_THEME) {
if (this.hass.selectedTheme?.theme) { if (this.hass.selectedTheme?.theme) {
fireEvent(this, "settheme", { fireEvent(this, "settheme", {
theme: "", theme: "",

View File

@ -32,6 +32,7 @@ class TimeFormatRow extends LitElement {
.disabled=${this.hass.locale === undefined} .disabled=${this.hass.locale === undefined}
.value=${this.hass.locale.time_format} .value=${this.hass.locale.time_format}
@selected=${this._handleFormatSelection} @selected=${this._handleFormatSelection}
naturalMenuWidth
> >
${Object.values(TimeFormat).map((format) => { ${Object.values(TimeFormat).map((format) => {
const formattedTime = formatTime(date, { const formattedTime = formatTime(date, {

View File

@ -4711,7 +4711,9 @@
}, },
"primary_color": "Primary color", "primary_color": "Primary color",
"accent_color": "Accent color", "accent_color": "Accent color",
"reset": "Reset" "reset": "Reset",
"backend-selected": "Use backend preferred theme",
"default": "Default"
}, },
"dashboard": { "dashboard": {
"header": "Dashboard", "header": "Dashboard",