Commit c934f38c authored by Daniel García Moreno's avatar Daniel García Moreno

i18n: Error control in regex

parent ae80f567
extern crate gettextrs;
extern crate regex;
use self::gettextrs::gettext;
use self::regex::Regex;
use self::regex::Captures;
use self::regex::Regex;
pub fn i18n(format: &str) -> String {
gettext(format)
}
pub fn i18n_f(format: &str, args: &[&str]) -> String {
let s = gettext(format);
let mut parts = s.split("{}");
......@@ -20,13 +18,13 @@ pub fn i18n_f(format: &str, args: &[&str]) -> String {
output
}
pub fn i18n_k(format: &str, kwargs: &[(&str, &str)]) -> String {
let mut s = gettext(format);
for (k, v) in kwargs {
let re = Regex::new(&format!("\\{{{}\\}}", k)).unwrap();
let x = v.to_string().clone();
s = re.replace_all(&s, |_: &Captures| x.clone()).to_string();
if let Ok(re) = Regex::new(&format!("\\{{{}\\}}", k)) {
s = re.replace_all(&s, |_: &Captures| v.to_string().clone())
.to_string();
}
}
s
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment