blob: 3647d4c72ff86f9029b6b4c3e3ca4c5013ccebbe (
plain)
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
38
|
use lazy_static::lazy_static;
use std::collections::HashMap;
// use tokio::fs::File;
// pub struct Language {
// pub storage: HashMap<String, String>,
// }
// impl Language {
// pub async fn load() -> Self {
// // TODO: download from mojang's servers and cache somewhere
// let mut storage = HashMap::new();
// let mut file = File::open("en_us.json").unwrap();
// let mut contents = String::new();
// file.read_to_string(&mut contents).unwrap();
// let en_us: HashMap<String, String> = serde_json::from_str(&contents).unwrap();
// Language { storage: en_us }
// }
// pub fn get(&self, key: &str) -> Option<&str> {
// self.storage.get(key)
// }
// }
// yeah i just decided to do this because otherwise we would have to have a
// Language object that we passed around everywhere which is not convenient
// The code above is kept in case I come up with a better solution
lazy_static! {
pub static ref STORAGE: HashMap<String, String> =
serde_json::from_str(include_str!("en_us.json")).unwrap();
}
pub fn get(key: &str) -> Option<&str> {
STORAGE.get(key).map(|s| s.as_str())
}
|