schihei 9f89000b0d fix(panel): keep the picked language when overriding the target
The header language picker set the effective target and then re-ran prepare, where TranslationDirectionPolicy only knew a Bool override and returned the mother tongue. Any picked language other than the mother tongue was discarded, so the panel appeared not to change. The policy now takes the override target itself, and PanelViewModel stores it, so a picker choice wins over a rule for that capture; a new capture returns to the rule/mother tongue. Move the shared panel test scaffolding into PanelTestSupport and the routing tests into PanelRoutingTests, and add picker and rule-override tests. Verified: make verify green; live checks with a German -> English rule show the picker switching to French, the next capture back to English with the banner, and the banner override to German.
2026-11-27 10:38:16 +01:00

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.
  • Language routing: a mother tongue default (e.g. everything to German) plus optional source-to-target rules (e.g. Chinese → English).
  • 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

  1. Select text in Safari, Mail, Notes, an editor or any other app.
  2. Press ⌘C twice quickly. The double-copy window is 500 ms by default and configurable.
  3. The panel appears near the cursor and the translation streams in.
  4. Copy puts the translation on the clipboard. Replace overwrites the selection only when you click it.
  5. 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 ⌘,

Mother tongue and language rules

The mother tongue is the default target for every source. In Settings ▸ General ▸ Translation you can add language rules that override it for a specific source language, for example:

Mother tongue: German
  Chinese (Simplified) → English
  Traditional Chinese  → English
  German               → English

With no rules, every language goes to the mother tongue. Rules apply only when the source is confidently detected; otherwise the mother tongue is used. The panel header shows the effective direction, a banner explains a rule and offers a one-capture override, and the panel language picker is a session-only override. Persistent rules live in Settings.

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 — mother tongue, language rules, 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 default de.schihei.sprachmittler is a placeholder).
  • Change model tags in docs/HYMT3_MODEL.md and the preset definitions in SprachmittlerEngines.
  • 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.

S
Description
No description provided
Readme
1.4 MiB
0 Stars 1 Watchers 0 Forks
Languages
Swift 94.6%
Shell 5%
Makefile 0.4%