aboutsummaryrefslogtreecommitdiff
path: root/pixel-client/src/strings.rs
diff options
context:
space:
mode:
Diffstat (limited to 'pixel-client/src/strings.rs')
-rw-r--r--pixel-client/src/strings.rs45
1 files changed, 0 insertions, 45 deletions
diff --git a/pixel-client/src/strings.rs b/pixel-client/src/strings.rs
deleted file mode 100644
index a941ecec..00000000
--- a/pixel-client/src/strings.rs
+++ /dev/null
@@ -1,45 +0,0 @@
-use anyhow::{anyhow, Result};
-use std::{
- collections::HashMap,
- fs::read_to_string,
- ops::Index,
- path::Path,
- sync::{LazyLock, Mutex},
-};
-
-pub struct Strings(HashMap<String, String>);
-impl Index<&'static str> for Strings {
- 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 {
- pub fn load(path: &Path) -> Result<Self> {
- Ok(Self(
- read_to_string(path)?
- .lines()
- .skip(1)
- .map(|l| {
- let (k, v) = l.split_once("=").ok_or(anyhow!("'=' missing"))?;
- Ok::<_, anyhow::Error>((
- k.trim_end().to_owned(),
- v.trim_start().replace("%n", "\n"),
- ))
- })
- .try_collect()?,
- ))
- }
-}
-
-static TR_LOAD: Mutex<Option<Strings>> = Mutex::new(None);
-static TR: LazyLock<Strings> = LazyLock::new(|| TR_LOAD.lock().unwrap().take().unwrap());
-
-pub fn tr<'a>(s: &'static str) -> &'a str {
- &TR[s]
-}
-pub fn set_language(lang: &str) {
- *TR_LOAD.lock().unwrap() =
- Some(Strings::load(Path::new(&format!("locale/{lang}.ini"))).unwrap());
-}