From d0fcd12b8101e9ab48710510a723c71976ad68fd Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Fri, 8 Mar 2024 23:37:59 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=96=20[pagetop]=20release=20developmen?= =?UTF-8?q?t=20version=200.0.51?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 10 ++--- src/base/component/error403.rs | 3 +- src/base/component/error404.rs | 3 +- src/locale.rs | 72 +++++++++++++++++++++------------- 4 files changed, 51 insertions(+), 37 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6d5629b2..868ea33b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pagetop" -version = "0.0.50" +version = "0.0.51" edition = "2021" authors = [ @@ -40,7 +40,7 @@ sqlite = ["database", "sea-orm/sqlx-sqlite"] [dependencies] async-trait = "0.1.77" -chrono = "0.4.33" +chrono = "0.4.35" concat-string = "1.0.1" figlet-rs = "0.1.5" itoa = "1.0.10" @@ -57,7 +57,7 @@ tracing-appender = "0.2.3" tracing-subscriber = { version = "0.3.18", features = ["json", "env-filter"] } tracing-actix-web = "0.7.9" -fluent-templates = "0.8.0" +fluent-templates = "0.9.0" unic-langid = { version = "0.9.4", features = ["macros"] } actix-web = "4" @@ -79,13 +79,13 @@ optional = true version = "0.4.1" [dependencies.sea-orm] -version = "0.12.9" +version = "0.12.14" features = ["debug-print", "macros", "runtime-async-std-native-tls"] default-features = false optional = true [dependencies.sea-schema] -version = "0.14.1" +version = "0.14.2" optional = true [build-dependencies] diff --git a/src/base/component/error403.rs b/src/base/component/error403.rs index b31ee954..172487d7 100644 --- a/src/base/component/error403.rs +++ b/src/base/component/error403.rs @@ -1,11 +1,10 @@ use crate::prelude::*; -#[derive(AutoDefault)] pub struct Error403; impl ComponentTrait for Error403 { fn new() -> Self { - Error403::default() + Error403 } fn prepare_component(&self, _cx: &mut Context) -> PrepareMarkup { diff --git a/src/base/component/error404.rs b/src/base/component/error404.rs index c96eac85..0292df8f 100644 --- a/src/base/component/error404.rs +++ b/src/base/component/error404.rs @@ -1,11 +1,10 @@ use crate::prelude::*; -#[derive(AutoDefault)] pub struct Error404; impl ComponentTrait for Error404 { fn new() -> Self { - Error404::default() + Error404 } fn prepare_component(&self, _cx: &mut Context) -> PrepareMarkup { diff --git a/src/locale.rs b/src/locale.rs index 46a89c14..a01f5f52 100644 --- a/src/locale.rs +++ b/src/locale.rs @@ -217,17 +217,23 @@ impl L10n { L10nOp::None => None, L10nOp::Text(text) => Some(text.to_owned()), L10nOp::Translate(key) => match self.locales { - Some(locales) => locales.lookup_with_args( - langid, - key, - &self - .args - .iter() - .fold(HashMap::new(), |mut args, (key, value)| { - args.insert(key.to_string(), value.to_owned().into()); - args - }), - ), + Some(locales) => { + if self.args.is_empty() { + locales.try_lookup(langid, key) + } else { + locales.try_lookup_with_args( + langid, + key, + &self + .args + .iter() + .fold(HashMap::new(), |mut args, (key, value)| { + args.insert(key.to_string(), value.to_owned().into()); + args + }), + ) + } + } None => None, }, } @@ -244,23 +250,33 @@ impl ToString for L10n { L10nOp::None => "".to_owned(), L10nOp::Text(text) => text.to_owned(), L10nOp::Translate(key) => match self.locales { - Some(locales) => locales - .lookup_with_args( - match key.as_str() { - LANGUAGE_SET_FAILURE => &LANGID_FALLBACK, - _ => &LANGID_DEFAULT, - }, - key, - &self - .args - .iter() - .fold(HashMap::new(), |mut args, (key, value)| { - args.insert(key.to_string(), value.to_owned().into()); - args - }), - ) - .unwrap_or(key.to_owned()), - None => key.to_owned(), + Some(locales) => { + if self.args.is_empty() { + locales.lookup( + match key.as_str() { + LANGUAGE_SET_FAILURE => &LANGID_FALLBACK, + _ => &LANGID_DEFAULT, + }, + key, + ) + } else { + locales.lookup_with_args( + match key.as_str() { + LANGUAGE_SET_FAILURE => &LANGID_FALLBACK, + _ => &LANGID_DEFAULT, + }, + key, + &self + .args + .iter() + .fold(HashMap::new(), |mut args, (key, value)| { + args.insert(key.to_string(), value.to_owned().into()); + args + }), + ) + } + } + None => format!("Unknown localization {}", key), }, } }