[Database] Add 'creation_datetime' to User + some little things

This commit is contained in:
Greg Burri 2025-01-07 23:55:16 +01:00
parent 91ab379718
commit 7a09e2360e
14 changed files with 179 additions and 131 deletions

View file

@ -6,7 +6,7 @@ use strum::EnumCount;
use strum_macros::EnumCount;
use tracing::{event, Level};
use crate::consts;
use crate::{consts, utils};
#[derive(Debug, Clone, EnumCount, Deserialize)]
pub enum Sentence {
@ -108,7 +108,8 @@ pub enum Sentence {
RecipeIngredientComment,
}
const DEFAULT_LANGUAGE_CODE: &str = "en";
pub const DEFAULT_LANGUAGE_CODE: &str = "en";
pub const PLACEHOLDER_SUBSTITUTE: &str = "{}";
#[derive(Clone)]
pub struct Tr {
@ -122,38 +123,21 @@ impl Tr {
}
}
pub fn t(&self, sentence: Sentence) -> String {
//&'static str {
self.lang.get(sentence).to_string()
// match self.lang.translation.get(&sentence) {
// Some(str) => str.clone(),
// None => format!(
// "Translation missing, lang: {}/{}, element: {:?}",
// self.lang.name, self.lang.code, sentence
// ),
// }
pub fn t(&self, sentence: Sentence) -> &'static str {
self.lang.get(sentence)
}
pub fn tp(&self, sentence: Sentence, params: &[Box<dyn ToString + Send>]) -> String {
// match self.lang.translation.get(&sentence) {
// Some(str) => {
// let mut result = str.clone();
// for p in params {
// result = result.replacen("{}", &p.to_string(), 1);
// }
// result
// }
// None => format!(
// "Translation missing, lang: {}/{}, element: {:?}",
// self.lang.name, self.lang.code, sentence
// ),
// }
let text = self.lang.get(sentence);
let mut result = text.to_string();
for p in params {
result = result.replacen("{}", &p.to_string(), 1);
}
result
let params_as_string: Vec<String> = params.iter().map(|p| p.to_string()).collect();
utils::substitute(
text,
PLACEHOLDER_SUBSTITUTE,
&params_as_string
.iter()
.map(AsRef::as_ref)
.collect::<Vec<_>>(),
)
}
pub fn current_lang_code(&self) -> &str {
@ -191,7 +175,6 @@ struct Language {
impl Language {
pub fn from_stored_language(stored_language: StoredLanguage) -> Self {
println!("!!!!!!!!!!!! {:?}", &stored_language.code);
Self {
code: stored_language.code,
name: stored_language.name,