1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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()),
            }
        }
    }
}