argaar / comfortable-environment-card

A card to display the Heat Index and Discomfort Index (aka Thom Index)
MIT License
54 stars 18 forks source link

Added HU translation #23

Closed n0is3r closed 9 months ago

n0is3r commented 10 months ago

Created hu.json Modified localize.ts to include hu.json

hu.json

`import as en from "./languages/en.json"; import as es from "./languages/es.json"; import as fr from "./languages/fr.json"; import as it from "./languages/it.json"; import as pt from "./languages/pt.json"; import as ru from "./languages/ru.json"; import as sk from "./languages/sk.json"; import as uk from "./languages/uk.json"; import * as hu from "./languages/hu.json";

// eslint-disable-next-line @typescript-eslint/no-explicit-any const languages: any = { en: en, es: es, fr: fr, it: it, ru: ru, sk: sk, pt: pt, uk: uk, hu: hu };

export function localize(string: string, search = '', replace = ''): string { const lang = (localStorage.getItem('selectedLanguage') || 'en').replace(/['"]+/g, '').replace('-', '_');

let translated: string;

try { translated = string.split('.').reduce((o, i) => o[i], languages[lang]); } catch (e) { translated = string.split('.').reduce((o, i) => o[i], languages['en']); }

if (translated === undefined) translated = string.split('.').reduce((o, i) => o[i], languages['en']);

if (search !== '' && replace !== '') { translated = translated.replace(search, replace); } return translated; }`

Andurilll commented 10 months ago

what ist this string?