From 080672a5fee18336971fa18ab35bb82fb62a0225 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 30 Sep 2025 20:31:58 +0200 Subject: Add map linter --- server/locale/src/lib.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'server/locale/src/lib.rs') 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); -impl Index<&'static str> for Strings { +pub struct Locale(HashMap); +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 { Ok(Self( include_str!("../../../locale/en.ini") @@ -146,9 +148,12 @@ impl Strings { .collect::>>()?, )) } + pub fn get(&self, id: &str) -> Option<&str> { + self.0.get(id).map(|x| x.as_str()) + } } -static TR: LazyLock = LazyLock::new(|| Strings::load().unwrap()); +pub static FALLBACK_LOCALE: LazyLock = LazyLock::new(|| Locale::load().unwrap()); pub fn tr(s: &'static str) -> &'static str { - &TR[s] + &FALLBACK_LOCALE[s] } -- cgit v1.2.3-70-g09d2