markdown-twainmarkdown-twain translates VS Code's built-in Markdown preview with an LLM. It works in desktop VS Code 1.96 or later with a provider that supports the OpenAI-compatible Chat Completions API. You choose the provider, model, and Target language. Opening a preview in Original Only sends no document text to the provider; translation starts when you select a translated Display mode. InstallSearch for markdown-twain in VS Code's Extensions view and select Install, or run:
The extension is for desktop VS Code. To build a VSIX yourself, see Build a VSIX from source. Translate a document
The status bar shows Preparing… and then a count of processed Blocks while translation runs. The preview keeps showing the source until the run finishes, then refreshes with the translations. Selecting Original Only restores the untranslated preview and stops translation work. The Display mode applies to previews in the current VS Code window and starts as Original Only in each new window.
What gets translatedA Block is a heading, paragraph, or table cell; this includes prose in list items and blockquotes. The extension translates these Blocks and reuses a translation while the Block, LLM connection, and Target language stay the same. Blocks already in the Target language can remain in their source form without a duplicate translation. Code blocks, math blocks, front matter, raw HTML blocks, and paragraphs containing only an image are left unchanged in the preview. Paragraphs containing only inline code, inline math, or inline HTML are also skipped. In prose that contains Markdown formatting, the model is instructed to preserve links, URLs, and inline code. What is sent to the provider: Before translating a document's Blocks, the extension sends up to the first 12,000 characters of the document's raw text to create a Document brief for consistent terminology. This can include code, math, HTML, and images that remain untranslated in the preview. It then sends the Blocks that need translation. A mixed prose paragraph is sent as inline Markdown. Preserving inline content is best effort: the model is instructed to keep Markdown syntax, URLs, and inline code unchanged, but its response is not structurally validated. Inline math, inline HTML, and image alt text may also change. The v1 spec describes this boundary. LLM connectionSet Up LLM Connection offers four Provider presets. Each preset supplies its base URL and has a corresponding API-key environment variable:
Choose Custom for another OpenAI-compatible endpoint, such as a local Ollama or LM Studio server. Enter the API base URL, for example The key step can save a key in VS Code's SecretStorage or use an environment variable. For a Custom provider, enter the variable's name or choose No key. Set an environment variable before launching VS Code so the extension host can read it; setting it only in VS Code's integrated terminal is insufficient. A saved key takes precedence over an environment variable. Selecting an environment-variable option during setup removes the saved key for that provider. For a preset, clearing a saved key falls back to its environment variable if set; for Custom, use Set API Key to configure an environment variable again. Keys are never stored in Choose a model from the provider's TroubleshootingRun markdown-twain: Test Connection first. It reports the provider, model, and connection timing on success; on failure, read the error notification and use a suggested fix command if one is offered. Setup tests the connection automatically. For a failed translation run, markdown-twain: Show Log records the provider's message. If setup succeeds but no translation appears, confirm that the preview is in Bilingual or Translation Only and that the Target language is the one you intended.
The extension relies on VS Code's proxy handling. These proxy setups cannot be used directly:
For an NTLM or Digest proxy, use a local HTTP relay such as Cntlm or Px. For an unsupported SOCKS proxy, use a compatible HTTP relay or proxy. Set VS Code's CreditsRead Frog inspired markdown-twain and supplied prompt text adapted for Markdown translation. LicenseGPL-3.0-or-later. See LICENSE. |