Unifies account error localizations

This commit is contained in:
Stuart Breckenridge
2023-03-11 17:14:05 +08:00
parent 37cfba50a2
commit ceb925d0f9
8 changed files with 65 additions and 32 deletions

View File

@@ -26,6 +26,7 @@ dependencies.append(contentsOf: [
let package = Package(
name: "Account",
defaultLocalization: "en",
platforms: [.macOS(SupportedPlatform.MacOSVersion.v11), .iOS(SupportedPlatform.IOSVersion.v14)],
products: [
.library(

View File

@@ -32,21 +32,42 @@ public enum AccountError: LocalizedError {
}
return false
}
public var errorTitle: String {
switch self {
case .createErrorNotFound:
// TODO: Add to Localizable
return NSLocalizedString("error.title.feed-not-found", bundle: Bundle.module, comment: "Unable to Add Feed")
case .createErrorAlreadySubscribed:
// TODO: Add to Localizable
return NSLocalizedString("error.title.already-subscribed", bundle: Bundle.module, comment: "Already Subscribed")
case .opmlImportInProgress:
// TODO: Add to Localizable
return NSLocalizedString("error.title.ompl-import-in-progress", bundle: Bundle.module, comment: "OPML Import in Progress")
case .wrappedError(_, _):
// TODO: Add to Localizable
return NSLocalizedString("error.title.error", bundle: Bundle.module, comment: "Error")
}
}
public var errorDescription: String? {
switch self {
case .createErrorNotFound:
return NSLocalizedString("The feed couldnt be found and cant be added.", comment: "Not found")
// TODO: Add to Localizable
return NSLocalizedString("error.message.feed-not-found", bundle: Bundle.module, comment: "Cant add a feed because no feed was found.")
case .createErrorAlreadySubscribed:
return NSLocalizedString("You are already subscribed to this feed and cant add it again.", comment: "Already subscribed")
// TODO: Add to Localizable
return NSLocalizedString("error.message.feed-already-subscribed", bundle: Bundle.module, comment: "You are already subscribed to this feed and cant add it again.")
case .opmlImportInProgress:
return NSLocalizedString("An OPML import for this account is already running.", comment: "Import running")
// TODO: Add to Localizable
return NSLocalizedString("error.message.opml-import-in-progress", bundle: Bundle.module, comment: "An OPML import for this account is already running.")
case .wrappedError(let error, let account):
switch error {
case TransportError.httpError(let status):
if isCredentialsError(status: status) {
let localizedText = NSLocalizedString("Your “%@” credentials are invalid or expired.", comment: "Invalid or expired")
return NSString.localizedStringWithFormat(localizedText as NSString, account.nameForDisplay) as String
// TODO: Add to Localizable
let localizedText = NSLocalizedString("error.message.credentials-expired.%@", bundle: Bundle.module, comment: "Your ”%@” credentials have expired.")
return String(format: localizedText, account.nameForDisplay)
} else {
return unknownError(error, account)
}

View File

@@ -0,0 +1,16 @@
/*
Localizable.strings
Created by Stuart Breckenridge on 11/03/2023.
*/
"error.title.feed-not-found" = "Unable to Add Feed";
"error.title.already-subscribed" = "Already Subscribed";
"error.title.ompl-import-in-progress" = "OPML Import in Progress";
"error.title.error" = "Error";
"error.message.feed-not-found" = "Cant add a feed because no feed was found.";
"error.message.already-subscribed" = "You are already subscribed to this feed and cant add it again.";
"error.message.opml-import-in-progress" = "An OPML import for this account is already running.";

View File

@@ -0,0 +1,16 @@
/*
Localizable.strings
Created by Stuart Breckenridge on 11/03/2023.
*/
"error.title.feed-not-found" = "Unable to Add Feed";
"error.title.already-subscribed" = "Already Subscribed";
"error.title.ompl-import-in-progress" = "OPML Import in Progress";
"error.title.error" = "Error";
"error.message.feed-not-found" = "Cant add a feed because no feed was found.";
"error.message.already-subscribed" = "You are already subscribed to this feed and cant add it again.";
"error.message.opml-import-in-progress" = "An OPML import for this account is already running.";

View File

@@ -136,8 +136,8 @@ private extension AddFeedController {
func showAlreadySubscribedError(_ urlString: String) {
let alert = NSAlert()
alert.alertStyle = .informational
alert.messageText = NSLocalizedString("alert.title.already-subscribed", comment: "Already subscribed")
alert.informativeText = NSLocalizedString("alert.message.already-subscribed", comment: "Cant add this feed because youve already subscribed to it.")
alert.messageText = AccountError.createErrorAlreadySubscribed.errorTitle
alert.informativeText = AccountError.createErrorAlreadySubscribed.localizedDescription
alert.beginSheetModal(for: hostWindow)
}
@@ -155,8 +155,8 @@ private extension AddFeedController {
func showNoFeedsErrorMessage() {
let alert = NSAlert()
alert.alertStyle = .informational
alert.messageText = NSLocalizedString("alert.title.feed-not-found", comment: "Feed not found")
alert.informativeText = NSLocalizedString("alert.message.feed-not-found", comment: "Cant add a feed because no feed was found.")
alert.messageText = AccountError.createErrorNotFound.errorTitle
alert.informativeText = AccountError.createErrorNotFound.localizedDescription
alert.beginSheetModal(for: hostWindow)
}

View File

@@ -64,9 +64,6 @@
/* You won't see this message again */
"alert.informative.will-not-see-again" = "You won't see this message again";
/* Cant add this feed because youve already subscribed to it. */
"alert.message.already-subscribed" = "Cant add this feed because youve already subscribed to it.";
/* Some articles dont have links, so they weren't copied. */
"alert.message.articles-without-links" = "Some articles dont have links, so they weren't copied.";
@@ -101,8 +98,6 @@
/* To enable notifications, open Notifications in System Settings, then find NetNewsWire in the list. */
"alert.message.enable-notifications-in-system-settings" = "To enable notifications, open Notifications in System Settings, then find NetNewsWire in the list.";
/* Cant add a feed because no feed was found. */
"alert.message.feed-not-found" = "Cant add a feed because no feed was found.";
/* A web browser will open the Feedly login for you to authorize access. */
"alert.message.feedly-web-browser-information" = "A web browser will open the Feedly login for you to authorise access.";
@@ -113,9 +108,6 @@
/* Twitter Deprecation Message */
"alert.message.twitter-deprecation-message" = "On February 1, 2023, Twitter announced the end of free access to the Twitter API, effective February 9.\n\nSince Twitter does not provide RSS feeds, weve had to use the Twitter API. Without free access to that API, we cant read feeds from Twitter.\n\nWeve left your Twitter feeds intact. If you have any starred items from those feeds, they will remain as long as you dont delete those feeds.\n\nYou can still read whatever you have already downloaded. However, those feeds will no longer update.";
/* Already subscribed */
"alert.title.already-subscribed" = "Already subscribed";
/* Author's website: */
"alert.title.authors-website" = "Author's website:";
@@ -143,9 +135,6 @@
/* Error */
"alert.title.error" = "Error";
/* Feed not found */
"alert.title.feed-not-found" = "Feed not found";
/* Install theme “%@” by %@? — the order of the variables is theme name, author name */
"alert.title.install-theme.%@.%@" = "Install theme “%@” by %@?";

View File

@@ -61,9 +61,6 @@
/* You won't see this message again */
"alert.informative.will-not-see-again" = "You won't see this message again";
/* Cant add this feed because youve already subscribed to it. */
"alert.message.already-subscribed" = "Cant add this feed because youve already subscribed to it.";
/* Some articles dont have links, so they weren't copied. */
"alert.message.articles-without-links" = "Some articles dont have links, so they weren't copied.";
@@ -98,9 +95,6 @@
/* To enable notifications, open Notifications in System Settings, then find NetNewsWire in the list. */
"alert.message.enable-notifications-in-system-settings" = "To enable notifications, open Notifications in System Settings, then find NetNewsWire in the list.";
/* Cant add a feed because no feed was found. */
"alert.message.feed-not-found" = "Cant add a feed because no feed was found.";
/* A web browser will open the Feedly login for you to authorize access. */
"alert.message.feedly-web-browser-information" = "A web browser will open the Feedly login for you to authorize access.";
@@ -110,9 +104,6 @@
/* Twitter Deprecation Message */
"alert.message.twitter-deprecation-message" = "On February 1, 2023, Twitter announced the end of free access to the Twitter API, effective February 9.\n\nSince Twitter does not provide RSS feeds, weve had to use the Twitter API. Without free access to that API, we cant read feeds from Twitter.\n\nWeve left your Twitter feeds intact. If you have any starred items from those feeds, they will remain as long as you dont delete those feeds.\n\nYou can still read whatever you have already downloaded. However, those feeds will no longer update.";
/* Already subscribed */
"alert.title.already-subscribed" = "Already subscribed";
/* Author's website: */
"alert.title.authors-website" = "Author's website:";
@@ -140,9 +131,6 @@
/* Error */
"alert.title.error" = "Error";
/* Feed not found */
"alert.title.feed-not-found" = "Feed not found";
/* Install theme “%@” by %@? — the order of the variables is theme name, author name */
"alert.title.install-theme.%@.%@" = "Install theme “%@” by %@?";

View File

@@ -44,6 +44,8 @@ extension UIViewController {
informativeText = error.localizedDescription
presentError(title: errorTitle, message: informativeText, dismiss: dismiss)
}
} else if let accountError = error as? AccountError {
presentError(title: accountError.errorTitle, message: accountError.localizedDescription)
} else {
let errorTitle = NSLocalizedString("alert.title.error", comment: "Error")
presentError(title: errorTitle, message: error.localizedDescription, dismiss: dismiss)