From 8873a1ac2c9e8d637240cc2222713541d48df151 Mon Sep 17 00:00:00 2001 From: Patrick Kissling Date: Mon, 17 Oct 2022 22:20:35 +0200 Subject: [PATCH] Add additional translations --- src/clock-weather-card.ts | 2 +- src/localize/languages/bg.json | 3 +- src/localize/languages/da.json | 3 +- src/localize/languages/de.json | 3 +- src/localize/languages/en.json | 3 +- src/localize/languages/fr.json | 3 +- src/localize/languages/nl.json | 65 +++++++++++++++---------------- src/localize/languages/pl.json | 3 +- src/localize/languages/pt-br.json | 3 +- src/localize/localize.ts | 33 +++++++++++----- 10 files changed, 63 insertions(+), 58 deletions(-) diff --git a/src/clock-weather-card.ts b/src/clock-weather-card.ts index 231a58bc..0fa7690c 100644 --- a/src/clock-weather-card.ts +++ b/src/clock-weather-card.ts @@ -18,7 +18,7 @@ import { svg, png } from './images'; import { version } from '../package.json'; console.info( -`%c CLOCK-WEATHER-CARD \n%c ${localize('common.version')} ${version} `, +`%c CLOCK-WEATHER-CARD \n%c ${localize('common.version')} ${version}`, 'color: orange; font-weight: bold; background: black', 'color: white; font-weight: bold; background: dimgray', ); diff --git a/src/localize/languages/bg.json b/src/localize/languages/bg.json index 57a6a678..065774b8 100644 --- a/src/localize/languages/bg.json +++ b/src/localize/languages/bg.json @@ -29,7 +29,6 @@ "3": "Ср", "4": "Чт", "5": "Пт", - "6": "Сб", - "today": "Днес" + "6": "Сб" } } \ No newline at end of file diff --git a/src/localize/languages/da.json b/src/localize/languages/da.json index 41e197ae..19ddba75 100644 --- a/src/localize/languages/da.json +++ b/src/localize/languages/da.json @@ -29,7 +29,6 @@ "3": "Ons", "4": "Tor", "5": "Fre", - "6": "Lør", - "today": "I dag" + "6": "Lør" } } diff --git a/src/localize/languages/de.json b/src/localize/languages/de.json index 3452c59f..4b534f2d 100644 --- a/src/localize/languages/de.json +++ b/src/localize/languages/de.json @@ -29,7 +29,6 @@ "3": "Mit", "4": "Don", "5": "Fre", - "6": "Sam", - "today": "Heute" + "6": "Sam" } } \ No newline at end of file diff --git a/src/localize/languages/en.json b/src/localize/languages/en.json index 59aaa51a..cef07625 100644 --- a/src/localize/languages/en.json +++ b/src/localize/languages/en.json @@ -29,7 +29,6 @@ "3": "Wed", "4": "Thu", "5": "Fri", - "6": "Sat", - "today": "Today" + "6": "Sat" } } \ No newline at end of file diff --git a/src/localize/languages/fr.json b/src/localize/languages/fr.json index ffa63417..28559c47 100644 --- a/src/localize/languages/fr.json +++ b/src/localize/languages/fr.json @@ -29,7 +29,6 @@ "3": "Mer", "4": "Jeu", "5": "Ven", - "6": "Sam", - "today": "Aujourd'hui" + "6": "Sam" } } diff --git a/src/localize/languages/nl.json b/src/localize/languages/nl.json index 6a4ea76f..37ee7578 100644 --- a/src/localize/languages/nl.json +++ b/src/localize/languages/nl.json @@ -1,35 +1,34 @@ { - "common": { - "version": "Versie", - "invalid_configuration": "Ongeldige configuratie.", - "entity_missing": "Vereiste weerentiteit ontbreekt.", - "invalid_forecast_days": "De waarde van forecast_days moet groter zijn dan 0." - }, - "weather": { - "clear-night": "Helder", - "cloudy": "Bewolkt", - "fog": "Mist", - "hail": "Hagel", - "lightning": "Onweersbuien", - "lightning-rainy": "Onweersbuien met regen", - "partlycloudy": "Half bewolkt", - "pouring": "Regen", - "rainy": "Regenachtig", - "snowy": "Sneeuw", - "snowy-rainy": "Natte sneeuw", - "sunny": "Zonnig", - "windy": "Winderig", - "windy-variant": "Storm", - "exceptional": "Chaos" - }, - "day": { - "0": "Zo", - "1": "Ma", - "2": "Di", - "3": "Wo", - "4": "Do", - "5": "Vr", - "6": "Za", - "today": "Vandaag" - } + "common": { + "version": "Versie", + "invalid_configuration": "Ongeldige configuratie.", + "entity_missing": "Vereiste weerentiteit ontbreekt.", + "invalid_forecast_days": "De waarde van forecast_days moet groter zijn dan 0." + }, + "weather": { + "clear-night": "Helder", + "cloudy": "Bewolkt", + "fog": "Mist", + "hail": "Hagel", + "lightning": "Onweersbuien", + "lightning-rainy": "Onweersbuien met regen", + "partlycloudy": "Half bewolkt", + "pouring": "Regen", + "rainy": "Regenachtig", + "snowy": "Sneeuw", + "snowy-rainy": "Natte sneeuw", + "sunny": "Zonnig", + "windy": "Winderig", + "windy-variant": "Storm", + "exceptional": "Chaos" + }, + "day": { + "0": "Zo", + "1": "Ma", + "2": "Di", + "3": "Wo", + "4": "Do", + "5": "Vr", + "6": "Za" + } } \ No newline at end of file diff --git a/src/localize/languages/pl.json b/src/localize/languages/pl.json index ec0cad67..9f4c93ae 100644 --- a/src/localize/languages/pl.json +++ b/src/localize/languages/pl.json @@ -29,7 +29,6 @@ "3": "śr.", "4": "czw.", "5": "pt.", - "6": "sob.", - "today": "dzisiaj" + "6": "sob." } } diff --git a/src/localize/languages/pt-br.json b/src/localize/languages/pt-br.json index 9130043b..a3956f18 100644 --- a/src/localize/languages/pt-br.json +++ b/src/localize/languages/pt-br.json @@ -29,7 +29,6 @@ "3": "Quarta", "4": "Quinta", "5": "Sexta", - "6": "Sábado", - "today": "Hoje" + "6": "Sábado" } } \ No newline at end of file diff --git a/src/localize/localize.ts b/src/localize/localize.ts index 79c1a690..d107fd57 100644 --- a/src/localize/localize.ts +++ b/src/localize/localize.ts @@ -1,25 +1,38 @@ +import * as bg from './languages/bg.json'; +import * as da from './languages/da.json'; +import * as de from './languages/de.json'; import * as en from './languages/en.json'; +import * as fr from './languages/fr.json'; +import * as nl from './languages/nl.json'; +import * as pl from './languages/pl.json'; +import * as ptBR from './languages/da.json'; // eslint-disable-next-line @typescript-eslint/no-explicit-any const languages: any = { - en + bg, + da, + de, + en, + fr, + nl, + pl, + ptBR }; -export function localize(string: string, search = '', replace = ''): string { - const lang = (localStorage.getItem('selectedLanguage') || 'en').replace(/['"]+/g, '').replace('-', '_'); - +export function localize(key: string): string { let translated: string; + const lang = (localStorage.getItem('selectedLanguage') || 'en') + .replace(/['"]+/g, '') + .replace('-', '_') + .replace('_', ''); try { - translated = string.split('.').reduce((o, i) => o[i], languages[lang]); + translated = key.split('.').reduce((o, i) => o[i], languages[lang]); } catch (e) { - translated = string.split('.').reduce((o, i) => o[i], languages['en']); + translated = key.split('.').reduce((o, i) => o[i], languages['en']); } - if (translated === undefined) translated = string.split('.').reduce((o, i) => o[i], languages['en']); + if (translated === undefined) translated = key.split('.').reduce((o, i) => o[i], languages['en']); - if (search !== '' && replace !== '') { - translated = translated.replace(search, replace); - } return translated; }