import Foundation /// UI-facing warning helpers re-exported by Core. public extension TranslationWarning { /// A short panel message. It never rewrites the translation. var panelMessage: String { switch self { case let .preambleDetected(line): String(localized: "The model added an explanation: “\(line)”") case .truncated: String(localized: "The translation was cut off.") case .repetitionLoop: String(localized: "The translation started repeating.") case let .missingProtectedToken(token): String(localized: "A protected token was lost: \(token)") case .emptyOutput: String(localized: "The model returned an empty translation.") case let .sameLanguage(source, target): String(localized: "This text already appears to be in \(target) (detected \(source)).") case .numericMismatch: String(localized: "A number may have changed.") case let .chunkFailed(index): String(localized: "Chunk \(index + 1) failed; the translation is incomplete.") } } /// True when the warning should disable Replace by default. /// The domain error that blocks Replace for this warning. var insertionError: SprachmittlerError { switch self { case .truncated: .truncated case .repetitionLoop: .repetitionLoop case .preambleDetected: .preambleDetected case let .missingProtectedToken(token): .protectedTokenLost(token: token) case .emptyOutput: .emptyOutput case .chunkFailed: .server(status: 0, message: "Chunk failed") case .sameLanguage, .numericMismatch: .cancelled } } var isBlocking: Bool { switch self { case .preambleDetected, .truncated, .repetitionLoop, .missingProtectedToken, .emptyOutput, .chunkFailed: true case .sameLanguage, .numericMismatch: false } } }