Skip to content

Commit

Permalink
Add abbreviation localization independant of HA language setting #22
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanswam committed Aug 17, 2020
1 parent 90cb035 commit ff0ea79
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/compass-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ export class CompassCard extends LitElement {
string = COMPASS_ABBREVIATIONS[0];
}
string = COMPASS_ABBREVIATIONS[index];

return localize(`directions.${string}`, '', '', language);
}

Expand Down
2 changes: 1 addition & 1 deletion src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const COMPASS_ABBREVIATIONS = [
];
export const UNAVAILABLE = localize('common.invalid');

export const INDICATORS = ['arrow_outward', 'arrow_inward', 'circle'];
export const INDICATORS = ['arrow_outward', 'arrow_inward', 'circle'].sort();

export const CONFIG_ENTITY = 'entity';
export const CONFIG_SECONDARY_ENTITY = 'secondary_entity';
Expand Down
10 changes: 5 additions & 5 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ export class CompassCardEditor extends LitElement implements LovelaceCardEditor

get _compass_language(): string {
if (this._config) {
return this._config?.compass?.language || getLocalLanguage();
return this._config?.compass?.language || '';
}
return getLocalLanguage();
return '';
}

protected render(): TemplateResult | void {
Expand All @@ -76,8 +76,8 @@ export class CompassCardEditor extends LitElement implements LovelaceCardEditor
const entities = Object.keys(this.hass.states)
.filter((eid) => CONFIG_DOMAINS.includes(eid.substr(0, eid.indexOf('.'))))
.sort();
const indicatorsSorted = INDICATORS.sort();
const languages = COMPASS_LANGUAGES.sort();
const indicatorsSorted = INDICATORS;
const languages = COMPASS_LANGUAGES;

return html`
<div class="card-config">
Expand Down Expand Up @@ -105,7 +105,7 @@ export class CompassCardEditor extends LitElement implements LovelaceCardEditor
</paper-dropdown-menu>
<paper-dropdown-menu
class="editor-entity-select"
label="${localize('editor.direction')} ${localize('editor.abbreviation')} ${localize('editor.language')} (${localize('editor.optional')})"
label="${localize('editor.direction')} ${localize('editor.abbreviations')} ${localize('editor.language')} (${localize('editor.optional')})"
@value-changed=${this._valueChanged}
.configValue=${CONFIG_COMPASS + '.' + CONFIG_LANGUAGE}
>
Expand Down
27 changes: 26 additions & 1 deletion src/localize/languages/de.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
{
"common": {
"version": "Version",
"description": "Zeigt einen Kompass mit einem Indikator in Richtung des Entitätswertes an",
"invalid_configuration": "Ungültige Konfiguration",
"no_entity": "Entität nicht konfiguriert",
"offset_not_a_number": "Richtungs-Offset ist keine Zahl",
"invalid": "ungültig",
"on": "An",
"off": "Aus"
},
"editor": {
"name": "Name",
"optional": "Optional",
"entity": "Entität",
"required": "Benötigt",
"primary": "Richtung",
"secondary": "Sekundär",
"indicator": "Indikator",
"direction": "Richtung",
"offset": "Offset",
"show": "Zeige",
"abbreviations": "Abkürzungen",
"toggle": "Umschalten",
"language": "Sprache"
},
"directions": {
"north": "Norden",
"east": "Osten",
"south": "Süd",
"south": "Süden",
"west": "Westen",
"N": "N",
"NNE": "NNO",
Expand Down
2 changes: 1 addition & 1 deletion src/localize/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"direction": "Direction",
"offset": "Offset",
"show": "Show",
"toggle": "Toggle",
"abbreviations": "Abbreviations",
"toggle": "Toggle",
"language": "Language"
},
"directions": {
Expand Down
4 changes: 3 additions & 1 deletion src/localize/languages/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"direction": "Direzione",
"offset": "Compensazione",
"show": "Mostra",
"toggle": "Inverti stato"
"abbreviations": "Abbreviazioni",
"toggle": "Inverti stato",
"language": "Linguaggio"
},
"directions": {
"north": "Nord",
Expand Down
4 changes: 3 additions & 1 deletion src/localize/languages/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"direction": "Richting",
"offset": "Afwijking",
"show": "Toon",
"toggle": "Wissel"
"abbreviations": "Afkorting",
"toggle": "Wissel",
"language": "Taal"
},
"directions": {
"north": "Noorden",
Expand Down
2 changes: 1 addition & 1 deletion src/localize/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const languages: any = {
it: it,
de: de,
};
export const COMPASS_LANGUAGES = Object.keys(languages);
export const COMPASS_LANGUAGES = [...Object.keys(languages), ''].sort();

export function getLocalLanguage(): string {
return (localStorage.getItem('selectedLanguage') || 'en').replace(/['"]+/g, '').replace('-', '_');
Expand Down

0 comments on commit ff0ea79

Please sign in to comment.