This commit is contained in:
Ondrej Vlach 2023-11-27 09:52:31 +01:00
parent 74d0caa569
commit 5d4a8a071b
3 changed files with 14 additions and 3 deletions

3
src/tools/lang.rs Normal file
View File

@ -0,0 +1,3 @@
pub fn get_lang_name_from_code(lang: &str) -> &str {
lang.split("-").collect::<Vec<&str>>()[0]
}

View File

@ -1,2 +1,3 @@
pub mod tera;
pub mod rocket;
pub mod lang;

View File

@ -1,13 +1,15 @@
use std::{collections::HashMap, str::FromStr};
use chrono::{Utc, Datelike, NaiveDate};
use log::error;
use log::{error, debug};
use rocket_dyn_templates::tera::{Value, Error};
use ovlach_data::cv::chrono::from_string;
use sha256::digest;
use fluent_resmgr::resource_manager::ResourceManager;
use unic_langid::LanguageIdentifier;
use crate::tools::lang::get_lang_name_from_code;
// TODO: tenhle modul je trochu prasacky..
pub fn static_filter(
@ -54,10 +56,15 @@ pub fn translate_filter(
pub fn lang_entity(
value: &Value,
_: &HashMap<String, rocket_dyn_templates::tera::Value>
attrs: &HashMap<String, rocket_dyn_templates::tera::Value>
) -> Result<Value, Error> {
// TODO: rewrite me!
return Ok(rocket_dyn_templates::tera::Value::String(format!("{}", value["en"].as_str().unwrap()))); // TODO: fix-me here!
let chosen_lang = attrs["lang"].as_str().unwrap();
let output_value = match value.as_object().unwrap().get(get_lang_name_from_code(chosen_lang)) {
Some(value) => value.as_str().unwrap(),
None => value["en"].as_str().unwrap(), // TODO: default
};
return Ok(rocket_dyn_templates::tera::Value::String(output_value.to_string())); // TODO: fix-me here!
}
pub fn gravatar_link(