Files
Sprachmittler/App/Settings/FallbackTargetSettings.swift
T
schihei 41f1cea769 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.
2026-11-26 17:34:11 +01:00

55 lines
2.0 KiB
Swift

import SprachmittlerCore
import SprachmittlerEngines
import SwiftUI
/// The optional reverse-direction controls in Settings ▸ General.
struct FallbackTargetSettings: View {
@Binding var autoSwitchTarget: Bool
@Binding var fallbackTargetLanguage: String
let targetLanguage: String
let recentTargets: [ModelLanguage]
@State private var showLanguagePicker = false
private var fallbackTarget: ModelLanguage {
HyMT3Languages.resolve(fallbackTargetLanguage) ?? HyMT3Languages.english
}
var body: some View {
Toggle(
String(
localized: "Translate the other direction when the text is already in the target language"
),
isOn: $autoSwitchTarget
)
.accessibilityLabel(String(localized: "Translate the other direction"))
if autoSwitchTarget {
LabeledContent(String(localized: "Fallback target language")) {
Button {
showLanguagePicker.toggle()
} label: {
HStack {
Text(fallbackTarget.localizedDisplayName)
Image(systemName: "chevron.up.chevron.down")
.font(.caption)
}
}
.popover(isPresented: $showLanguagePicker, arrowEdge: .bottom) {
LanguagePickerView(
selection: Binding(
get: { fallbackTarget },
set: { fallbackTargetLanguage = $0.code }
),
recent: recentTargets,
excluding: targetLanguage
)
}
.accessibilityLabel(String(localized: "Fallback target language"))
}
Text(String(localized: "Used only when the text is confidently detected as the target language."))
.font(.caption)
.foregroundStyle(.secondary)
}
}
}