Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

3.6 KB
Raw Blame
import PeelCore
import SwiftUI

extension FixedSentence {
    /// Here rather than in PeelCore, which has no catalog of its own, so the words follow the reader's language.
    var words: LocalizedStringResource {
        switch self {
        case .notAFullPath: "That isn’t a full path."
        case .dotInPath: "The path has a . or .. in it."
        case .controlCharacter: "The path holds a character no real name has."
        case .folderNotFound: "The folder it’s in couldn’t be found."
        case .tooManyOpenFolders: "Peel’s helper had too many folders open at once. Try again."
        case .outsideHelpersFolders: "It is outside the folders Peel’s helper may touch."
        case .onlyAppsThere: "Peel removes only apps from that folder."
        case .notThereAnymore: "It isn’t there anymore."
        case .alreadyThere: "Something is there already."
        case .protectedByMacOS: "macOS marks it as protected."
        case .irreplaceable: "It holds something nothing could bring back, so Peel never moves it."
        case .codeFolder: "It could have changed while it was in the Trash, and code is loaded from that folder, so Peel’s helper puts back only what is root’s alone. You can drag it back out in Finder."
        case .onlyLinksThere: "Peel removes only links from that folder."
        case .leadsSomewhere: "It still leads to something on this Mac."
        case .onlyGoneProgramsThere: "From that folder, Peel removes only what starts a program that is no longer there."
        case .helperOutOfDate: "Peel’s helper is out of date. Reinstall it in Settings."
        case .accountNotAllowed: "This account isn’t allowed to use Peel’s helper."
        case .notAuthorized: "An administrator didn’t allow this."
        case .tooManyItems: "Too many items in one request."
        case .noTrash: "There’s no Trash to move this to."
        case .pathTooLong: "The path is too long."
        case .cannotKeepRecord: "Peel’s helper can’t keep its record of what it moves, so nothing was moved."
        case .cannotReadRecord: "Peel’s helper can’t read its record of what it moved, so nothing was put back."
        case .notInTrash: "It isn’t in the Trash."
        case .notInHelpersRecord: "Peel’s helper has no record of moving this from there, so it stays in the Trash. You can drag it back out in Finder."
        case .invalidRequest: "The request wasn’t valid."
        case .configurationMissing: "The configuration file is missing."
        case .declaredTwice: "Two files declare this job."
        case .toolTimedOut: "The tool didn’t answer in time, so it was stopped."
        case .toolStopped: "Stopped before it finished."
        case .receiptMisplaced: "The receipt isn’t where macOS keeps receipts."
        case .receiptForgotten: "It was already forgotten."
        case .homebrewNotInstalled: "Homebrew isn’t installed."
        case .helperUnavailable: "Peel’s helper isn’t available."
        }
    }

    /// What PeelCore or the helper sent, in the reader's language when it is one of these, as it came otherwise.
    static func translated(_ message: String, in bundle: Bundle? = nil) -> String {
        FixedSentence(message).map { $0.words.resolved(in: bundle) } ?? message
    }
}

extension LocalizedStringResource {
    /// The words as Foundation resolves them, or from `bundle` by their key: only for a sentence with no arguments.
    func resolved(in bundle: Bundle?) -> String {
        guard let bundle else { return String(localized: self) }
        return String(localized: String.LocalizationValue(key), table: table, bundle: bundle, locale: locale)
    }
}