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) {
|
||||
|
||||
+18
-1
@@ -1,10 +1,27 @@
|
||||
use std::borrow::Cow;
|
||||
use std::ops::Deref;
|
||||
use leptos::*;
|
||||
use crate::locales::catalogues::get_dictionary;
|
||||
|
||||
mod catalogues;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Locales(pub Vec<Option<String>>);
|
||||
|
||||
pub fn init_locales() {
|
||||
#[cfg(not(feature = "ssr"))]
|
||||
{
|
||||
let loc = Locales(
|
||||
window()
|
||||
.navigator()
|
||||
.languages()
|
||||
.into_iter()
|
||||
.map(|val| val.as_string())
|
||||
.collect::<Vec<_>>(),
|
||||
);
|
||||
provide_context(loc);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn trl(phrase: &str) -> impl Fn() -> String {
|
||||
let mut translated = phrase;
|
||||
if let Some(dict) = get_dictionary() {
|
||||
|
||||
Reference in New Issue
Block a user