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.

Say Peel's own words in the reader's language when a Brewfile can't be written

Țugui Dragoșe0951f7f224c
diff --git a/Peel/Model/InventoryExport.swift b/Peel/Model/InventoryExport.swift
index 99fbf192..7cf64218 100644
--- a/Peel/Model/InventoryExport.swift
+++ b/Peel/Model/InventoryExport.swift
@@ -31,9 +31,13 @@ enum InventoryExport {
alert.runModal()
}
- /// What the alert says when Homebrew couldn't write the Brewfile.
- static func reason(for failure: Homebrew.CommandFailure) -> String {
- failure.output ?? String(localized: "Homebrew stopped without saying why.")
+ /// What the alert says when Homebrew couldn't write the Brewfile: Homebrew's words, or Peel's own sentence in the
+ /// reader's language.
+ static func reason(for failure: Homebrew.CommandFailure, in bundle: Bundle? = nil) -> String {
+ guard let output = failure.output else {
+ return String(localized: "Homebrew stopped without saying why.", bundle: bundle)
+ }
+ return FixedSentence.translated(output.trimmingCharacters(in: .whitespacesAndNewlines), in: bundle)
}
/// Returns nil when the file was written or the user canceled, and the error message otherwise.
diff --git a/PeelTests/AppLibraryTests.swift b/PeelTests/AppLibraryTests.swift
index 85b71e1a..dd313aa3 100644
--- a/PeelTests/AppLibraryTests.swift
+++ b/PeelTests/AppLibraryTests.swift
@@ -704,6 +704,13 @@ private nonisolated final class TestClock: Sendable {
#expect(InventoryExport.reason(for: Homebrew.CommandFailure(output: "Error: No such keg")) == "Error: No such keg")
}
+ @Test func anExportSaysPeelsOwnSentencesInTheReadersLanguage() throws {
+ let romanian = try #require(Bundle.main.path(forResource: "ro", ofType: "lproj").flatMap(Bundle.init(path:)))
+ let notInstalled = Homebrew.CommandFailure(output: "Homebrew isn’t installed.")
+ #expect(InventoryExport.reason(for: notInstalled, in: romanian) == "Homebrew nu este instalat.")
+ #expect(InventoryExport.reason(for: Homebrew.CommandFailure(output: "Error: No such keg\n"), in: romanian) == "Error: No such keg")
+ }
+
@Test func twoCopiesOfAnAppAtTwoBuildsKeepAnAnswerEach() async throws {
let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")
defer { try? FileManager.default.removeItem(at: folder) }