Skip to content

feat: add bidirectional translation support#17

Merged
zccrs merged 1 commit intozccrs:masterfrom
liujianqiang-niu:master
Feb 25, 2026
Merged

feat: add bidirectional translation support#17
zccrs merged 1 commit intozccrs:masterfrom
liujianqiang-niu:master

Conversation

@liujianqiang-niu
Copy link
Contributor

Enhanced translation functionality to support both Chinese-to-English and English-to-Chinese translation directions
Added command-line options --to-english and --to-chinese for explicit direction control
Implemented configurable default translation direction via config command
Updated translation prompts for different directions with specific formatting rules
Added text wrapping for Chinese content to maintain proper formatting Modified AI service interface to accept translation direction parameter Updated documentation with new features and examples

Log: Added bidirectional translation support with configurable direction

Influence:

  1. Test Chinese-to-English translation with various Chinese text inputs
  2. Test English-to-Chinese translation with different English content
  3. Verify translation direction configuration persistence
  4. Test command-line options for explicit translation direction control
  5. Validate translation quality and format preservation
  6. Test mixed content handling (Chinese and English in same text)
  7. Verify configuration settings for default translation direction

feat: 添加双向翻译支持

增强翻译功能,支持中译英和英译中双向翻译
添加命令行选项 --to-english 和 --to-chinese 用于显式控制翻译方向
实现可通过配置命令设置默认翻译方向
为不同翻译方向更新提示词,包含特定的格式规则
添加中文文本自动换行以保持格式规范
修改 AI 服务接口以接受翻译方向参数
更新文档,包含新功能和示例

Log: 新增双向翻译支持,可配置翻译方向

Influence:

  1. 测试中译英功能,使用各种中文文本输入
  2. 测试英译中功能,使用不同英文内容
  3. 验证翻译方向配置的持久性
  4. 测试命令行选项的显式翻译方向控制
  5. 验证翻译质量和格式保持
  6. 测试混合内容处理(中英文混合文本)
  7. 验证默认翻译方向的配置设置

Fixes: #16

Enhanced translation functionality to support both Chinese-to-English
and English-to-Chinese translation directions
Added command-line options --to-english and --to-chinese for explicit
direction control
Implemented configurable default translation direction via config
command
Updated translation prompts for different directions with specific
formatting rules
Added text wrapping for Chinese content to maintain proper formatting
Modified AI service interface to accept translation direction parameter
Updated documentation with new features and examples

Log: Added bidirectional translation support with configurable direction

Influence:
1. Test Chinese-to-English translation with various Chinese text inputs
2. Test English-to-Chinese translation with different English content
3. Verify translation direction configuration persistence
4. Test command-line options for explicit translation direction control
5. Validate translation quality and format preservation
6. Test mixed content handling (Chinese and English in same text)
7. Verify configuration settings for default translation direction

feat: 添加双向翻译支持

增强翻译功能,支持中译英和英译中双向翻译
添加命令行选项 --to-english 和 --to-chinese 用于显式控制翻译方向
实现可通过配置命令设置默认翻译方向
为不同翻译方向更新提示词,包含特定的格式规则
添加中文文本自动换行以保持格式规范
修改 AI 服务接口以接受翻译方向参数
更新文档,包含新功能和示例

Log: 新增双向翻译支持,可配置翻译方向

Influence:
1. 测试中译英功能,使用各种中文文本输入
2. 测试英译中功能,使用不同英文内容
3. 验证翻译方向配置的持久性
4. 测试命令行选项的显式翻译方向控制
5. 验证翻译质量和格式保持
6. 测试混合内容处理(中英文混合文本)
7. 验证默认翻译方向的配置设置

Fixes: zccrs#16
@zccrs zccrs merged commit 5b28e51 into zccrs:master Feb 25, 2026
14 checks passed
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds comprehensive bidirectional translation support to the Git Commit Helper tool, allowing users to translate content both from Chinese to English (the existing default) and from English to Chinese. The implementation includes CLI options for explicit direction control, a configurable default translation direction stored in the config file, and direction-specific translation prompts tailored to each language pair. The changes maintain backward compatibility while extending the translation functionality significantly.

Changes:

  • Added TranslateDirection enum to config with ChineseToEnglish and EnglishToChinese variants
  • Extended CLI with --to-english and --to-chinese options for the translate command
  • Added --set-translate-direction option to the config command for setting default translation direction
  • Updated AI service interface to accept translation direction parameter throughout the codebase
  • Enhanced translation prompts with direction-specific rules and examples
  • Updated comprehensive documentation with new features and usage examples

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/config.rs Added TranslateDirection enum, default_translate_direction function, and integrated direction into Config struct
src/main.rs Added CLI options for translation direction, updated config command to handle direction setting, modified translate command to support bidirectional translation
src/ai_service.rs Updated AiService trait with direction parameter, added direction-specific translation prompts, modified all translation functions to accept direction
src/git.rs Updated git hook translation calls to explicitly use ChineseToEnglish direction
src/commit.rs Updated commit suggestion generation to pass ChineseToEnglish direction
README.md Added comprehensive documentation for bidirectional translation feature with examples and configuration options

return Err(anyhow::anyhow!("无效的翻译方向,请使用 'to-english'(中译英)或 'to-chinese'(英译中)"));
}
};
config.translate_direction = direction.clone();
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .clone() call is unnecessary here. The direction variable is already moved from the match expression and doesn't need to be cloned to assign to config.translate_direction. You can simply use config.translate_direction = direction; instead.

Suggested change
config.translate_direction = direction.clone();
config.translate_direction = direction;

Copilot uses AI. Check for mistakes.
Comment on lines +46 to +50
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub enum TranslateDirection {
ChineseToEnglish, // 中译英(默认)
EnglishToChinese, // 英译中
}
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TranslateDirection enum should derive Copy in addition to Clone since it's a simple enum with no data. This would make it more efficient to pass around and eliminate the need for .clone() calls throughout the codebase (e.g., on line 443 in main.rs). Add Copy to the derive macro: #[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]

Copilot uses AI. Check for mistakes.
config::TranslateDirection::ChineseToEnglish
} else {
// 使用配置文件中的默认方向
config.translate_direction.clone()
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another unnecessary .clone() call on config.translate_direction. If TranslateDirection derives Copy (as suggested), this clone can be removed. Even without Copy, you could use a reference here: &config.translate_direction and adjust the match expression accordingly.

Suggested change
config.translate_direction.clone()
config.translate_direction

Copilot uses AI. Check for mistakes.
Comment on lines +46 to +50
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub enum TranslateDirection {
ChineseToEnglish, // 中译英(默认)
EnglishToChinese, // 英译中
}
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding unit tests for the new bidirectional translation feature. Since the repository has comprehensive test coverage for parsing functions in commit.rs (16 test functions), similar test coverage would be beneficial for the translation direction logic. Key areas to test:

  1. Parsing of different direction string values ("to-english", "chinese-to-english", "中译英", etc.)
  2. Translation prompt generation for both directions
  3. Default direction configuration behavior
  4. Error handling for invalid direction values

This would help ensure the new feature works correctly and prevent regressions.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

git-commit-helper translate 不支持英文翻译中文

3 participants