Building a Desktop Quick Translation Tool with Large Language Models: Technical Practice
This article describes how to build a desktop translation tool that helps developers read AI coding assistant output without leaving their workflow. It covers requirement analysis, a five-layer architecture, a pluggable adapter layer for multiple models, Markdown rendering, OCR screenshot translation, local history, and security and release practices.
When developers use AI coding assistants to read code, debug, and organize documentation, they often face a common situation. The replies mix languages and pack in technical terms. Natural-language explanations sit alongside code blocks, tables, and lists. Reading this content requires constant attention switching. Copying text into a browser translator interrupts the workflow, and the original formatting often breaks. Instead of relying on an external web page, this article describes building a desktop quick translation tool on top of a large language model. The tool compresses four steps, capturing text, translating, rendering, and retaining results, into a single hotkey action. It breaks down the requirements, architecture, key module implementation, and engineering considerations from a general technical perspective.
1. Requirement Analysis: Low Interruption, Structure Preservation, and Extensibility
The core of this tool is not another translation web page. It embeds translation into the reading and debugging process that developers already follow. The requirements fall into four categories:
- Low-interruption text capture: After a user copies or selects a passage, a global hotkey triggers the translation directly. The user does not paste manually or switch windows.
- Structure preservation: Assistant replies often contain Markdown structures such as bold text, bulleted lists, tables, and code blocks. The translated result must support a rendered view. Plain text output would flatten these formats into a single block.
- Multi-source comparison: Different model services handle terminology, code comments, and long-sentence splitting in different ways. The tool should connect to several model services that support common API protocols and display their results side by side.
- Traceability and reuse: Translated long texts, error messages, and text extracted from images should go into a local history. Users should be able to star items, view details, reuse the original text, and switch rendering modes.
From an engineering standpoint, two non-functional requirements apply. First, privacy and credential security: text, screenshots, and model access credentials must not be stored on disk or exposed in plain text without need. Second, releasability: the installation package should minimize environment dependencies and run with standard user permissions.
2. Overall Architecture: Desktop Client, Translation Pipeline, and Local Storage
The system can be divided into five layers:
- Interaction layer: global hotkeys, floating cards, the system tray, and the settings page.
- Capture layer: clipboard reading, selection monitoring, and screenshot region selection with OCR.
- Translation pipeline layer: text preprocessing, model adapters, concurrent requests, and result normalization.
- Rendering layer: switching between plain text and Markdown rendering, code block escaping, and display of tables and lists.
- Data layer: local history, favorites, and configuration and credential management.
The data flow can be simplified as follows:
Hotkey / screenshot-> Get text or image-> Preprocess (deduplicate, trim, OCR)-> Translation pipeline (single model or concurrent multi-model)-> Result normalization-> Render floating card-> Save to local history
The translation pipeline is the core of extensibility. Model service adapters should implement a unified interface:
interface TranslatorAdapter {name: stringtranslate(text, targetLang, options): Promise<Result>}
The upper layers only need the input text, the target language, and the display order. They do not need to know which service produced the result. To add a new model, a developer only implements a new adapter. Request logic stays out of the UI code.
3. Key Module Implementation
3.1 Global Hotkeys and Translation Without Pasting
The hotkey module has to handle three concerns: registration, conflicts, and trigger timing. It can provide two operations. After copying text, pressing Alt+C reads the clipboard and shows the translation in a popup. After selecting text, pressing Alt+Q translates the selection. Pressing Esc collapses the card back to the tray.
Pseudocode:
onHotkey("Alt+C"):text = clipboard.readText()if text.isEmpty: returnif text == lastTranslated: returnshowLoadingCard()result = translatePipeline(text)showResultCard(result)saveHistory(text, result)
The implementation needs to handle several details. The clipboard may contain rich text, images, or duplicate content, so the tool should fall back to plain text and deduplicate within a short time window. The global hotkeys should detect conflicts and let users change them. Translation requests should run asynchronously so the interface does not freeze. When the user triggers translation repeatedly, the tool should cancel the previous request or mark its result as stale, so an old result does not overwrite a new one.
3.2 Side-by-Side Multi-Model Comparison and the Adapter Layer
The value of side-by-side comparison lies in checking how each model handles terminology and long sentences, not in simply stacking outputs. The adapter layer should apply uniform timeout, retry, error isolation, and cancellation logic. If one model fails, the other columns should still display their results.
async function translateAll(text):tasks = adapters.map(a => requestWithTimeout(a, text))results = await settleAll(tasks)return results.map(normalize)
Normalization must account for differences in response structures across services. The layer should expose only common fields to the upper layers: text, status, latency, and error information. The tool should limit the number of concurrent requests so that several configured models do not saturate the network at once. Error messages should be sanitized, and credentials must never be written to logs.
3.3 Markdown Rendering and Plain Text Switching
Markdown structures are common in AI assistant replies. The card can include an “M” toggle in the top-right corner. When it is on, the tool parses and renders bold text, lists, tables, and code blocks. When it is off, the card shows the raw Markdown so users can copy and edit the text.
Implementation points include the following. Keep the original text before parsing. Escape code blocks during rendering so they are never executed as HTML. Give wide tables horizontal scrolling. Indent nested lists clearly. Switching the toggle should change only the display layer and should not trigger a new translation request. For text that contains commands, paths, or code snippets, keep code block styling enabled by default to reduce the risk of misreading.
3.4 OCR Screenshot Translation
Screenshot translation is a necessary addition for error dialogs that cannot be selected, English images, and interface text. The flow is: a hotkey starts region selection, the tool captures the region, preprocesses the image, runs OCR, and sends the recognized text into the translation pipeline.
onHotkey("Alt+W"):region = captureRegion()image = preprocess(region)text = ocrEngine.recognize(image)if text.isEmpty: showTip()else: translatePipeline(text)
The OCR engine should sit behind a replaceable interface. It can use the operating system’s built-in recognition or an offline recognition model that users download in the settings. Preprocessing may include common steps such as scaling, grayscale conversion, and contrast enhancement, but the design should not promise a fixed accuracy level. Users should be able to edit the recognized text before translating it, so that OCR errors do not corrupt terminology.
3.5 History and Favorites
A history record should include the original text, the translation, the target language, the model identifier, the timestamp, the source type (clipboard, selection, or OCR), and a starred flag. The detail view should allow one-click switching to Markdown rendering and reuse of the original text. Storage should stay local. For sensitive use cases, the tool should offer options to clear history and turn off automatic retention. For long texts, the list view should show only a summary and load the full content in the detail view to keep the interface responsive.
4. Engineering and Security Practices
First, credential management. Model access credentials should not be hard-coded in the client or stored in plain text in ordinary configuration files. The tool can use the system credential store or local encrypted storage, and it should consistently redact credentials in logs.
Second, privacy boundaries. Screenshots and clipboard text may contain business information. The tool should clearly state which content is sent to model services. It should prefer local OCR where possible, let users disable history, and let users clear their data.
Third, release and installation. The project can be open-sourced on a general-purpose code hosting platform, with executable installers provided on the release page. The installer should work with standard user permissions and should not require a separate runtime environment, which lowers the barrier to trying the tool. To start using it, users should only need to enter their model service credentials and choose a target language in the settings page.
Fourth, interface details. The floating card should support pinning, collapsing when it loses focus, and closing from the keyboard. It should show a loading state during translation. Error messages should distinguish network failures, invalid credentials, and empty content. Hotkeys and the rendering toggle should be configurable.
5. Use Cases and Limitations
This approach suits reading technical documentation, reviewing code comments, understanding error messages, translating image-based materials, and comparing results from several models. It does not replace human review. Machine translation output must be checked manually, especially for high-risk content such as legal text, security material, and command-line instructions. For text that contains sensitive information, evaluate the data flow and retention policy before use.
Overall, building a desktop quick translation tool with a large language model is not mainly about calling a translation API once. The key is to design around the developer’s workflow: low-interruption interaction, an extensible adapter layer, structured rendering, and local data management. Connecting capture, translation, rendering, and retention into a stable pipeline is what makes the tool a dependable part of everyday reading and debugging.
