aboutsummaryrefslogtreecommitdiff
path: root/base/src/locale.rs
blob: 6df7221d01dd6b23014f27fa943d4ed5b8df4f42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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}]")),
    }
}