utils.rs 479 Bytes
Newer Older
1 2
// based on https://gitlab.gnome.org/World/podcasts/-/blob/master/podcasts-gtk/src/i18n|utils.rs
use gettextrs::gettext;
3
use regex::{Captures, Regex};
4

5 6 7
pub fn i18n_f(format: &str, kwargs: &[(&str, &str)]) -> String {
    let mut s = gettext(format);
    for (k, v) in kwargs {
8
        if let Ok(re) = Regex::new(&format!("\\{{{k}\\}}")) {
9 10 11 12
            s = re
                .replace_all(&s, |_: &Captures<'_>| v.to_string())
                .to_string();
        }
13
    }
14
    s
15
}