diff --git a/src/templates.rs b/src/templates.rs index 2825677..23cc4c6 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -41,17 +41,17 @@ mod filters { use crate::config::LOC; pub fn tr(key: &str, lang: &str) -> askama::Result { + let translation = LOC.get(key).ok_or_else(|| { + eprintln!("tr filter: couldn't find the key {}", key); + askama::Error::from(std::fmt::Error) + })?; Ok(String::from( - LOC.get(key) - .ok_or_else(|| { - eprintln!("tr filter: couldn't find the key {}", key); - askama::Error::from(std::fmt::Error) - })? + translation .get(lang) - .ok_or_else(|| { + .unwrap_or(translation.get("en").ok_or_else(|| { eprintln!("tr filter: couldn't find the lang {} in key {}", lang, key); askama::Error::from(std::fmt::Error) - })? + })?) .as_str() .ok_or_else(|| { eprintln!("tr filter: lang {} in key {} is not str", lang, key);