Files
Sprachmittler/App/Panel/LanguagePickerView.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

61 lines
2.3 KiB
Swift

import SprachmittlerCore
import SwiftUI
/// A searchable language list used by the panel and Settings.
struct LanguagePickerView: View {
@Binding var selection: ModelLanguage
var recent: [ModelLanguage] = []
var excluding: String?
@Environment(\.dismiss) private var dismiss
@State private var query = ""
var body: some View {
VStack(alignment: .leading, spacing: 8) {
TextField(String(localized: "Search languages"), text: $query)
.textFieldStyle(.roundedBorder)
.accessibilityLabel(String(localized: "Search languages"))
ScrollView {
LazyVStack(alignment: .leading, spacing: 2) {
ForEach(filtered) { language in
Button {
selection = language
dismiss()
} label: {
HStack {
Text(language.localizedDisplayName)
Spacer()
if language.code == selection.code {
Image(systemName: "checkmark")
}
}
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.padding(.vertical, 4)
.padding(.horizontal, 6)
}
}
}
}
.padding(12)
.frame(width: 320, height: 380)
}
private var filtered: [ModelLanguage] {
let all = LanguageCatalogue.all.sorted {
$0.localizedDisplayName.localizedCaseInsensitiveCompare($1.localizedDisplayName) == .orderedAscending
}
let available = all.filter { language in
guard let excluding else { return true }
return language.code.caseInsensitiveCompare(excluding) != .orderedSame
}
guard !query.trimmingCharacters(in: .whitespaces).isEmpty else { return available }
return available.filter {
$0.localizedDisplayName.localizedCaseInsensitiveContains(query)
|| $0.modelName.localizedCaseInsensitiveContains(query)
|| $0.code.localizedCaseInsensitiveContains(query)
}
}
}