feat(panel): optional reverse direction for target-language text

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.
This commit is contained in:
schihei committed 2026-11-26 17:34:11 +01:00
1 parent 7c9cece201
commit 41f1cea769
24 files changed
+723 -148

No files matched your search

+3 -1
View File
@@ -83,7 +83,9 @@ If detected: warning `preambleDetected(firstLine:)`; the panel shows a banner; R
## 8. Same-language input
If `NLLanguageRecognizer` reports the target language with confidence ≥ 0.5 and all detected candidates agree, show "This text already appears to be in {language}" and offer "Translate anyway". Do not block: short text, names and mixed text are often misdetected.
If `NLLanguageRecognizer` reports the target language with confidence ≥ 0.5 and all meaningful candidates agree, the source is considered to be in the target language. Near-zero hypotheses (below 0.05) are ignored, so a confident single-language text is not treated as mixed.
With `autoSwitchTarget` on (default), a confident same-language source is translated into `fallbackTargetLanguage` instead of the saved target. The prompt, chunking and validation use that effective target. The panel shows "German → English" (or the configured pair), a banner explains the switch, and "Translate to German" overrides the direction for that capture only. The same-language advisory is shown only when no switch happens. Detection is advisory: uncertain or mixed text keeps the saved target, and the user can change it with the language picker.
## 9. Numbers and units