Building a Custom Windows Text Selection Translation Tool with LLM APIs
When LLM responses mix Chinese and English with heavy technical jargon, copying text into a browser translator disrupts your workflow and ruins formatting. This article walks through building a personalized Windows translation tool using LLM APIs, covering global hotkeys, clipboard monitoring, multi-model comparison, Markdown rendering, OCR screenshot translation, and local history, plus engineering tips for API key management, packaging, privacy, and cost control.
1. Why Build Your Own Translation Tool
When working with large language models, many developers hit the same recurring pain point: model responses often mix languages, pairing dense technical terms with long stretches of English that are exhausting to read. The common workaround—copying content into a browser translator—has several obvious problems:
- High context-switching cost: jumping between windows repeatedly breaks your reading flow;
- Lost formatting: bulleted lists, code blocks, and tables usually get mangled by web translation, drastically reducing readability;
- Privacy and efficiency concerns: repeatedly pasting long text is uncontrollable, and nothing gets saved as a searchable record.
General-purpose translation tools on the market solve part of the problem, but they fit the “translate LLM responses” scenario poorly—global hotkey combos, Markdown restoration, and history retention are often missing. Since you already have LLM APIs at hand, the most natural idea is: use the LLM itself to build a translation tool tailored to your own workflow.
2. Overall Design and Core Features
The core goal of a good desktop translation tool is to be “handy and unobtrusive.” Following proven text-selection translation interaction patterns, the design centers on the following modules.
2.1 Clipboard Monitoring + Global Hotkeys: Paste-Free Translation
The smoothest interaction while reading conversations or documents is:
- Copy in the chat window, or simply press
Ctrl+C; - Then press the global hotkey
Alt+C. The tool automatically reads the clipboard and pops up a translation card—no manual pasting required.
On the Windows desktop, you can register a system-wide hotkey (via mechanisms like RegisterHotKey) and combine it with clipboard change detection to trigger translation. Pseudocode example:
import pyperclip, keyboarddef on_hotkey():text = pyperclip.paste()if text.strip():show_translate_card(text)keyboard.add_hotkey('alt+c', on_hotkey)keyboard.wait()
- Selection translation: after selecting text, press
Alt+Q; the tool grabs the selection via simulated copy or UI Automation and translates it; - System tray residency: press
Escto dismiss the window back to the tray, keeping a “summon on demand, dismiss when done” low-interruption form factor.
2.2 Side-by-Side Multi-Model Comparison
Translation styles vary noticeably across models: some lean literal, others more interpretive, and terminology handling differs too. The tool should support configuring multiple OpenAI-compatible LLM services, dispatching one request in parallel, and displaying the results as side-by-side cards for quick comparison.
import asyncio, httpxasync def translate(model_cfg, text):async with httpx.AsyncClient() as client:r = await client.post(model_cfg["endpoint"], headers={"Authorization": f"Bearer {model_cfg['api_key']}"}, json={"model": model_cfg["model"],"messages": [{"role": "system", "content": "You are a professional technical translator. Preserve the Markdown structure."},{"role": "user", "content": text}]})return r.json()["choices"][0]["message"]["content"]
For prompt design, add constraints tailored to technical text: keep code blocks intact, include the original English term on first occurrence, and preserve the original list structure. These significantly improve translation usability.
2.3 One-Click Markdown Rendering
LLM responses are almost always in Markdown, and displaying raw source looks clunky. Place an “M” toggle in the top-right corner of the translation card:
- Rendering on: bold text, bulleted lists, tables, and code blocks render cleanly with proper formatting;
- Rendering off: reverts to plain text showing raw Markdown markup, making it easy to copy back into the original environment.
Implementation-wise, integrate a lightweight Markdown parsing library and do controlled rendering inside the card, making sure code blocks keep monospaced fonts and syntax highlighting.
2.4 OCR Screenshot Translation and History
- OCR recognition: for error dialogs or English images you can’t select, press
Alt+Wto capture a region, then recognize and translate. Windows ships with a built-in OCR engine you can call directly; for scenarios demanding higher accuracy, you can download a local offline OCR component (hundreds of MB, no extra runtime installation required) with one click. All inference runs locally, so nothing on your screen leaks. - History: all translations are automatically saved to local history with search support; important long texts can be starred, and the detail view also supports Markdown rendering toggles and original-text reuse, avoiding repeated translation of the same content.
3. Engineering Considerations
- API key management: store keys in a local config file or the system credential store—never hardcode them or commit them to a repository;
- Packaging and distribution: use a packaging tool to bundle the app into an installer, so users don’t need to install a runtime separately and no administrator privileges are required, lowering the barrier to entry;
- Privacy boundaries: translated text is sent to the configured model service; for sensitive content, prefer locally deployed or explicitly authorized model services;
- Cost control: add a caching layer so identical source text hits the cache and returns directly, reducing redundant API calls.
4. Conclusion
The value of this project isn’t its complexity—it’s the customized fit for a personal workflow: global hotkeys deliver “no interruption,” multi-model comparison addresses “uncertain quality,” Markdown rendering handles “formatting fidelity,” and OCR plus history cover the long-tail scenarios. The whole project can be fully open source and free to use, and going from idea to working tool typically takes just a weekend. For developers, it’s also great practice: global hotkeys, clipboard access, OCR, streaming API calls, and local persistence cover nearly every core skill in desktop development. If you’re interested, follow this approach and build your own productivity tool.
