44 lines
1.1 KiB
Rust
44 lines
1.1 KiB
Rust
use std::collections::HashMap;
|
|
use serde::{Serialize, Deserialize};
|
|
|
|
use crate::defs::DictFromFile;
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize ,Default)]
|
|
pub struct Local {
|
|
pub id: String,
|
|
pub itms: HashMap<String,String>
|
|
}
|
|
impl DictFromFile for Local {
|
|
fn fix_root_path<Local>(&mut self, _root_path: 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()),
|
|
}
|
|
}
|
|
}
|
|
}
|