2023-08-18 12:22:23 +02:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
use lazy_static::lazy_static;
|
|
|
|
|
use leptos::*;
|
|
|
|
|
|
|
|
|
|
lazy_static! {
|
|
|
|
|
static ref LANGUAGES: HashMap<&'static str, HashMap<&'static str, &'static str>> = {
|
|
|
|
|
let m = HashMap::from([
|
|
|
|
|
("cs", HashMap::from( [
|
|
|
|
|
("Dashboard", "Přehled"),
|
|
|
|
|
("Settings", "Nastavení"),
|
2023-08-24 21:58:03 +02:00
|
|
|
("Search...", "Najít..."),
|
|
|
|
|
("Close", "Zavřít"),
|
2023-09-08 11:53:08 +02:00
|
|
|
("Save changes", "Uložit změny"),
|
|
|
|
|
("Company info", "Organizace"),
|
|
|
|
|
("Name cannot be empty", "Jméno nesmí být prázdné"),
|
2023-08-18 12:22:23 +02:00
|
|
|
])),
|
|
|
|
|
("sk", HashMap::from( [
|
|
|
|
|
("Dashboard", "Prehlad"),
|
|
|
|
|
("Settings", "Nastavenie"),
|
|
|
|
|
("Search...", "Najsť...")
|
|
|
|
|
]))
|
|
|
|
|
]);
|
|
|
|
|
m
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-15 13:55:01 +02:00
|
|
|
fn get_locales() -> Vec<Option<String>> {
|
|
|
|
|
let (loc, set_loc) = create_signal(Vec::new());
|
2023-08-18 12:22:23 +02:00
|
|
|
|
2023-09-15 13:55:01 +02:00
|
|
|
create_effect(move |_| {
|
2023-08-18 12:22:23 +02:00
|
|
|
let js_locales = window().navigator().languages();
|
|
|
|
|
set_loc.update(|l| *l = js_locales.into_iter().map(|val| val.as_string()).collect::<Vec<_>>());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
loc.get_untracked()
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-15 13:55:01 +02:00
|
|
|
pub fn get_dictionary() -> Option<&'static HashMap<&'static str, &'static str>> {
|
|
|
|
|
let locs = get_locales();
|
2023-08-18 12:22:23 +02:00
|
|
|
|
|
|
|
|
for loc in locs {
|
|
|
|
|
if let Some(key) = loc {
|
|
|
|
|
if let Some(k) = key.split("-").collect::<Vec<_>>().get(0) {
|
|
|
|
|
if *k == "en" {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
if !LANGUAGES.contains_key(*k) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
return LANGUAGES.get(*k);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
None
|
|
|
|
|
}
|