diff options
| author | mat <github@matdoes.dev> | 2022-05-08 18:38:22 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-05-08 18:38:22 -0500 |
| commit | 7c742347a7e16ac28fcc88e3bab30e68695763e4 (patch) | |
| tree | ac33cff59db9eb9bf3c2f33125e53eb0df0e073c /azalea-language/src/lib.rs | |
| parent | a9a8834b3aa78b1b85b16e738be8bd9105ef23c0 (diff) | |
| download | azalea-drasl-7c742347a7e16ac28fcc88e3bab30e68695763e4.tar.xz | |
azalea-chat now checks language files
Diffstat (limited to 'azalea-language/src/lib.rs')
| -rw-r--r-- | azalea-language/src/lib.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/azalea-language/src/lib.rs b/azalea-language/src/lib.rs new file mode 100644 index 00000000..3647d4c7 --- /dev/null +++ b/azalea-language/src/lib.rs @@ -0,0 +1,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()) +} |
