Files
rezervovator/src/locales/catalogues.rs
T

52 lines
1.4 KiB
Rust
Raw Normal View History

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í"),
("Search...", "Najít...")
])),
("sk", HashMap::from( [
("Dashboard", "Prehlad"),
("Settings", "Nastavenie"),
("Search...", "Najsť...")
]))
]);
m
};
}
fn get_locales(cx: Scope) -> Vec<Option<String>> {
let (loc, set_loc) = create_signal(cx, Vec::new());
create_effect(cx, move |_| {
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()
}
pub fn get_dictionary(cx: Scope) -> Option<&'static HashMap<&'static str, &'static str>> {
let locs = get_locales(cx);
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
}