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) } }