Feat/add tradingagents #6
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ValueCell i18n(国际化)系统详细说明文档
1. 系统概述
ValueCell的i18n系统是一个完整的国际化解决方案,支持多语言、时区、货币格式、日期时间格式等功能。系统采用模块化设计,支持Agent间的上下文管理。
1.1 支持的语言
1.2 核心特性
2. 项目结构
3. 核心组件详解
3.1 常量配置 (
core/constants.py)定义了系统的基础配置:
3.2 配置类 (
config/i18n.py)I18nConfig类管理i18n配置:3.3 翻译管理 (
services/i18n_service.py)TranslationManager类
负责翻译文件的加载和管理:
I18nService类
主要的i18n服务类:
3.4 Agent上下文管理 (
services/agent_context.py)为Agent提供用户特定的i18n上下文:
3.5 工具函数 (
utils/i18n_utils.py)提供各种实用功能:
detect_browser_language(): 从HTTP头检测语言偏好format_file_size(): 文件大小格式化format_duration(): 时长格式化pluralize(): 复数形式处理validate_translation_file(): 翻译文件验证get_missing_translations(): 查找缺失翻译4. 翻译文件结构
翻译文件采用JSON格式,支持嵌套结构:
{ "common": { "yes": "是", "no": "否", "loading": "加载中..." }, "messages": { "welcome": "欢迎使用ValueCell", "data_saved": "数据已成功保存" }, "app": { "version": "版本 {version}", "copyright": "© {year} ValueCell. 保留所有权利。" } }4.1 支持的功能
"messages.welcome""版本 {version}"5. API接口
5.1 主要端点
/i18n/config/i18n/languages/i18n/language/i18n/timezones/i18n/timezone/i18n/translate/i18n/format/datetime/i18n/format/number/i18n/format/currency/i18n/user/settings/i18n/agent/context5.2 请求头支持
X-User-ID: 用户标识X-Session-ID: 会话标识Accept-Language: 浏览器语言偏好5.3 API使用示例
6. 使用方法
6.1 基础使用
6.2 日期时间格式化
6.3 数字和货币格式化
6.4 Agent使用
6.5 批量处理多用户
7. 环境变量配置
8. 扩展和定制
8.1 添加新语言
core/constants.py中添加语言定义locales/目录创建对应的JSON文件8.2 自定义翻译加载器
8.3 添加新的格式化器
9. 最佳实践
9.1 翻译键命名规范
9.2 Agent开发建议
9.3 性能优化
10. 故障排除
10.1 常见问题
Q: 翻译不显示,返回键名
A: 检查翻译文件是否存在,键名是否正确
Q: 时区转换不正确
A: 确认pytz库已安装,时区名称正确
Q: Agent上下文混乱
A: 确保使用上下文管理器或正确清理上下文
10.2 调试方法
11. 开发和测试
11.1 运行示例
11.2 启动API服务
11.3 API测试
这个i18n系统为ValueCell提供了完整的国际化支持,不仅支持基本的多语言功能,还特别针对Agent间通信和用户上下文管理进行了优化,是一个生产级的解决方案。