Fixed localization.
This commit is contained in:
+4
-6
@@ -1,15 +1,15 @@
|
||||
use crate::locales::{init_locales, trl};
|
||||
use crate::pages::home_page::HomePage;
|
||||
use crate::pages::settings::Settings;
|
||||
use leptos::*;
|
||||
use leptos_meta::*;
|
||||
use leptos_router::*;
|
||||
use crate::locales::trl;
|
||||
use crate::pages::home_page::HomePage;
|
||||
use crate::pages::settings::Settings;
|
||||
|
||||
#[component]
|
||||
pub fn App() -> impl IntoView {
|
||||
// Provides context that manages stylesheets, titles, meta tags, etc.
|
||||
provide_meta_context();
|
||||
//provide_context(DialogOpener::new());
|
||||
init_locales();
|
||||
|
||||
view! {
|
||||
<Html
|
||||
@@ -219,5 +219,3 @@ pub fn App() -> impl IntoView {
|
||||
</div>*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
+2
-4
@@ -1,7 +1,3 @@
|
||||
use actix_web::middleware::DefaultHeaders;
|
||||
use sqlx::migrate;
|
||||
use sqlx::postgres::PgPoolOptions;
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
@@ -15,6 +11,8 @@ async fn main() -> std::io::Result<()> {
|
||||
use actix_session::SessionMiddleware;
|
||||
use actix_web::cookie::Key;
|
||||
use actix_web::web::Data;
|
||||
use sqlx::migrate;
|
||||
use sqlx::postgres::PgPoolOptions;
|
||||
|
||||
let conf = get_configuration(None).await.unwrap();
|
||||
let addr = conf.leptos_options.site_addr;
|
||||
|
||||
Reference in New Issue
Block a user