You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
807 B
Rust

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() {
if let Some(p) = dict.get(phrase.to_string().as_str()) {
translated = *p;
}
}
let out = translated.to_string();
move || { out.clone() }
}