summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2025-10-14 17:17:48 +0800
committer魏曹先生 <1992414357@qq.com>2025-10-14 17:17:48 +0800
commit0cd19e64d4d255e45233255478ca3a0bd5c439ae (patch)
tree6bfa39c10731328edacc6b1c86ae49c85197f7ed /src/utils
parent24c2c8cad43c755cf668ea92a08c0be7fb3b819d (diff)
feat: add internationalization support and new command-line tools
- Add locale support with English and Chinese translations - Introduce new jv and jvv command-line tools - Replace jvc.rs with improved command structure - Add utility modules for language selection and markdown coloring - Update configuration and dependencies
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/lang_selector.rs14
-rw-r--r--src/utils/md_colored.rs20
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: &regex::Captures| {
+ format!("{}", caps[1].bold())
+ })
+ .to_string();
+
+ let italic_re = Regex::new(r"\*(.*?)\*").unwrap();
+ result = italic_re
+ .replace_all(&result, |caps: &regex::Captures| {
+ format!("{}", caps[1].italic())
+ })
+ .to_string();
+
+ result
+}