feat(builtin_commands): add multi-language support for /help command#8134
feat(builtin_commands): add multi-language support for /help command#8134oujunhaoyueling wants to merge 1 commit intoAstrBotDevs:masterfrom
Conversation
- Add help_language config option with 4 language choices (en-US, zh-CN, zh-TW, ru-RU) - Add i18n translations for command descriptions - Add new i18n files for zh-TW and ru-RU - Fix type error in cron manager get_builtin_tool call
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider normalizing/validating
help_languageonce inHelpCommand.__init__(e.g., falling back to a known default if the config value is invalid) instead of relying onTRANSLATIONS.getin each lookup. - The large
TRANSLATIONSdict hardcodes strings in Python; it may be cleaner and more consistent with the rest of the plugin to load these from the existing i18n JSON files or a separate resource module so translations can be extended without touching code.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider normalizing/validating `help_language` once in `HelpCommand.__init__` (e.g., falling back to a known default if the config value is invalid) instead of relying on `TRANSLATIONS.get` in each lookup.
- The large `TRANSLATIONS` dict hardcodes strings in Python; it may be cleaner and more consistent with the rest of the plugin to load these from the existing i18n JSON files or a separate resource module so translations can be extended without touching code.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request introduces multi-language support for built-in commands, primarily focusing on the /help command. It adds i18n configuration files for English, Russian, and Chinese, and updates the HelpCommand logic to handle localized descriptions. Feedback suggests using neutral keys in translation files instead of Chinese characters and leveraging the existing JSON-based i18n system rather than hardcoding translation dictionaries in the source code. Additionally, a regression was noted where internal commands are no longer filtered from the help output, and it is recommended to restore this exclusion.
| }, | ||
| "config": { | ||
| "builtin_commands": { | ||
| "配置": "Config" |
| TRANSLATIONS = { | ||
| "en-US": { | ||
| "no_commands": "No enabled built-in commands.", | ||
| "version_format": "AstrBot v{version}(WebUI: {dashboard_version})", | ||
| "commands": { | ||
| "help": "Show help message", | ||
| "sid": "Get session ID and other related information", | ||
| "reset": "Reset conversation history", | ||
| "stop": "Stop agent execution", | ||
| "new": "Create new conversation", | ||
| "stats": "Show token usage statistics for the current conversation", | ||
| "provider": "View or switch LLM Provider", | ||
| "dashboard_update": "Update AstrBot WebUI", | ||
| "set": "Set session variable", | ||
| "unset": "Unset session variable", | ||
| }, | ||
| }, | ||
| "zh-CN": { | ||
| "no_commands": "没有启用的内置指令。", | ||
| "version_format": "AstrBot v{version}(WebUI: {dashboard_version})", | ||
| "commands": { | ||
| "help": "显示帮助信息", | ||
| "sid": "获取会话ID和其他相关信息", | ||
| "reset": "重置对话历史", | ||
| "stop": "停止Agent执行", | ||
| "new": "创建新对话", | ||
| "stats": "显示当前对话的Token使用统计", | ||
| "provider": "查看或切换LLM提供商", | ||
| "dashboard_update": "更新AstrBot WebUI", | ||
| "set": "设置会话变量", | ||
| "unset": "取消设置会话变量", | ||
| }, | ||
| }, | ||
| "zh-TW": { | ||
| "no_commands": "沒有啟用的內建指令。", | ||
| "version_format": "AstrBot v{version}(WebUI: {dashboard_version})", | ||
| "commands": { | ||
| "help": "顯示幫助信息", | ||
| "sid": "獲取會話ID和其他相關信息", | ||
| "reset": "重置對話歷史", | ||
| "stop": "停止Agent執行", | ||
| "new": "創建新對話", | ||
| "stats": "顯示當前對話的Token使用統計", | ||
| "provider": "查看或切換LLM提供商", | ||
| "dashboard_update": "更新AstrBot WebUI", | ||
| "set": "設置會話變量", | ||
| "unset": "取消設置會話變量", | ||
| }, | ||
| }, | ||
| "ru-RU": { | ||
| "no_commands": "Нет включенных встроенных команд.", | ||
| "version_format": "AstrBot v{version}(WebUI: {dashboard_version})", | ||
| "commands": { | ||
| "help": "Показать справку", | ||
| "sid": "Получить ID сессии и другую информацию", | ||
| "reset": "Сбросить историю диалога", | ||
| "stop": "Остановить выполнение агента", | ||
| "new": "Создать новый диалог", | ||
| "stats": "Показать статистику использования токенов", | ||
| "provider": "Просмотр или смена провайдера LLM", | ||
| "dashboard_update": "Обновить AstrBot WebUI", | ||
| "set": "Установить переменную сессии", | ||
| "unset": "Сбросить переменную сессии", | ||
| }, | ||
| }, | ||
| } |
There was a problem hiding this comment.
Hardcoding a large translation dictionary directly in the source code is discouraged as it makes maintenance and adding new languages more difficult. Since the plugin already utilizes JSON-based i18n files in the .astrbot-plugin/i18n/ directory, consider leveraging the existing i18n system to manage these strings.
| if not effective: | ||
| continue |
There was a problem hiding this comment.
The previous logic specifically excluded several internal commands (set, unset, help, dashboard_update) from the help list to keep the output clean. This exclusion has been removed, which will cause these commands to appear in the /help response. If this change was unintentional, please restore the filtering.
| if not effective: | |
| continue | |
| if not effective or effective in ["set", "unset", "help", "dashboard_update"]: | |
| continue |
Screenshots or Test Results / 运行截图或测试结果
Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Add configurable multi-language support for the /help built-in command and resolve a cron manager type issue when registering the send_message_to_user tool.
New Features:
Bug Fixes:
Enhancements: