fabaccess-bffh/bffhd/utils/l10nstring.rs

59 lines
1.4 KiB
Rust
Raw Normal View History

2021-11-26 21:01:43 +01:00
use std::collections::HashMap;
2022-03-15 20:00:43 +01:00
2021-11-26 21:01:43 +01:00
use once_cell::sync::Lazy;
struct Locales {
2022-05-05 15:50:44 +02:00
map: HashMap<&'static str, HashMap<&'static str, &'static str>>,
2021-11-26 21:01:43 +01:00
}
impl Locales {
2022-05-05 15:50:44 +02:00
pub fn get(&self, lang: &str, msg: &str) -> Option<(&'static str, &'static str)> {
self.map
.get(msg)
.and_then(|map| map.get_key_value(lang).map(|(k, v)| (*k, *v)))
2021-11-26 21:01:43 +01:00
}
pub fn available(&self, _msg: &str) -> &[&'static str] {
&[]
}
}
2022-05-05 15:50:44 +02:00
static LANG: Lazy<Locales> = Lazy::new(|| Locales {
map: HashMap::new(),
2021-11-26 21:01:43 +01:00
});
struct L10NString {
msg: &'static str,
}
/*
2021-11-26 21:01:43 +01:00
impl l10n::Server for L10NString {
fn get(&mut self, params: l10n::GetParams, mut results: l10n::GetResults)
-> Promise<(), Error>
{
let lang = pry!(pry!(params.get()).get_lang());
if let Some((lang, content)) = LANG.get(lang, &self.msg) {
let mut builder = results.get();
builder.set_lang(lang);
builder.set_content(content);
}
Promise::ok(())
}
fn available(&mut self, _: l10n::AvailableParams, mut results: l10n::AvailableResults)
-> Promise<(), Error>
{
let langs = LANG.available(self.msg);
let builder = results.get();
let mut lb = builder.init_langs(langs.len() as u32);
for (n, lang) in langs.into_iter().enumerate() {
lb.reborrow().set(n as u32, *lang);
}
Promise::ok(())
}
}
2022-05-05 15:50:44 +02:00
*/