diff options
author | metamuffin <metamuffin@disroot.org> | 2025-04-19 21:40:47 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-04-19 21:40:47 +0200 |
commit | ea22b4ce7a2a089eb3824870561e555c65a2eb1b (patch) | |
tree | a690409637c98737d898f75a2428a89dbf51857d /base/src/locale.rs | |
parent | e4d60fc1a59f1c747c81871118512ef543e48e05 (diff) | |
download | jellything-ea22b4ce7a2a089eb3824870561e555c65a2eb1b.tar jellything-ea22b4ce7a2a089eb3824870561e555c65a2eb1b.tar.bz2 jellything-ea22b4ce7a2a089eb3824870561e555c65a2eb1b.tar.zst |
start on localization
Diffstat (limited to 'base/src/locale.rs')
-rw-r--r-- | base/src/locale.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/base/src/locale.rs b/base/src/locale.rs new file mode 100644 index 0000000..6df7221 --- /dev/null +++ b/base/src/locale.rs @@ -0,0 +1,22 @@ +use std::{borrow::Cow, collections::HashMap}; + +#[derive(Debug, Clone, Copy)] +pub enum Language { + English, +} + +pub fn tr<'a>(lang: Language, key: &str, args: &[(&str, &str)]) -> Cow<'a, str> { + let source_str = include_str!("../../locale/en.ini"); + let tr_map = source_str + .lines() + .filter_map(|line| { + let (key, value) = line.split_once("=")?; + Some((key.trim(), value.trim())) + }) + .collect::<HashMap<&'static str, &'static str>>(); + + match tr_map.get(key) { + Some(value) => Cow::Borrowed(value), + None => Cow::Owned(format!("TR[{key}]")), + } +} |