Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>Comment Translator (CPA)New to Visual Studio Code? Get it now.
Comment Translator (CPA)

Comment Translator (CPA)

llwllw

|
2 installs
| (0) | Free
Translate code comments with your own Claude/OpenAI-compatible CPA gateway. Inserts the translation under each original comment, with one-click cleanup.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

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

  • Translate the whole file or only the selected lines (Ctrl+Alt+T / Cmd+Alt+T, right-click menu, command palette).
  • Insert below (default), replace in place, or preview only.
  • Consecutive comment lines are treated as one paragraph: a single translation goes below the last line.
  • Clean by default — no marker text is appended to your file.
  • Built-in scanner understands comments in ~40 languages and does not mistake "//" inside strings, regexes or template literals for comments.
  • Skips shebangs, license headers, and directives such as eslint-disable, @ts-ignore, noqa.
  • Translates Python docstrings — and leaves triple-quoted data strings alone.
  • Batched, concurrent requests with retry/backoff and a cancellable progress notification.
  • API key stored in VS Code SecretStorage (not in settings.json, not in the repo).
  • Output channel with full request/response timing for debugging your gateway.

Setup

  1. Install the extension and reload.

  2. Pick the protocol for your gateway:

    Your gateway exposes commentTranslator.protocol
    POST /v1/messages (Anthropic) anthropic
    POST /v1/chat/completions (OpenAI) openai
  3. Set commentTranslator.baseUrl (no /v1 suffix — it is appended automatically), e.g. http://127.0.0.1:18317.

  4. Set commentTranslator.model to the model id your gateway expects.

  5. Run Comment Translator: Set API Key and paste the key.

  6. Run Comment Translator: Test Gateway Connection to verify.

Minimal settings.json:

{
  "commentTranslator.protocol": "anthropic",
  "commentTranslator.baseUrl": "http://127.0.0.1:18317",
  "commentTranslator.model": "go/deepseek-v4.1-flash",
  "commentTranslator.targetLanguage": "Chinese (Simplified)",
  "commentTranslator.mode": "insertBelow",
  "commentTranslator.authStyle": "both"
}

authStyle

Some gateways only accept x-api-key, others only Authorization: Bearer.

  • both (default) sends both headers — works with most relays.
  • x-api-key — Anthropic-native.
  • bearer — OpenAI-compatible.

Usage

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.
  • replace mode is destructive — there is no undo other than VS Code's own undo stack. insertBelow is 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

  1. Open https://marketplace.visualstudio.com/manage/publishers/llwllw/trustedpublishing

  2. Select Trusted Publishing → Create and fill in:

    Field Value
    Policy name Release workflow
    Repository owner 041764
    Repository vscode-extention
    Workflow release.yml
    Environment (empty)
  3. Make sure package.json → publisher matches 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 --oidc flag. 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

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft