Skip to content

Commit

Permalink
Add additional translations
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Kissling authored and pkissling committed Oct 17, 2022
1 parent 011c3ab commit 8873a1a
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/clock-weather-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
Expand Down
3 changes: 1 addition & 2 deletions src/localize/languages/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"3": "Ср",
"4": "Чт",
"5": "Пт",
"6": "Сб",
"today": "Днес"
"6": "Сб"
}
}
3 changes: 1 addition & 2 deletions src/localize/languages/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"3": "Ons",
"4": "Tor",
"5": "Fre",
"6": "Lør",
"today": "I dag"
"6": "Lør"
}
}
3 changes: 1 addition & 2 deletions src/localize/languages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"3": "Mit",
"4": "Don",
"5": "Fre",
"6": "Sam",
"today": "Heute"
"6": "Sam"
}
}
3 changes: 1 addition & 2 deletions src/localize/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"3": "Wed",
"4": "Thu",
"5": "Fri",
"6": "Sat",
"today": "Today"
"6": "Sat"
}
}
3 changes: 1 addition & 2 deletions src/localize/languages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"3": "Mer",
"4": "Jeu",
"5": "Ven",
"6": "Sam",
"today": "Aujourd'hui"
"6": "Sam"
}
}
65 changes: 32 additions & 33 deletions src/localize/languages/nl.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
3 changes: 1 addition & 2 deletions src/localize/languages/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"3": "śr.",
"4": "czw.",
"5": "pt.",
"6": "sob.",
"today": "dzisiaj"
"6": "sob."
}
}
3 changes: 1 addition & 2 deletions src/localize/languages/pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"3": "Quarta",
"4": "Quinta",
"5": "Sexta",
"6": "Sábado",
"today": "Hoje"
"6": "Sábado"
}
}
33 changes: 23 additions & 10 deletions src/localize/localize.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 8873a1a

Please sign in to comment.