diff options
Diffstat (limited to 'server/locale/src/lib.rs')
-rw-r--r-- | server/locale/src/lib.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/server/locale/src/lib.rs b/server/locale/src/lib.rs index 1d01e4e1..9d55c7cd 100644 --- a/server/locale/src/lib.rs +++ b/server/locale/src/lib.rs @@ -16,6 +16,8 @@ */ +pub mod message; + use anyhow::anyhow; use hurrycurry_protocol::Message; use std::{ @@ -122,15 +124,15 @@ macro_rules! tre_param { }; } -pub struct Strings(HashMap<String, String>); -impl Index<&'static str> for Strings { +pub struct Locale(HashMap<String, String>); +impl Index<&'static str> for Locale { type Output = str; fn index(&self, index: &'static str) -> &Self::Output { self.0.get(index).map(|s| s.as_str()).unwrap_or(index) } } -impl Strings { +impl Locale { pub fn load() -> anyhow::Result<Self> { Ok(Self( include_str!("../../../locale/en.ini") @@ -146,9 +148,12 @@ impl Strings { .collect::<anyhow::Result<HashMap<_, _>>>()?, )) } + pub fn get(&self, id: &str) -> Option<&str> { + self.0.get(id).map(|x| x.as_str()) + } } -static TR: LazyLock<Strings> = LazyLock::new(|| Strings::load().unwrap()); +pub static FALLBACK_LOCALE: LazyLock<Locale> = LazyLock::new(|| Locale::load().unwrap()); pub fn tr(s: &'static str) -> &'static str { - &TR[s] + &FALLBACK_LOCALE[s] } |