SPB Git

Repository Public License

Naming.swift 9.2 KB 210 lines swift

1// ORIX Scan2// File: App/Sources/Core/Naming.swift3// Description: User-facing names for engine values (filters, presets, steps, issues) and error messages.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import Foundation8import ORIXKit9import SwiftUI1011extension FilterMode {12    var title: LocalizedStringResource {13        switch self { case .original: "Original"; case .color: "Colour"; case .grayscale: "Greyscale"; case .blackWhite: "Black & White" }14    }15    var symbol: String {16        switch self { case .original: "photo"; case .color: "paintpalette"; case .grayscale: "circle.lefthalf.filled"; case .blackWhite: "doc.plaintext" }17    }18}1920extension ExportPreset {21    var title: LocalizedStringResource {22        switch self { case .maximum: "Maximum Quality"; case .balanced: "Balanced"; case .small: "Small File Size" }23    }24    var detail: LocalizedStringResource {25        switch self {26        case .maximum: "Full resolution. Imported pages are kept untouched."27        case .balanced: "Sharp on screen and in print, much lighter."28        case .small: "Smallest files for sending. Fine text can soften."29        }30    }31}3233extension PageSizeMode {34    var title: LocalizedStringResource {35        switch self { case .automatic: "Automatic"; case .a4: "A4"; case .letter: "US Letter" }36    }37}3839extension RecognitionMode {40    var title: LocalizedStringResource {41        switch self { case .automatic: "Automatic"; case .fast: "Fast"; case .accurate: "Accurate" }42    }43    var detail: LocalizedStringResource {44        switch self {45        case .automatic: "Accurate recognition that detects the language of each page."46        case .fast: "Quickest results. Best for clean, printed text."47        case .accurate: "Best results in the languages you choose."48        }49    }50}5152extension LibrarySort {53    var title: LocalizedStringResource {54        switch self { case .modified: "Date Modified"; case .created: "Date Created"; case .title: "Name"; case .size: "Size"; case .pages: "Pages" }55    }56}5758extension LibraryFilter {59    var title: LocalizedStringResource {60        switch self {61        case .all: "All Documents"; case .favorites: "Favourites"; case .withText: "With Text"62        case .withoutText: "Without Text"; case .scans: "Scans"; case .imports: "Imported"63        }64    }65}6667extension QualityIssue {68    var title: LocalizedStringResource {69        switch self {70        case .blur: "This page looks blurry"71        case .lowContrast: "Low contrast"72        case .tooDark: "The page is dark"73        case .tooBright: "The page is washed out"74        case .lowResolution: "Low resolution"75        case .perspective: "Strong perspective"76        case .croppedText: "Text may be cut off"77        case .unreadableRegions: "Some text is hard to read"78        }79    }80    var advice: LocalizedStringResource {81        switch self {82        case .blur: "Hold the device steady and retake the page for sharper text."83        case .lowContrast: "Try the Black & White filter, or retake with more light."84        case .tooDark: "Add light or raise the brightness."85        case .tooBright: "Avoid direct light or glare, then retake."86        case .lowResolution: "Small text may not be recognized. Move closer and retake."87        case .perspective: "The page was captured at an angle. Shoot from straight above for best results."88        case .croppedText: "Text touches the edge. Check the crop."89        case .unreadableRegions: "Recognition was unsure about part of this page. Review the text."90        }91    }92}9394extension ActionKind {95    var title: LocalizedStringResource {96        switch self {97        case .autoCrop: "Detect Edges"; case .deskew: "Straighten"; case .enhance: "Enhance"; case .recognizeText: "Recognize Text"98        case .rename: "Rename"; case .moveToFolder: "Move to Folder"; case .markFavorite: "Mark as Favourite"99        case .exportPDF: "Create PDF"; case .exportText: "Export Text"; case .exportTables: "Export Tables"100        }101    }102    var symbol: String {103        switch self {104        case .autoCrop: "crop"; case .deskew: "level"; case .enhance: "wand.and.stars"; case .recognizeText: "text.viewfinder"105        case .rename: "pencil"; case .moveToFolder: "folder"; case .markFavorite: "star"106        case .exportPDF: "doc.richtext"; case .exportText: "text.alignleft"; case .exportTables: "tablecells"107        }108    }109    var summary: LocalizedStringResource {110        switch self {111        case .autoCrop: "Finds the page outline in photos and crops to it."112        case .deskew: "Rotates pages so text lines are level."113        case .enhance: "Applies a filter and cleans the background."114        case .recognizeText: "Reads the text of every page, on this device."115        case .rename: "Names the document from a pattern."116        case .moveToFolder: "Files the document in a folder."117        case .markFavorite: "Adds the document to Favourites."118        case .exportPDF: "Builds a PDF, searchable when text is recognized."119        case .exportText: "Saves the recognized text as a file."120        case .exportTables: "Saves detected tables as CSV files."121        }122    }123}124125extension WorkflowInput {126    var title: LocalizedStringResource {127        switch self { case .scan: "Scan"; case .photos: "Photos"; case .files: "Files"; case .library: "Library Documents" }128    }129    var symbol: String {130        switch self { case .scan: "doc.viewfinder"; case .photos: "photo.on.rectangle"; case .files: "folder"; case .library: "books.vertical" }131    }132}133134extension Workflow {135    /// Presets are named in the user's language; user workflows keep the name they were given.136    var displayName: String {137        guard let key = presetKey else { return name }138        switch key {139        case "scanToPDF": return String(localized: "Scan to PDF")140        case "scanToSearchablePDF": return String(localized: "Scan to Searchable PDF")141        case "receiptArchive": return String(localized: "Receipt Archive")142        case "documentCleanup": return String(localized: "Document Cleanup")143        case "bookScanner": return String(localized: "Book Scanner")144        case "extractText": return String(localized: "Extract Text")145        case "extractTables": return String(localized: "Extract Tables")146        case "compressPDF": return String(localized: "Compress PDF")147        default: return name148        }149    }150}151152extension StepOutcome.Note {153    var title: LocalizedStringResource {154        switch self {155        case .noOutlineFound: "No page outline found"156        case .alreadyStraight: "Already straight"157        case .noTablesFound: "No table found"158        case .noTextFound: "No text found"159        case .alreadyRecognized: "Text already recognized"160        }161    }162}163164struct AlertInfo: Identifiable {165    let id = UUID()166    var title: String167    var message: String168169    /// Turns any error into words a person can act on. Document content never appears in these messages.170    init(_ error: Error) {171        switch error {172        case ORIXError.documentNotFound:173            title = String(localized: "Document Not Found"); message = String(localized: "This document is no longer in your library.")174        case ORIXError.pageNotFound:175            title = String(localized: "Page Not Found"); message = String(localized: "This page is no longer part of the document.")176        case ORIXError.unreadableImage:177            title = String(localized: "Image Can't Be Read"); message = String(localized: "The image is damaged or in a format ORIX Scan doesn't support.")178        case ORIXError.unreadablePDF:179            title = String(localized: "PDF Can't Be Opened"); message = String(localized: "The file is damaged or isn't a valid PDF.")180        case ORIXError.passwordRequired, ORIXError.wrongPassword:181            title = String(localized: "Password Needed"); message = String(localized: "This PDF is protected. Enter its password to import it.")182        case ORIXError.insufficientStorage:183            title = String(localized: "Not Enough Storage"); message = String(localized: "Free up space on this device, then try again. Nothing was lost.")184        case ORIXError.emptyDocument:185            title = String(localized: "Nothing to Save"); message = String(localized: "A document needs at least one page.")186        case ORIXError.exportFailed:187            title = String(localized: "Export Failed"); message = String(localized: "The file couldn't be created. Your document is unchanged.")188        case ORIXError.recognitionFailed:189            title = String(localized: "Text Recognition Failed"); message = String(localized: "The text couldn't be read on this page. You can try again.")190        case ORIXError.corruptedManifest:191            title = String(localized: "Document Damaged"); message = String(localized: "This document's index file is damaged and can't be opened.")192        default:193            title = String(localized: "Something Went Wrong"); message = error.localizedDescription194        }195    }196197    init(title: String, message: String) {198        self.title = title199        self.message = message200    }201}202203extension Int {204    var byteCountString: String { ByteCountFormatter.string(fromByteCount: Int64(self), countStyle: .file) }205}206207extension Int64 {208    var byteCountString: String { ByteCountFormatter.string(fromByteCount: self, countStyle: .file) }209}210
Files main
Menu

Theme