Add variable translations

This commit is contained in:
2024-06-18 19:45:19 +02:00
parent b9fc904f8c
commit 6cdffafa9a

View File

@ -9,6 +9,36 @@ import NVAlert
open class UpdateCheck open class UpdateCheck
{ {
/**
* Translations that can be overridden.
*/
public struct translations {
public static var couldNotRetrieveUpdateTitle
= "Could not retrieve update information."
public static var couldNotRetrieveUpdateDescription
= "There was an issue retrieving information about possible updates. This could be a connection or server issue. Check your internet connection and try again later."
public static var appIsUpToDateTitle
= "%@ is up-to-date!"
public static var appIsUpToDateDescription
= "The version on the server is not newer than this version, so you're all good."
public static var updateAvailableTitle
= "An updated version of %@ is available."
public static var updateAvailableSubtitle
= "Version %@ is available for download."
public static var updateAvailableDescription
= "Do you want to download and install this updated version?"
public static var buttonInstall = "Install"
public static var buttonDismiss = "Dismiss"
public static var buttonViewReleaseNotes = "View Release Notes"
}
let caskUrl: URL let caskUrl: URL
let selfUpdaterName: String let selfUpdaterName: String
let selfUpdaterPath: String let selfUpdaterPath: String
@ -40,6 +70,11 @@ open class UpdateCheck
self.caskUrl = caskUrl self.caskUrl = caskUrl
} }
/**
* Resolves the URL for the release notes using he given callback.
*
* You will be able to use the retrieved CaskFile which you may need in order to determine the complete URL.
*/
public func resolvingReleaseNotes(with callback: @escaping (NVCaskFile) -> URL?) -> Self { public func resolvingReleaseNotes(with callback: @escaping (NVCaskFile) -> URL?) -> Self {
self.releaseNotesUrlCallback = callback self.releaseNotesUrlCallback = callback
return self return self
@ -86,8 +121,8 @@ open class UpdateCheck
if promptOnFailure { if promptOnFailure {
await Alert.confirm( await Alert.confirm(
title: "Could not retrieve update information!", title: translations.couldNotRetrieveUpdateTitle,
description: "There was an issue retrieving information about possible updates. This could be a connection or server issue. Check your internet connection and try again later." description: translations.couldNotRetrieveUpdateDescription
) )
} }
} }
@ -97,8 +132,9 @@ open class UpdateCheck
if promptOnFailure { if promptOnFailure {
await Alert.confirm( await Alert.confirm(
title: "The app is up-to-date!", title: translations.appIsUpToDateTitle
description: "The version on the server is not newer than this version, so you're all good." .replacingOccurrences(of: "%@", with: Executable.name),
description: translations.appIsUpToDateDescription
) )
} }
} }
@ -109,24 +145,26 @@ open class UpdateCheck
let current = AppVersion.fromCurrentVersion() let current = AppVersion.fromCurrentVersion()
let alert = await NVAlert().withInformation( let alert = await NVAlert().withInformation(
title: "An updated version of \(Executable.name) is available.", title: translations.updateAvailableTitle
subtitle: "Version \(newerVersion.version) is available for download.", .replacingOccurrences(of: "%@", with: Executable.name),
description: "Do you want to download and install this updated version?" subtitle: translations.updateAvailableSubtitle
.replacingOccurrences(of: "%@", with: newerVersion.version),
description: translations.updateAvailableDescription
) )
.withPrimary( .withPrimary(
text: "Install", text: translations.buttonInstall,
action: { vc in action: { vc in
vc.close(with: .OK) vc.close(with: .OK)
self.launchSelfUpdater() self.launchSelfUpdater()
} }
) )
.withTertiary(text: "Dismiss", action: { vc in .withTertiary(text: translations.buttonDismiss, action: { vc in
vc.close(with: .OK) vc.close(with: .OK)
}) })
if let callback = self.releaseNotesUrlCallback, if let callback = self.releaseNotesUrlCallback,
let url = callback(self.caskFile) { let url = callback(self.caskFile) {
await alert.withSecondary(text: "View Release Notes") { _ in await alert.withSecondary(text: translations.buttonViewReleaseNotes) { _ in
NSWorkspace.shared.open(url) NSWorkspace.shared.open(url)
} }
} }