Skip to content

Feature/vscode i18n#219

Merged
lizhengfeng101 merged 7 commits into
alibaba:mainfrom
zephyrq-z:feature/vscode-i18n
Jun 25, 2026
Merged

Feature/vscode i18n#219
lizhengfeng101 merged 7 commits into
alibaba:mainfrom
zephyrq-z:feature/vscode-i18n

Conversation

@zephyrq-z

Copy link
Copy Markdown
Contributor

Description

Implement i18n (internationalization) support for the VS Code extension, resolving all hardcoded Chinese/English UI strings across the extension host, WebView, and package.json contributions.

What was done

  • package.json contributions — Migrated hardcoded strings to %key% placeholders resolved by VS Code's native package.nls.json / package.nls.zh-cn.json mechanism (requires engines.vscode >= 1.74.0).
  • Shared i18n message catalog (src/shared/i18n.ts) — 260+ translation entries covering all UI strings, with t() lookup function and resolveLocale() locale detector.
  • WebView i18n — Preact I18nContext + useT() hook wrapping all 13 view/component files. Locale passed from extension host via init / configPanelInit messages.
  • Extension host i18nCommentProvider, ConfigPanelProvider, SidebarProvider, GitService, CliService all use t() / resolveLocale() for user-facing strings.

Architecture

  • Locale detection: vscode.env.languageresolveLocale()'en' or 'zh-cn'
  • Fallback: unknown locales → 'en'; missing keys → English default
  • WebView: locale flows from host → store → I18nContext.ProvideruseT() hook

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (no functional changes)
  • Documentation update
  • CI / Build / Tooling

How Has This Been Tested?

  • make test passes locally
  • npx webpack --mode development passes (3 bundles: extension, webview, configPanel)
  • npx jest --no-coverage passes (74/74 tests, 9 suites)
HapiGo_2026-06-25_16 57 46
  • yarn lint passes (1 pre-existing warning in shellEnv.ts, unrelated, fixed)
HapiGo_2026-06-25_16 23 57
  • yarn test passes (all tests, 9 suites)
HapiGo_2026-06-25_16 23 28
  • Extension import test passed in Qoder(en)
HapiGo_2026-06-25_16 14 53 HapiGo_2026-06-25_16 24 05
  • Extension import test passed in Qoder CN(zh-cn)
HapiGo_2026-06-25_16 15 55 HapiGo_2026-06-25_16 24 10

Checklist

  • My code follows the project's coding style (go fmt, go vet)
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly (if applicable)
  • I have signed the CLA

Related Issues

Closes #205

zephyrq-z and others added 5 commits June 25, 2026 15:39
- Integrated translation functionality using `useT` from `I18nProvider` across multiple components including CustomProviderManager, EnvSetupGuide, FileList, LogViewer, PasswordInput, Select, and various views (CancelledView, ConfigView, DoneView, EmptyView, FailedView, IdleView, RunningView).
- Replaced hardcoded strings with localized strings to enhance user experience for different languages.
- Updated button labels, titles, and hints to reflect the new translation implementation.
…n(预存代码,非本次 PR 引入,阻塞了 lint,这里进行修复)

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔍 OpenCodeReview found 16 issue(s) in this PR.

  • ✅ 16 posted as inline comment(s)
  • 📝 0 posted as summary

Comment thread extensions/vscode/src/extension/services/GitService.ts
Comment thread extensions/vscode/src/extension/services/CliService.ts Outdated
Comment thread extensions/vscode/src/extension/providers/SidebarProvider.ts Outdated
Comment thread extensions/vscode/src/webview/App.tsx Outdated
Comment thread extensions/vscode/src/webview/components/CustomProviderManager.tsx
Comment thread extensions/vscode/src/webview/views/EmptyView.tsx Outdated
Comment thread extensions/vscode/src/webview/views/DoneView.tsx Outdated
Comment thread extensions/vscode/src/webview/views/ConfigView.tsx Outdated
Comment thread extensions/vscode/src/webview/views/ConfigView.tsx Outdated
Comment on lines +30 to +38
const getPrimaryLabel = () => {
if (!configured) return t('view.idle.configFirst');
if (running) return t('view.idle.reviewing');
if (!selectionReady) {
return mode === 'branch' ? t('view.idle.selectBranch') : t('view.idle.selectCommit');
}
if (files.length === 0) return t('view.idle.noFiles');
return t('view.idle.reviewAll');
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The getPrimaryLabel function references selectionReady and files, which are declared later (lines 52–58). Although this works at runtime because the function is only invoked during rendering (after all const bindings are initialized), it hurts readability. Consider moving getPrimaryLabel below the declarations of files, selectionReady, etc., so the dependency order is top-to-bottom and easier to follow.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

不需要修改变量声明顺序,和之前版本顺序保持一致,运行时完全正常,移动反而增加 diff 噪音

   - Fix singular '1 hour ago' / '1 小时前' in GitService.formatRelative
   - Replace hardcoded 'en' locale with dynamic resolveLocale in CliService.install
   - Move hardcoded full-width colon into i18n translation strings
   - Narrow locale type from string to SupportedLocale in messages, stores
   - Extract toHtmlLang() helper to deduplicate locale→HTML lang mapping
   - Replace nested ternary with mapping object in ConfigView
   - Add missing trailing newlines to 7 files
   - Add jest __mocks__/vscode.js for CliService test
@zephyrq-z

Copy link
Copy Markdown
Contributor Author

在 vs code的中英文端侧都没有发现问题

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@lizhengfeng101 lizhengfeng101 merged commit b1db14f into alibaba:main Jun 25, 2026
2 checks passed
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.

Add i18n support for the VS Code extension

2 participants