Skip to content

Commit 1c2c14c

Browse files
committed
feat(i18n): add basic internationalization support
1 parent 078936b commit 1c2c14c

3 files changed

Lines changed: 70 additions & 0 deletions

File tree

src/i18n/messages/en.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use phf::phf_map;
2+
3+
pub static MESSAGES: phf::Map<&'static str, &'static str> = phf_map! {
4+
5+
// Configuration file I/O
6+
"config_loaded" => "Configuration loaded successfully",
7+
"config_not_found" => "Configuration file not found",
8+
"failed_init_config" => "Failed to initialize configuration: {}",
9+
"failed_print_config" => "Failed to print configuration: {}",
10+
"config_file_not_found" => "Config file not found: {}",
11+
"failed_parse_config" => "Failed to parse config: {}",
12+
"global_config_not_initialized" => "Global configuration not initialized",
13+
14+
// Configuration file details
15+
"config_details" => "---- Configuration Details -----",
16+
"language" => "Language",
17+
"authors" => "Authors",
18+
"date_range" => "Date Range",
19+
"repos" => "Repositories",
20+
"includes" => "Includes",
21+
"excludes" => "Excludes",
22+
"format" => "Format",
23+
24+
// Keypress
25+
"wait_for_key" => "Press any key to continue...",
26+
"press_to_exit" => "Press any key to exit...",
27+
};

src/i18n/messages/zh.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use phf::phf_map;
2+
3+
pub static MESSAGES: phf::Map<&'static str, &'static str> = phf_map! {
4+
5+
// Configuration file I/O
6+
"config_loaded" => "配置加载成功",
7+
"config_not_found" => "未找到配置文件",
8+
"failed_init_config" => "配置初始化失败:{}",
9+
"failed_print_config" => "打印配置失败:{}",
10+
"config_file_not_found" => "配置文件不存在:{}",
11+
"failed_parse_config" => "解析配置失败:{}",
12+
"global_config_not_initialized" => "全局配置未初始化",
13+
14+
// Configuration file details
15+
"config_details" => "----------- 配置详情 -----------",
16+
"language" => "语言",
17+
"authors" => "作者",
18+
"date_range" => "日期范围",
19+
"repos" => "仓库",
20+
"includes" => "包含",
21+
"excludes" => "排除",
22+
"format" => "格式",
23+
24+
// Keypress
25+
"wait_for_key" => "按任意键继续...",
26+
"press_to_exit" => "按任意键退出...",
27+
};

src/i18n/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
mod messages {
2+
pub mod en;
3+
pub mod zh;
4+
}
5+
6+
use crate::config;
7+
8+
pub fn t<'a>(key: &'a str) -> &'a str {
9+
let messages = if config::is_chinese() {
10+
&messages::zh::MESSAGES
11+
} else {
12+
&messages::en::MESSAGES
13+
};
14+
15+
messages.get(key).copied().unwrap_or(key)
16+
}

0 commit comments

Comments
 (0)