Select text in the DSH web client and a translate button appears at the end of the selection; clicking it translates that text in place. Translation goes through the host llm service, so it reuses the model the current session already has selected and needs no separate API key; an OpenAI-compatible endpoint can be configured instead. The result opens in a popover that stays inside the viewport, with one-click copy, a row of language buttons for instant retranslation, and smart Chinese-to-English / other-to-Chinese as the default. Configuration is stored host-side and its API key is never sent to the browser.
Install
# from GitHub (first run asks for allowBuilds approval — follow the hint, retry)
dsh plugin --profile web add github:huanleyabo/dsh-selection-translate
Any plugin you install runs third-party code with your own permissions — it can read your files, use your credentials, and reach the network, and tool approvals don’t sandbox it. GitHub-sourced plugins also run build scripts at install time — pnpm blocks those until you allow them, so an install can stop with ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED or ERR_PNPM_IGNORED_BUILDS; dsh prints the exact key to add under allowBuilds in your profile’s pnpm-workspace.yaml, and the install works on the next run. Allowing a build is a trust decision: only install sources you trust, and pin a commit (github:owner/repo#sha).
README
Select any text inside the DSH client → a small 译 (translate) button appears next to it → click once and the model translates it in place. Copy with one click.
By default it reuses the model your current session is already using (through the Host-side llm service), so no extra API key is required. It can also be pointed at any OpenAI-compatible endpoint.
中文文档见 README.md。
Features
| Feature | Description |
|---|---|
| Selection trigger | Select text with the mouse (inputs, textareas, chat transcript, tool output) and a 译 button floats next to the selection |
| Touch layout | On a finger-driven device the button moves below the selection, centred — clear of the hand still resting on the text — and grows to a 34px target |
| One-click translate | Calls the model and shows the result in a popover anchored to the selection |
| Smart placement | The popover avoids screen edges and flips above / clamps into view when space runs out |
| Target language | A row of language chips retranslates instantly to another language |
| Smart zh⇄en | The default Smart mode translates Chinese→English and everything else→Simplified Chinese |
| Copy result | One-click copy, with an execCommand fallback outside secure contexts |
| Two model sources | ① the current session model (default, zero-config) ② any OpenAI-compatible endpoint |
| Settings | Settings → General gains a row: on/off switch, default target language, and a Model & endpoint expander (provider switch / base URL / model / API key / test) |
| Privacy | The API key lives only on the Host side and is never sent to the browser; the browser only posts {text, targetLang, sessionId} |
Usage
- Select a piece of text → a 译 button appears at the end of the selection.
- Click 译 → a popover opens showing the source text and starts translating.
- To switch language, click a language chip at the bottom (
智能 / 简中 / 繁中 / EN / 日 / 韩 …). - 复制译文 copies the result, 重译 retries, and
Escor a click outside closes it.
Keyboard selection (
Shift + arrow keys) also triggers the button.
Install
This is a standard DSH bundle package. Install it into a profile:
# from GitHub
dsh plugin --profile desktop add github:huanleyabo/dsh-selection-translate
# or from a local checkout
dsh plugin --profile desktop add link:/absolute/path/to/dsh-selection-translate
cordis.patch.yml inserts the plugin row into the profile's loader tree:
- insert:
- id: dsh-selection-translate
name: dsh-selection-translate
Configuration
The config file lives at ~/.dsh/selection-translate.json (mode 0600):
{
"enabled": true,
"targetLang": "auto",
"maxChars": 6000,
"temperature": 0.1,
"timeoutMs": 60000,
"provider": "current",
"endpoint": "",
"model": "",
"apiKey": ""
}
| Field | Description |
|---|---|
enabled |
Master switch for select-to-translate |
targetLang |
Default target language; auto means smart zh⇄en |
maxChars |
Maximum characters per request (guards against accidental huge selections) |
temperature |
Sampling temperature; keep it low for translation |
timeoutMs |
Per-request timeout (default 60s) |
provider |
current uses the current session model; external uses the endpoint below |
endpoint / model / apiKey |
Used when provider is "external"; endpoint must be a full /chat/completions URL |
How the current model is resolved (provider: "current")
The Host resolves the model in this order and uses the first hit:
- the session named by the request's
sessionId, viarequestContext()/requestHeader(); agentDefaultModel.currentSelection()(the "default model" setting);- the most recent live session that yields a provider and model.
If none resolve, the plugin tells you to pick a model in the composer or switch to a custom endpoint.
Host HTTP API
Prefix /api/dsh-selection-translate:
| Method | Path | Description |
|---|---|---|
GET |
/ping |
Health check |
GET |
/config |
Read config (without apiKey; only hasApiKey) |
POST |
/config |
Patch the config, returns the redacted full config |
POST |
/translate |
{ text, targetLang?, sessionId? } → { ok, text, provider, model, targetLang, ms } |
Translation failures come back as { ok: false, error } with HTTP 200 so the UI can show the reason in place.
Slots used
| Slot | Purpose |
|---|---|
shell.overlay |
Frame-wide floating layer: the 译 button and the result popover (replaceRisk: none, purely additive) |
settings.general.item |
The General-settings preference row; the full configuration lives here, so it is always reachable |
settings.plugin.item |
Optional Plugins-page card; some compositions do not declare this seat, in which case registration only warns and nothing else is affected |
Known boundaries
- Text inside iframes is not covered. HTML document previews (
iframe[data-html-preview]), sidebar browser pages and similar live in separate documents, so the parent page'sgetSelection()cannot see a selection made there and no button appears. The selection listener is attached to the main document only. - The selection listener is built on
selectionchange+mouseup/keyup:contenteditable(such as the Composer) goes through the standardwindow.getSelection()path, while nativeINPUT/TEXTAREAgo throughselectionStart/End. provider: "current"needs the hostllmandsessionsservices; when they are missing it reports a clear error instead of failing silently.- A custom endpoint must speak the OpenAI-compatible
chat/completionsprotocol.
Tests
Two self-contained verification scripts that need no dependencies (React is not installed on disk, so they ship a minimal React hook runtime and DOM stub):
node test/host.test.mjs # 32 checks
node test/client.test.mjs # 14 checks
License
MIT
Links
More in this category
zhu1090093659/dsh-web#packages/dsh-task-board★ 10696
Task board for the dsh web GUI: a sidebar multi-column kanban whose cards run in real DSH agent sessions and can also be scheduled with cron expressions, executed host-side even with the browser closed.
zhu1090093659/dsh-web#packages/dsh-web-all★ 10696
Plugin and skin collection for the DSH Web UI: task board, Git graph, right-side panel, remote mobile UI, pet, live token stats, and a skin center.
ccch1mneyyy/dsh-TUI★ 8484
Claude Code-style full-screen terminal UI: pixel-whale header, live status line, and streaming thought expansion.
MeteorNOX/DeepSeek-Balance-Whale-Widget★ 7509
A fixed-corner whale widget for the DSH web GUI — balance, today's usage and per-turn cost with peak/off-peak pricing, editable balance-alert and daily-budget bubbles, a module-based custom bubble queue with A/B weighted choices and random lines or images, 30+ vendor templates (OpenAI, OpenRouter, Kimi, SiliconFlow, Ark, Zhipu, MiniMax and more) with per-model balance and subscription quota, plus task-end sound, imported audio, custom roles and a resource manager. Local-only, no telemetry.
omdsh-dev/DSH-better-sidebar★ 5395
Full sidebar workbench with file rendering and editing, terminal, Git, and subagents; third-party plugins can register new tabs.
omdsh-dev/dsh-genui★ 1082
Interactive UI components rendered inline in replies: layout, charts, forms, quizzes, mermaid, 3D scenes, and an action event loop back to the model.
Community comments
Comments are public GitHub Discussions. Loading them connects to GitHub and Giscus; a GitHub account is required to post.