feat: add language support and onboard configuration wizard (v0.2.0)
- Add language code intelligent parsing module (internal/lang) - Support --lang parameter for target language specification - Support multiple language code formats (BCP47, aliases, Chinese names) - Implement interactive onboard configuration wizard - Update Config struct with language fields - Add survey library dependency for interactive UI - Improve CLI command interface - Add comprehensive unit tests for language module - Update documentation (AGENTS.md, changelog.md, taolun.md, memory.md) Supported language codes: - Standard: zh-CN, zh-TW, en-US, en-GB, ja, ko, es, fr, de - Aliases: cn, en, jp, kr, es, fr, de - Chinese names: chinese, english, japanese Commands: - yoyo "Hello world" - basic translation - yoyo --lang=cn "Hello world" - specify target language - yoyo onboard - start configuration wizard - yoyo onboard --force - force reconfiguration Version: 0.2.0
This commit is contained in:
59
AGENTS.md
59
AGENTS.md
@@ -761,7 +761,64 @@ A: 使用指数退避重试,并在`internal/api/`中实现限流器。
|
||||
### Q: 如何支持更多语言?
|
||||
A: 在配置文件中添加语言映射,并更新翻译逻辑。
|
||||
|
||||
## 语言代码处理
|
||||
|
||||
### 支持的语言代码格式
|
||||
项目支持多种语言代码格式,通过 `internal/lang` 模块处理:
|
||||
|
||||
1. **标准BCP47格式**: `zh-CN`, `zh-TW`, `en-US`, `en-GB`, `ja`, `ko` 等
|
||||
2. **简短别名**: `cn`(中文), `en`(英文), `jp`(日文), `kr`(韩文) 等
|
||||
3. **中文名称**: `chinese`(中文), `english`(英文), `japanese`(日文) 等
|
||||
|
||||
### 语言解析函数
|
||||
```go
|
||||
// 解析语言代码
|
||||
lang.ParseLanguageCode("cn") // 返回 "zh-CN"
|
||||
lang.ParseLanguageCode("en") // 返回 "en-US"
|
||||
lang.ParseLanguageCode("zh-TW") // 返回 "zh-TW"
|
||||
|
||||
// 获取语言名称(用于显示)
|
||||
lang.GetLanguageName("zh-CN") // 返回 "中文(简体)"
|
||||
lang.GetLanguageName("en-US") // 返回 "English (US)"
|
||||
```
|
||||
|
||||
## Onboard配置向导
|
||||
|
||||
### 配置流程
|
||||
1. 选择主要翻译厂商
|
||||
2. 配置厂商API密钥、HOST、模型
|
||||
3. 设置全局配置(默认语言、超时)
|
||||
4. 保存配置到 `configs/config.yaml`
|
||||
|
||||
### 使用方法
|
||||
```bash
|
||||
yoyo onboard # 启动配置向导
|
||||
yoyo onboard --force # 强制重新配置
|
||||
```
|
||||
|
||||
### 配置向导实现
|
||||
- 使用 `github.com/AlecAivazis/survey/v2` 实现交互式界面
|
||||
- 支持厂商选择、API配置、语言设置
|
||||
- 生成标准YAML配置文件
|
||||
|
||||
## 分阶段迁移策略
|
||||
|
||||
### 第一阶段:开发阶段(当前)
|
||||
- API密钥存储在 `.env` 文件
|
||||
- 复杂配置存储在 `configs/config.yaml`
|
||||
- 支持环境变量替换
|
||||
|
||||
### 第二阶段:上线前
|
||||
- 实现配置文件路径查找机制
|
||||
- 支持用户配置目录 `~/.config/yoo/yoo.yml`
|
||||
- 提供配置迁移工具
|
||||
|
||||
### 第三阶段:最终优化
|
||||
- 移除对 `.env` 文件依赖
|
||||
- 完全使用配置文件
|
||||
|
||||
## 参考资源
|
||||
- [Effective Go](https://go.dev/doc/effective_go)
|
||||
- [Go Code Review Comments](https://github.com/golang/go/wiki/CodeReviewComments)
|
||||
- [Go Style Guide](https://google.github.io/styleguide/go/)
|
||||
- [Go Style Guide](https://google.github.io/styleguide/go/)
|
||||
- [Survey库文档](https://github.com/AlecAivazis/survey)
|
||||
Reference in New Issue
Block a user