feat(settings): mother-tongue language routing table

Replace the single reverse-direction pair with a general routing table. The saved target is the mother tongue and the default target for every source; languageRoutes is an empty-by-default, source-unique list of source-to-target rules (for example Chinese -> English, Traditional Chinese -> English, German -> English). Rules apply only when the source is confidently detected; otherwise the mother tongue is used. Same-language rules are dropped.\n\nThe panel shows the effective direction and a banner explaining a rule, with a one-capture override back to the mother tongue; the panel picker is now a session-only override. Persistent rules are edited in Settings. The old autoSwitchTarget/fallbackTargetLanguage keys are ignored, so the default after migration is everything -> mother tongue.\n\nAdd LanguageRoute, generalize the direction policy and tests, add the rules UI, and update ADR-022, architecture, translation output, user guide, README and progress. Verified: make verify green; empty rules translate French -> German, a Chinese -> English rule produces Chinese (Simplified) -> English with the banner, and the rules table renders in Settings.
This commit is contained in:
schihei committed 2026-11-26 18:31:45 +01:00
1 parent 41f1cea769
commit 940abcc996
24 files changed
+454 -336

No files matched your search

+6 -6
View File
@@ -66,23 +66,23 @@ extension PanelView {
}
}
private func autoSwitchMessage(from original: ModelLanguage) -> String {
let source = original.localizedDisplayName
private func routedMessage(from routedSource: ModelLanguage) -> String {
let source = routedSource.localizedDisplayName
let target = model.effectiveTarget.localizedDisplayName
return String(localized: "Detected \(source). Translating to \(target).")
}
@ViewBuilder var warningArea: some View {
if let original = model.autoSwitchedFrom {
if let routedSource = model.routedSource {
HStack(alignment: .top, spacing: 8) {
Image(systemName: "arrow.left.arrow.right.circle.fill")
.foregroundStyle(.blue)
.accessibilityHidden(true)
Text(autoSwitchMessage(from: original))
Text(routedMessage(from: routedSource))
.font(.callout)
Spacer()
Button(String(localized: "Translate to \(original.localizedDisplayName)")) {
Task { await model.overrideTarget(original) }
Button(String(localized: "Translate to \(model.configuration.target.localizedDisplayName)")) {
Task { await model.overrideTarget(model.configuration.target) }
}
.controlSize(.small)
}
+1 -1
View File
@@ -84,7 +84,7 @@ struct PanelView: View {
selection: Binding(
get: { model.effectiveTarget },
set: { language in
Task { await model.setTarget(language) }
Task { await model.overrideTarget(language) }
}
),
recent: model.configuration.recentTargets