diff options
| author | metamuffin <metamuffin@disroot.org> | 2026-01-20 01:53:09 +0100 |
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2026-01-20 01:53:09 +0100 |
| commit | bc155f7abea6ee5155b6460d367a6797205db4fd (patch) | |
| tree | a2c55d96c493cf2b71bfc79539d4f8d0d8953392 /ui/src/locale.rs | |
| parent | 10736db63ad6d99e6cdce41920aa10dbeab02129 (diff) | |
| download | jellything-bc155f7abea6ee5155b6460d367a6797205db4fd.tar jellything-bc155f7abea6ee5155b6460d367a6797205db4fd.tar.bz2 jellything-bc155f7abea6ee5155b6460d367a6797205db4fd.tar.zst | |
started ui refactor
Diffstat (limited to 'ui/src/locale.rs')
| -rw-r--r-- | ui/src/locale.rs | 43 |
1 files changed, 6 insertions, 37 deletions
diff --git a/ui/src/locale.rs b/ui/src/locale.rs index b3bf3b6..a2fdce0 100644 --- a/ui/src/locale.rs +++ b/ui/src/locale.rs @@ -3,21 +3,15 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2026 metamuffin <metamuffin.org> */ -use markup::{Render, RenderAttributeValue}; -use std::{borrow::Cow, collections::HashMap, sync::LazyLock}; - -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub enum Language { - English, - German, -} +use jellycommon::*; +use std::{collections::HashMap, sync::LazyLock}; static LANG_TABLES: LazyLock<HashMap<Language, HashMap<&'static str, &'static str>>> = LazyLock::new(|| { let mut k = HashMap::new(); for (lang, source) in [ - (Language::English, include_str!("../../locale/en.ini")), - (Language::German, include_str!("../../locale/de.ini")), + (LANG_ENG.0, include_str!("../../locale/en.ini")), + (LANG_DEU.0, include_str!("../../locale/de.ini")), ] { // TODO fallback to english let tr_map = source @@ -32,36 +26,15 @@ static LANG_TABLES: LazyLock<HashMap<Language, HashMap<&'static str, &'static st k }); -pub fn tr(lang: Language, key: &str) -> Cow<'static, str> { +pub fn tr(lang: Language, key: &str) -> &'static str { let tr_map = LANG_TABLES.get(&lang).unwrap(); - match tr_map.get(key) { - Some(value) => Cow::Borrowed(value), - None => Cow::Owned(format!("TR[{key}]")), - } + tr_map.get(key).copied().unwrap_or("MISSING TRANSLATION") } pub fn get_translation_table(lang: &Language) -> &'static HashMap<&'static str, &'static str> { LANG_TABLES.get(lang).unwrap() } -pub struct TrString<'a>(Cow<'a, str>); -impl Render for TrString<'_> { - fn render(&self, writer: &mut impl std::fmt::Write) -> std::fmt::Result { - self.0.render(writer) - } -} -impl RenderAttributeValue for TrString<'_> { - fn is_none(&self) -> bool { - false - } - fn is_true(&self) -> bool { - false - } - fn is_false(&self) -> bool { - false - } -} - pub fn escape(str: &str) -> String { let mut o = String::with_capacity(str.len()); let mut last = 0; @@ -81,7 +54,3 @@ pub fn escape(str: &str) -> String { o += &str[last..]; o } - -pub fn trs<'a>(lang: &Language, key: &str) -> TrString<'a> { - TrString(tr(*lang, key)) -} |