diff options
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/lang_selector.rs | 14 | ||||
| -rw-r--r-- | src/utils/md_colored.rs | 20 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/utils/lang_selector.rs b/src/utils/lang_selector.rs new file mode 100644 index 0000000..c3603ea --- /dev/null +++ b/src/utils/lang_selector.rs @@ -0,0 +1,14 @@ +pub fn current_locales() -> String { + if let Ok(lang) = std::env::var("APP_LANG") { + return lang; + } + + if let Ok(lang) = std::env::var("LANG") { + if let Some(base_lang) = lang.split('.').next() { + return base_lang.replace('_', "-"); + } + return lang; + } + + "en".to_string() +} diff --git a/src/utils/md_colored.rs b/src/utils/md_colored.rs new file mode 100644 index 0000000..9991014 --- /dev/null +++ b/src/utils/md_colored.rs @@ -0,0 +1,20 @@ +use colored::*; +use regex::Regex; + +pub fn md(text: impl AsRef<str>) -> String { + let bold_re = Regex::new(r"\*\*(.*?)\*\*").unwrap(); + let mut result = bold_re + .replace_all(text.as_ref().trim(), |caps: ®ex::Captures| { + format!("{}", caps[1].bold()) + }) + .to_string(); + + let italic_re = Regex::new(r"\*(.*?)\*").unwrap(); + result = italic_re + .replace_all(&result, |caps: ®ex::Captures| { + format!("{}", caps[1].italic()) + }) + .to_string(); + + result +} |
