Fixed localization.

This commit is contained in:
2023-09-18 13:10:59 +02:00
parent a2a4c551b4
commit 0bac17f2eb
4 changed files with 26 additions and 24 deletions
+2 -13
View File
@@ -1,6 +1,7 @@
use std::collections::HashMap;
use lazy_static::lazy_static;
use leptos::*;
use crate::locales::Locales;
lazy_static! {
static ref LANGUAGES: HashMap<&'static str, HashMap<&'static str, &'static str>> = {
@@ -24,20 +25,8 @@ lazy_static! {
};
}
fn get_locales() -> Vec<Option<String>> {
let (loc, set_loc) = create_signal(Vec::new());
create_effect(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() -> Option<&'static HashMap<&'static str, &'static str>> {
let locs = get_locales();
let locs = use_context::<Locales>().unwrap_or(Locales(vec![])).0;
for loc in locs {
if let Some(key) = loc {
if let Some(k) = key.split("-").collect::<Vec<_>>().get(0) {