Fixed localization.
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user