use std::collections::HashMap;
use serde::{Serialize, Deserialize};
#[derive(Debug, Clone, Serialize, Deserialize ,Default)]
pub struct Local {
pub id: String,
pub itms: HashMap<String,String>
}
impl Local {
pub fn new(id: String, itms: HashMap<String,String>) -> Self {
Self {
id,
itms
}
}
#[allow(dead_code)]
pub fn itm(&self, key: &str, dflt: &str) -> String {
match self.itms.get(key) {
Some(val) => format!("{}",val),
None => if dflt.is_empty() {
format!("{}",key)
} else {
format!("{}",dflt)
}
}
}
pub fn get_lang(locales: &HashMap<String, Local>, key: &str, dflt: &str) -> Local {
match locales.get(key) {
Some(val) => val.to_owned(),
None => match locales.get(dflt) {
Some(val) => val.to_owned(),
None => Local::new(String::from(""),HashMap::new()),
}
}
}
}