From 0cd19e64d4d255e45233255478ca3a0bd5c439ae Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Tue, 14 Oct 2025 17:17:48 +0800 Subject: 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 --- src/utils/lang_selector.rs | 14 ++++++++++++++ src/utils/md_colored.rs | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 src/utils/lang_selector.rs create mode 100644 src/utils/md_colored.rs (limited to 'src/utils') 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) -> 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 +} -- cgit