From 2b4e4f30a46ecd3be75e19922a077f6da6c1e0f0 Mon Sep 17 00:00:00 2001 From: Marc Sygrove Date: Mon, 8 May 2023 20:45:01 +0000 Subject: [PATCH] added language optional and fix horizontal card --- README.md | 1 + package.json | 2 +- src/const.ts | 2 +- src/editor.ts | 18 ++++++++++++++++++ src/localize/localize.ts | 14 +++++++++++--- src/types.ts | 1 + src/uv-index-card.ts | 12 ++++++------ 7 files changed, 39 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index f2cfb4b..f35e6c1 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ entity: sensor.weather_station_uv | show_error | boolean | **Optional** | Show what an error looks like for the card | `false` | | show_warning | boolean | **Optional** | Show what a warning looks like for the card | `false` | | entity | string | **Required** | Home Assistant entity ID. | `none` | +| language | string | **Optional** | The 2 character that determines the language| `en` | | tap_action | object | **Optional** | Action to take on tap | `action: more-info` | | hold_action | object | **Optional** | Action to take on hold | `none` | | double_tap_action | object | **Optional** | Action to take on double tap | `none` | diff --git a/package.json b/package.json index 8759251..e87b0b8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "uv-index-card", - "version": "1.1.0", + "version": "1.2.0", "description": "Lovelace uv-index-card", "keywords": [ "home-assistant", diff --git a/src/const.ts b/src/const.ts index 78b357d..38e11f4 100644 --- a/src/const.ts +++ b/src/const.ts @@ -1 +1 @@ -export const CARD_VERSION = '1.1.0'; +export const CARD_VERSION = '1.2.0'; diff --git a/src/editor.ts b/src/editor.ts index 6e47a85..6ff9f73 100644 --- a/src/editor.ts +++ b/src/editor.ts @@ -9,6 +9,7 @@ import { formfieldDefinition } from '../elements/formfield'; import { selectDefinition } from '../elements/select'; import { switchDefinition } from '../elements/switch'; import { textfieldDefinition } from '../elements/textfield'; +import { CARD_LANGUAGES } from './localize/localize'; @customElement('uv-index-card-editor') export class UVIndexCardEditor extends ScopedRegistryHost(LitElement) implements LovelaceCardEditor { @@ -49,6 +50,10 @@ export class UVIndexCardEditor extends ScopedRegistryHost(LitElement) implements return this._config?.entity || ''; } + get _language(): string { + return this._config?.language || ''; + } + get _show_warning(): boolean { return this._config?.show_warning || false; } @@ -85,6 +90,19 @@ export class UVIndexCardEditor extends ScopedRegistryHost(LitElement) implements .configValue=${'name'} @input=${this._valueChanged} > + ev.stopPropagation()} + > + ${CARD_LANGUAGES.map((languageItem) => { + return html`${languageItem}`; + })} + o[i], languages[lang]); + translated = string.split('.').reduce((o, i) => o[i], languages[language]); } catch (e) { translated = string.split('.').reduce((o, i) => o[i], languages['en']); } diff --git a/src/types.ts b/src/types.ts index 0b91247..b474ef1 100644 --- a/src/types.ts +++ b/src/types.ts @@ -15,6 +15,7 @@ export interface UVIndexCardConfig extends LovelaceCardConfig { show_error?: boolean; test_gui?: boolean; entity?: string; + language?: string; tap_action?: ActionConfig; hold_action?: ActionConfig; double_tap_action?: ActionConfig; diff --git a/src/uv-index-card.ts b/src/uv-index-card.ts index 85275e7..03715f4 100644 --- a/src/uv-index-card.ts +++ b/src/uv-index-card.ts @@ -82,11 +82,11 @@ export class UVIndexCard extends LitElement { protected render(): TemplateResult | void { // TODO Check for stateObj or other necessary things and render a warning if missing if (this.config.show_warning) { - return this._showWarning(localize('common.show_warning')); + return this._showWarning(localize('common.show_warning', '', '', this.config.language)); } if (this.config.show_error) { - return this._showError(localize('common.show_error')); + return this._showError(localize('common.show_error', '', '', this.config.language)); } const entityId = this.config.entity; @@ -128,7 +128,7 @@ export class UVIndexCard extends LitElement { >
- + UV @@ -150,14 +150,14 @@ export class UVIndexCard extends LitElement {

- ${localize('common.uv_index')}
+ ${localize('common.uv_index', '', '', this.config.language)}
${stateValue}

- ${localize('common.uv_risk')}
- ${localize(uvRiskStr)} + ${localize('common.uv_risk', '', '', this.config.language)}
+ ${localize(uvRiskStr, '', '', this.config.language)}