Comment Translator (CPA)Translate code comments with your own CPA / LLM gateway — Anthropic Messages or OpenAI Chat Completions — and insert the translation right under the original comment. Works with any gateway that speaks one of those two protocols: a self-hosted proxy, LiteLLM, one-api, an internal Claude/OpenAI relay, etc. Features
Setup
Minimal
|
| Command | Shortcut | What it does |
|---|---|---|
| Comment Translator: Translate Comments Here | Ctrl+Alt+T |
Translate comments intersecting the selection |
| Comment Translator: Translate All Comments in File | — | Translate every comment in the active file |
| Comment Translator: Remove Inserted Translations | — | Delete all lines ending with the marker (needs insertMarker) |
| Comment Translator: Test Gateway Connection | — | One tiny round-trip to your gateway |
| Comment Translator: Set API Key | — | Store the key in SecretStorage |
| Comment Translator: Clear Stored API Key | — | Remove it |
| Comment Translator: Show Logs | — | Open the output channel |
Example result:
// Load configuration from disk
// 从磁盘加载配置 [translated]
const cfg = load();
Settings
| Setting | Default | Notes |
|---|---|---|
protocol |
anthropic |
anthropic or openai |
baseUrl |
http://127.0.0.1:18317 |
/v1 is appended automatically |
apiKey |
"" |
Prefer the Set API Key command |
authStyle |
both |
both, x-api-key, bearer |
model |
go/deepseek-v4.1-flash |
Any model id your gateway accepts |
targetLanguage |
Chinese (Simplified) |
Free text |
mode |
insertBelow |
insertBelow, replace, previewOnly |
chunkSize |
40 |
Comments per request |
concurrency |
3 |
Parallel requests |
maxTokens |
4096 |
Per response |
temperature |
0.2 |
|
requestTimeoutMs |
60000 |
Per request |
maxCommentLength |
4000 |
Longer comments are skipped |
skipExistingTranslations |
true |
Skip comments already followed by a marker line |
skipLicenseHeaders |
true |
Skip copyright/license blocks near the top |
mergeAdjacentComments |
true |
Fold consecutive comment lines into one paragraph |
insertMarker |
false |
Append a marker so translations can be removed later |
markerText |
[translated] |
|
extraInstructions |
"" |
Domain glossary / tone instructions |
Supported languages
C, C++, C#, Java, Kotlin, Scala, Swift, Objective-C, Dart, Groovy, Solidity, Protobuf, GLSL/WGSL/HLSL, Zig, Rust, Go, JavaScript/TypeScript/JSX/TSX, PHP, CSS/SCSS/Sass/Less/Stylus, Python, Ruby, Perl, R, Julia, Elixir, Crystal, Nim, CoffeeScript, PowerShell, Shell/Bash/Zsh/Fish, Makefile, Dockerfile, YAML, TOML, INI, Nix, HCL/Terraform, CMake, GraphQL, SQL, HTML/XML/SVG, Markdown, Vue, Svelte, Lua, Haskell, F#, OCaml, Erlang, LaTeX, Clojure, Lisp/Scheme/Racket, Elm.
Unknown language ids fall back to the file extension.
Local development
npm install
npm run compile
npm test # 36 tests: scanner, renderer, retries, both protocols against a mock gateway
Press F5 in VS Code to launch an Extension Development Host.
npm run package # produces comment-translator-llw-0.1.1.vsix
Notes & limitations
- The scanner is heuristic, not a full parser. It is conservative: inside comments it does not try to interpret nested syntax.
replacemode is destructive — there is no undo other than VS Code's own undo stack.insertBelowis the safer default.- Very large files are chunked, so a failure in one chunk is reported in the log and aborts the run rather than writing partial results.
- The extension sends comment text (and a few nearby code lines for context) to the gateway you configure. Nothing is sent anywhere else.
Releasing
Publishing uses Trusted Publishing (OIDC) — no PAT is stored in the repo. Bump the version, push a tag, and the workflow publishes for you:
npm version patch # or minor / major
git push --follow-tags
.github/workflows/release.yml then runs tests, packages, publishes with
vsce publish --oidc, and attaches the .vsix to a GitHub release.
One-time setup: Trusted Publishing policy
Open https://marketplace.visualstudio.com/manage/publishers/llwllw/trustedpublishing
Select Trusted Publishing → Create and fill in:
Field Value Policy name Release workflowRepository owner 041764Repository vscode-extentionWorkflow release.ymlEnvironment (empty) Make sure
package.json→publishermatches the Marketplace publisher (llwllw).
The workflow job must have id-token: write permission — already set.
Requires vsce 4.x (
npx @vscode/vsce@4). vsce 3.x has no--oidcflag. The Marketplace credential expires after 15 minutes and each OIDC token can be exchanged only once, so a re-run always requests a fresh one.
To publish manually from a local machine you still need a PAT:
npx @vscode/vsce@4 login llwllw
npx @vscode/vsce@4 publish patch
License
MIT