Feat/i18n integration#112
Open
xinggitxing wants to merge 12 commits into
Open
Conversation
f0ea78c to
824d2c2
Compare
Phase 2 of the i18n implementation. Replaces hardcoded English
strings across all UI modules with i18n t() calls:
- MessageView (index.tsx + utils.ts): thinking/loadedSkill/
conversationSummary/changes/plan/result/toolName/reasoningFallback/
noContent/imageAttachment labels
- loadingText: Thinking... placeholder and elapsed format
- exitSummary: Goodbye header and table column labels
- WelcomeScreen: shortcut tips descriptions and title
- slashCommands: all built-in command descriptions
- cli.tsx: --help text via cli.help.* keys
- McpStatusList: status labels (ready/failed/connecting/reconnecting)
- i18n.ts: fix getExtensionRoot for tsx test environments (2 levels up);
change TranslationKey to string for dot-notation support
- Tests: add initI18n('en') calls to tests that use t()
15 files changed, 135 insertions(+), 92 deletions(-)
Phase 3 of the i18n implementation. Makes system prompt generation
and session runtime messages locale-aware:
- prompt.ts: import t/getThinkingLocale/getReplyLocale;
getCurrentDateAndModelPrompt() uses t('prompt.dateAndModel');
getDefaultSkillPrompt() uses t('prompt.skillDocumentsHeader');
getSystemPrompt() appends thinking and reply language instructions
using the configured thinkingLocale and replyLocale
- session.ts: import t; replace 'compacting'/'Interrupted.'/
'Killed processes:'/'Failed to kill processes:' with t() calls
- Tests: add initI18n('en') to prompt.test.ts and session.test.ts;
update assertion patterns from Chinese to English text
4 files changed, 15 insertions(+), 11 deletions(-)
Phase 4 of the i18n implementation. Adds runtime locale configuration: - src/ui/components/ConfigDropdown/index.tsx: two-step dropdown for selecting UI Language / Thinking Language / Reply Language - src/ui/slashCommands.ts: register /config as a built-in command - src/ui/PromptInput.tsx: integrate ConfigDropdown with /config routing - src/ui/App.tsx: locale change handlers with settings.json persistence (readSettings + writeSettings) - UseI18n context + global setThinkingLocale/setReplyLocale for three-locale state management 5 files changed, 217 insertions(+), 2 deletions(-)
Add 96 new translation keys (236 total) and replace hardcoded strings with t() calls across 12 component files: - ModelsDropdown, RawModelDropdown (incl. RAW_COMMAND_MODELS labels), SkillsDropdown, FileMentionMenu, DropdownMenu, SlashCommandMenu - McpStatusList, SessionList, UndoSelector, ProcessStdoutView (complemented missing translations) - Added initI18n to test files for formatSessionStatus/image count
Split locales/{lang}/index.json into 18 individual JSON files:
- One file per UI component (ui-message-view, ui-prompt-input, etc.)
- Grouped small dropdowns into ui-dropdowns.json
- Grouped undo-related into ui-undo.json
- Session, prompt, cli-help remain separate
Updated check-i18n.mjs to read all *.json files from locale dirs
instead of just index.json.
i18n.ts loadLocaleDir() already supports multi-file loading.
- Show current locale value next to each category name (e.g. 'Language (en)')
- Translate locale option labels ('English'/'中文') via t() lookup
- Replace hardcoded 'current' with t('ui.config.currentLabel')
- Remove unused useMemo import (fixes lint warning)
- Add 4 new translation keys: currentLabel, localeEn, localeZhCN, categoryWithValue
(240 total keys)
- After selecting a locale, ConfigDropdown returns to category selection instead of closing (onClose was called immediately) - Shows status message in footer (e.g. 'Language: English') via onStatusMessage prop wired to PromptInput's setStatusMessage - Added 3 translation keys: languageUpdated, thinkingLanguageUpdated, replyLanguageUpdated (243 total) - WelcomeScreen tips already fully translated, no changes needed
…odule-level t() calls WelcomeScreen.SHORTCUT_TIPS was defined at module scope, so t() ran before initI18n() (ESM import order), returning key strings like "ui.welcome.pasteImage" instead of translated text. Convert SHORTCUT_TIPS from a module-level const array to a lazy getShortcutTips() function called at render time. Also update the i18n-development SKILL.md to: - Add the WelcomeScreen real-world case to Pitfall lessweb#1 - Document the "tests pass but UI shows raw keys" subtle trap in Pitfall lessweb#5 - Expand audit commands for detecting module-level t() calls
…List and WelcomeScreen
- PermissionPrompt: fully i18n-ized (17 strings -> t() calls), new locale
module ui-permission-prompt.json with en/zh-CN translations
- SessionList: fix 6 remaining hardcoded strings (delete confirm,
footer help, waiting/denied statuses)
- WelcomeScreen: fix 'Tips:' hardcoded prefix -> t('ui.welcome.tipsPrefix')
- App.tsx: fix hardcoded permission denied status message
- locales: add 25 new translation keys across 4 modules (total 267 keys)
- docs: update i18n-todo.md with comprehensive scan results and
new findings (PermissionPrompt, App.tsx, Tips component)
- settings.ts: fix indentation (tab to spaces)
… paste/history hooks - Fix stale relative import paths in cli.tsx, ConfigDropdown, DropdownMenu, McpStatusList, UpdatePrompt, and App.tsx after src/ui/ directory restructuring - Extract handlePaste/expandPasteMarkerAtCursor into usePasteHandling hook - Extract navigateHistory into useHistoryNavigation hook - Clean up unused imports in App.tsx, move resolveCurrentSettings locally
824d2c2 to
353032b
Compare
… directive injection Introduce an 'Enhanced Lang Instructions' toggle in the config dropdown (Ctrl+P) that controls whether thinking/reply language instructions are injected into each user message. Defaults to enabled. Key changes: - Add enhancedLangInstructions setting (env/project/user, default true) - Add buildLanguageInstructionStrings() to i18n module - Inject language instructions into user messages (session.ts) and compact prompts (prompt.ts) - Add UI toggle in ConfigDropdown with enable/disable options - Persist toggle state to settings.json via App callback - Add corresponding i18n keys for en and zh-CN locales
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
feat(i18n): 国际化(i18n)支持
概述
为 Deep Code CLI 添加完整的国际化(i18n)支持,覆盖四个维度:UI 界面文字、系统提示词模板、LLM 思考语言和LLM 回复语言。支持中/英双语,并允许用户独立配置 UI 语言、思考语言和回复语言。
新增特性
1. 三语言独立配置
locale— UI 语言 + 系统提示词模板语言thinkingLocale— LLM 推理内容(reasoning_content)语言replyLocale— LLM 输出内容语言三者默认一致,均可独立设置。支持
en(英语)和zh-CN(中文)。2.
/config命令新增
/config命令,提供两级下拉菜单:设置会持久化写入到
.deepcode/settings.json。3. 系统提示词语种感知
getCurrentDateAndModelPrompt()使用当前 locale 生成日期和模型信息getSystemPrompt()自动追加思考语言和回复语言指令到 LLM system prompt4. 全 UI 组件翻译
所有 Ink 组件中的硬编码文本均已替换为
t()调用,覆盖:5. CJK 字符宽度安全
新增
src/common/display-width.ts,提供displayWidth()(参考 wcwidth 语义,CJK 计 2 列,ASCII 计 1 列)和truncateDisplay()(视觉宽度安全截断),修复了下拉菜单中 CJK 文本被截断为"推…"的问题。6. 翻译文件完整性检查
新增
scripts/check-i18n.mjs,通过npm run check:i18n验证所有 locale 文件间 key 一致性。7. i18n-development 技能(LLM 辅助开发)
新增
.agents/skills/i18n-development/SKILL.md— 这是一个特殊的 技能定义文件,由 Deep Code CLI 自动加载。当开发者使用 Deep Code CLI 在此项目上工作时,LLM 会自动加载该技能文档,获得关于 i18n 架构的完整上下文,包括:initI18n()、t()、useI18n()的使用方式t()调用、CJK 宽度、事件传播等)如何对新组件进行 i18n 化
步骤 1:添加翻译键值
在
locales/en/和locales/zh-CN/目录下找到对应模块的 JSON 文件,添加新的键值对。例如,为一个新的
StatusBar组件添加翻译:locales/en/ui-status-bar.json{ "ui": { "statusBar": { "connected": "Connected", "disconnected": "Disconnected", "latency": "Latency: {ms}ms" } } }locales/zh-CN/ui-status-bar.json{ "ui": { "statusBar": { "connected": "已连接", "disconnected": "未连接", "latency": "延迟:{ms}ms" } } }步骤 2:在代码中使用
t()React 组件(使用
useI18n()钩子)非 React 模块(直接导入
t)步骤 3:添加参数插值
翻译字符串中的
{变量名}会被t()的第二个参数替换:"Latency: {ms}ms"t("key", { ms: "42" })Latency: 42ms"{count} servers"t("key", { count: 3 })3 servers步骤 4:更新测试
使用了
t()的测试文件需要在 setup 中初始化 i18n:步骤 5:运行检查
注意事项
t()调用t()在模块顶部被调用时,initI18n()尚未执行,会导致返回 key 原文字符串:在计算 UI 列宽或截断字符串时,使用
displayWidth()而非String.length,因为 CJK 字符视觉宽度为 2 列:其他注意事项
<Static>:已渲染的消息不会在 locale 切换时自动重绘,需调用reloadActiveSessionView()templates/tools/*.md保持英文不翻译(仅面向 LLM,非用户可见)变更文件清单
检查清单
npm run check通过npm test通过npm run check:i18n通过en和zh-CN翻译文件 key 一致/config命令持久化设置