Add opt-in automatic reverse translation for a two-language pair. autoSwitchTarget defaults on with fallbackTargetLanguage English (or German when the target is English); the saved target and the effective request target are separate. Confident source-equals-target text uses the fallback, the header and a panel banner show the effective direction, and the banner can override the direction for one capture without changing the saved target. The language picker still changes the saved target, and changing the target to the fallback swaps the pair. JSON/HTML/code handling is unchanged.\n\nFilter near-zero NLLanguageRecognizer hypotheses so the existing high-confidence same-language rule works for real text. Add resolver, settings, view-model, detector and persistence tests; document ADR-022, the panel, settings and user guide. Verified: make verify green; German text with target German/fallback English renders German → English with the banner, English text stays English → German, a real click on the override shows German → German, and a new German capture switches back to English.
Sprachmittler
Sprachmittler is a native macOS menu-bar app for Apple Silicon. Select text in any app, press ⌘C twice, and a floating panel shows a translation from Tencent's Hy-MT3 model running locally through Ollama. Copy it, or click Replace to put it over the selection. Nothing is replaced automatically, and nothing leaves your Mac by default.
It is the companion to Schriftleser and Vorleser: Vorleser reads text aloud, Schriftleser turns documents into text, and Sprachmittler translates the text you select.
A user-facing installation, permission and troubleshooting guide is in docs/USER_GUIDE.md.
Features
Translate
- Double-copy trigger in any app: select, ⌘C, ⌘C.
- Streaming translations from a local Hy-MT3 model; no cloud API.
- 102 supported languages with a language picker and recent targets.
- Automatic reverse direction: with target German and fallback English, German text is translated to English and English text to German.
- Markdown rendering for headings, bold, italic, lists, quotes, code and links.
- Configurable translation text size, source-preview toggle and an optional Fast model preset.
The panel
- Non-activating floating panel: the source app stays frontmost and keeps the menu bar.
- Draggable full-width header; the panel keeps its position while open and appears near the cursor when shown again.
- Esc closes it without clicking first; a click outside closes it too.
- Copy, Retry and explicit Replace, with validation warnings that disable Replace when the output is unsafe.
System integration
- Menu-bar actions: Translate Clipboard Text, target language, Copy Last Translation, Replace Last Translation, Settings, onboarding, diagnostics and Quit.
- macOS Services item: "Translate with Sprachmittler".
- First-run onboarding checks Ollama, the model and the optional Accessibility permission.
- Accessibility is used only for Replace and is never required for translation or Copy.
Privacy
- Local Ollama endpoint by default; a remote endpoint needs an explicit toggle and HTTPS.
- No history, telemetry or account. Source text and translations are never written to disk.
- No global key taps and no Input Monitoring.
Requirements
| Requirement | Details |
|---|---|
| Mac | Apple Silicon, macOS 14 Sonoma or later |
| Ollama | Current release; verified with 0.40.18 |
| Translation model | hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M (about 5.15 GB, 16 GB unified memory recommended) |
| Fast preset (optional) | hf.co/tencent/Hy-MT3-1.8B-GGUF:Q4_K_M (about 1.35 GB) |
| Accessibility | Optional; needed only for Replace |
| Build tools | Xcode 16 or later, Homebrew, XcodeGen, SwiftFormat and SwiftLint (make bootstrap) |
| OpenCode | Optional; 2.x only when using the repository's agent workflow |
Install from source
git clone <repository-url>
cd Sprachmittler
make bootstrap
Start Ollama and download the model once:
ollama serve
ollama pull hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M
Then build, install and launch the Release app:
make install
make install builds the Release configuration, replaces /Applications/Sprachmittler.app and opens it. For a local disk image instead:
make dmg
The DMG is ad-hoc signed for local use, not notarised. The app runs from the menu bar and has no Dock icon; open it and follow the first-run onboarding.
For a Debug build during development:
make app
Usage
- Select text in Safari, Mail, Notes, an editor or any other app.
- Press ⌘C twice quickly. The double-copy window is 500 ms by default and configurable.
- The panel appears near the cursor and the translation streams in.
- Copy puts the translation on the clipboard. Replace overwrites the selection only when you click it.
- Esc or a click outside closes the panel.
The panel takes keyboard focus while it is visible by default, so Esc and the shortcuts work immediately. The app itself is not activated: the source app stays frontmost, and clicking it returns keyboard focus. The Close with Esc without clicking setting turns the focus-taking behaviour off.
| Action | Shortcut |
|---|---|
| Translate the selection | ⌘C twice |
| Close the panel | Esc, or click outside |
| Copy the translation | ⌘C |
| Retry | ⌘R |
| Replace the selection | ⌘↩ |
| Settings | ⌘, |
Translating the other direction
When the source is confidently detected as the saved target language, the panel translates into the configured fallback language instead. The header and banner show the effective direction, and the banner offers a one-capture override. Settings ▸ General ▸ Translation controls this; it is on by default with English as the fallback (German when the target is English).
Markdown
When the source looks like Markdown and Settings ▸ General ▸ Translation ▸ Render Markdown formatting is on (the default), the translation is rendered with headings, bold, italic, lists, quotes, fenced code and links. JSON, HTML and code sources are never Markdown-rendered. Copy and Replace always use the raw Markdown translation, not the rendered text. Only http and https links open, and only on an explicit click.
Replace
Replace verifies the source app and, when available, the selected text before touching it. It prefers a direct Accessibility write and falls back to a clipboard snapshot plus synthetic paste. Blocking validation warnings — a likely preamble, truncation, a repetition loop or a lost protected token — disable Replace by default. The previous clipboard is restored after the fallback paste when it is still safe to do so.
Settings
- General — target language, fallback target language, source preview, Markdown rendering, translation text size, Esc behaviour, double-copy window and startup.
- Model — model and Fast preset, Ollama endpoint, sampling and context settings.
- Translation — chunking and prompt policy.
- Privacy — local/remote endpoint policy and permissions.
- Diagnostics — server version, model digests, the last 50 timings and error kinds. No text or translations.
Privacy
- The default endpoint is
http://127.0.0.1:11434. A non-loopback endpoint requires an explicit setting and HTTPS. - Source text, translations and pasteboard contents are never written to disk and are not kept as history.
- The clipboard snapshot for a Replace fallback lives in memory for that one replacement and is restored.
- Logs contain counts, timings, short hashes and error kinds, never the selected text or the translation.
- Markdown links are restricted to
http/https; remote images are never fetched. - The app does not install a key tap and never requests Input Monitoring. While the panel is visible, a transient mouse-down monitor dismisses it when a click goes to another app; the event is discarded and the monitor is removed when the panel closes.
The hard requirements are listed in docs/SECURITY_PRIVACY.md.
How it works
select text → ⌘C twice → pasteboard capture → validate → chunk
→ documented Hy-MT3 prompt → Ollama /api/chat (streaming)
→ validate → floating panel
The app is a menu-bar agent (LSUIElement) with a non-activating NSPanel. Replace re-verifies the frontmost app and the selected text before inserting. The translation pipeline, capture/insertion seams and UI state models are separate modules so they can be tested without the UI.
| Module | Responsibility |
|---|---|
App/ |
Menu-bar app, panel, settings, onboarding, diagnostics and composition root |
Packages/SprachmittlerKit/ |
Translation pipeline, prompt adapters, Ollama client, capture/insertion, text utilities and tests |
docs/ |
Architecture, product requirements, model/API contracts, privacy, testing and decisions |
scripts/ |
Build, verification, privacy, fixture, icon and release helpers |
evaluation/ |
Corpus manifest schema, metrics and report format; the corpus itself stays out of git |
See docs/ARCHITECTURE.md for the full design.
Status
Sprachmittler is at 0.1.0. M0–M8 are implemented, make verify is green, and local install and DMG builds are verified.
The 7B model is the provisional default; the default model and prompt policy are decided by the evaluation gate in docs/MODEL_EVALUATION.md. Manual macOS-only checks remain for the double-copy and insertion matrices, VoiceOver, and the 10-app compatibility matrix. Current task state is in docs/PROGRESS.md.
Local builds are ad-hoc signed. make release is the Developer ID and notarisation path and needs the corresponding credentials.
Development
make bootstrap # install xcodegen, swiftformat, swiftlint, jq and ripgrep if missing
make doctor # check OpenCode 2.x and the resolved V2 configuration
make generate # regenerate Sprachmittler.xcodeproj from project.yml
make build # swift build plus the Debug app target
make test # package unit, contract and component tests
make app # build and launch the Debug app
make verify # format, lint, privacy, tests, Debug + Release builds
make install # build Release, install in /Applications and launch
make dmg # local unnotarised DMG from the Release build
make smoke # translate one fixed synthetic sentence
make live-test # tests against a real local Ollama
make fixtures # capture Ollama fixtures
make manifest # regenerate MANIFEST.sha256
make release # signed/notarised release dry-run; needs credentials
The package builds and tests without Xcode UI:
swift build --package-path Packages/SprachmittlerKit
swift test --package-path Packages/SprachmittlerKit
swift run --package-path Packages/SprachmittlerKit sprachmittler-cli --help exposes the language catalogue, model inspection, translation and evaluation commands.
Working with OpenCode
The repository is set up for the OpenCode 2.x development workflow. AGENTS.md contains the rules the agent loads, opencode.json is the native V2 config, and .opencode/ contains the agents, commands and skills. Use /next for the next open task, /task T4.2 for a named task, and /verify before calling work done. docs/OPENCODE_V2.md explains the configuration and how to check it.
OpenCode is a development tool. The app builds and runs without it.
Forking
- Set your bundle identifier in
project.yml(the defaultde.schihei.sprachmittleris a placeholder). - Change model tags in
docs/HYMT3_MODEL.mdand the preset definitions inSprachmittlerEngines. - Use your own Developer ID and notarisation credentials for
make release. - Do not commit
Sprachmittler.xcodeproj, build products,evaluation/corpus/or evaluation results.
Licensing
Sprachmittler bundles no models. Hy-MT3 is published by Tencent under Apache-2.0; the GGUF conversions used here are published by Tencent on Hugging Face. Settings shows the licence and the model digest. Re-check the model card before commercial distribution. The 30B-A3B model is not a preset: it needs far more memory than a 16 GB Mac has.