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.
27 lines
1.2 KiB
Swift
27 lines
1.2 KiB
Swift
import SprachmittlerText
|
|
|
|
/// Family-neutral same-language check used by the pipeline. The canonical-code mapping stays in
|
|
/// Engines, next to the catalogue that defines it.
|
|
public enum LanguageMatching {
|
|
/// True when detection is confident and every meaningful alternative resolves to `language`.
|
|
public static func isLanguage(_ detection: LanguageDetection, _ language: ModelLanguage) -> Bool {
|
|
guard detection.confidence >= 0.5, !detection.alternatives.isEmpty else { return false }
|
|
let targetCode = HyMT3Languages.resolve(language.code)?.code ?? language.code
|
|
var agreed = false
|
|
for code in detection.alternatives {
|
|
guard let resolved = HyMT3Languages.resolve(code),
|
|
resolved.code.caseInsensitiveCompare(targetCode) == .orderedSame
|
|
else {
|
|
return false
|
|
}
|
|
agreed = true
|
|
}
|
|
return agreed
|
|
}
|
|
|
|
/// True when detection is confident and every meaningful alternative is the target language.
|
|
public static func isSameLanguage(_ detection: LanguageDetection, target: ModelLanguage) -> Bool {
|
|
isLanguage(detection, target)
|
|
}
|
|
}
|