Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internationalise account package #4050

Open
wants to merge 4 commits into
base: detour2023
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Account/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.3
// swift-tools-version:5.7
import PackageDescription

var dependencies: [Package.Dependency] = [
Expand Down Expand Up @@ -27,7 +27,7 @@ dependencies.append(contentsOf: [
let package = Package(
name: "Account",
defaultLocalization: "en",
platforms: [.macOS(SupportedPlatform.MacOSVersion.v11), .iOS(SupportedPlatform.IOSVersion.v14)],
platforms: [.macOS(SupportedPlatform.MacOSVersion.v13), .iOS(SupportedPlatform.IOSVersion.v16)],
products: [
.library(
name: "Account",
Expand Down
22 changes: 11 additions & 11 deletions Account/Sources/Account/Account.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
public static let defaultLocalAccountName: String = {
let defaultName: String
#if os(macOS)
defaultName = NSLocalizedString("account.name.mac", value: "On My Mac", comment: "Account name")
defaultName = String(localized: "account.name.mac", bundle: .module, comment: "On My Mac")
#else
if UIDevice.current.userInterfaceIdiom == .pad {
defaultName = NSLocalizedString("account.name.ipad", value: "On My iPad", comment: "Account name")
defaultName = String(localized: "account.name.ipad", bundle: .module, comment: "On My iPad")
} else {
defaultName = NSLocalizedString("account.name.iphone", value: "On My iPhone", comment: "Account name")
defaultName = String(localized: "account.name.iphone", bundle: .module, comment: "On My iPhone")
}
#endif

Expand Down Expand Up @@ -291,21 +291,21 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
case .onMyMac:
defaultName = Account.defaultLocalAccountName
case .cloudKit:
defaultName = NSLocalizedString("iCloud", comment: "iCloud")
defaultName = String("iCloud")
case .feedly:
defaultName = NSLocalizedString("Feedly", comment: "Feedly")
defaultName = String("Feedly")
case .feedbin:
defaultName = NSLocalizedString("Feedbin", comment: "Feedbin")
defaultName = String("Feedbin")
case .newsBlur:
defaultName = NSLocalizedString("NewsBlur", comment: "NewsBlur")
defaultName = String("NewsBlur")
case .freshRSS:
defaultName = NSLocalizedString("FreshRSS", comment: "FreshRSS")
defaultName = String("FreshRSS")
case .inoreader:
defaultName = NSLocalizedString("Inoreader", comment: "Inoreader")
defaultName = String("Inoreader")
case .bazQux:
defaultName = NSLocalizedString("BazQux", comment: "BazQux")
defaultName = String("BazQux")
case .theOldReader:
defaultName = NSLocalizedString("The Old Reader", comment: "The Old Reader")
defaultName = String("The Old Reader")
}

NotificationCenter.default.addObserver(self, selector: #selector(downloadProgressDidChange(_:)), name: .DownloadProgressDidChange, object: nil)
Expand Down
26 changes: 13 additions & 13 deletions Account/Sources/Account/AccountError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,29 @@ public enum AccountError: LocalizedError {
public var errorTitle: String {
switch self {
case .createErrorNotFound:
return NSLocalizedString("error.title.feed-not-found", bundle: Bundle.module, comment: "Unable to Add Feed")
return String(localized: "error.title.feed-not-found", bundle: .module, comment: "Unable to Add Feed")
case .createErrorAlreadySubscribed:
return NSLocalizedString("error.title.already-subscribed", bundle: Bundle.module, comment: "Already Subscribed")
return String(localized: "error.title.already-subscribed", bundle: .module, comment: "Already Subscribed")
case .opmlImportInProgress:
return NSLocalizedString("error.title.ompl-import-in-progress", bundle: Bundle.module, comment: "OPML Import in Progress")
return String(localized: "error.title.ompl-import-in-progress", bundle: .module, comment: "OPML Import in Progress")
case .wrappedError(_, _):
return NSLocalizedString("error.title.error", bundle: Bundle.module, comment: "Error")
return String(localized: "error.title.error", bundle: .module, comment: "Error")
}
}

public var errorDescription: String? {
switch self {
case .createErrorNotFound:
return NSLocalizedString("error.message.feed-not-found", bundle: Bundle.module, comment: "Can’t add a feed because no feed was found.")
return String(localized: "error.message.feed-not-found", bundle: .module, comment: "Can’t add a feed because no feed was found.")
case .createErrorAlreadySubscribed:
return NSLocalizedString("error.message.feed-already-subscribed", bundle: Bundle.module, comment: "You are already subscribed to this feed and can’t add it again.")
return String(localized: "error.message.feed-already-subscribed", bundle: .module, comment: "You are already subscribed to this feed and can’t add it again.")
case .opmlImportInProgress:
return NSLocalizedString("error.message.opml-import-in-progress", bundle: Bundle.module, comment: "An OPML import for this account is already running.")
return String(localized: "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("error.message.credentials-expired.%@", bundle: Bundle.module, comment: "Your ”%@” credentials have expired.")
let localizedText = String(localized: "error.message.credentials-expired.%@", bundle: .module, comment: "Your ”%@” credentials have expired.")
return String(format: localizedText, account.nameForDisplay)
} else {
return unknownError(error, account)
Expand All @@ -79,15 +79,15 @@ public enum AccountError: LocalizedError {
switch error {
case TransportError.httpError(let status):
if isCredentialsError(status: status) {
return NSLocalizedString("Please update your credentials for this account, or ensure that your account with this service is still valid.", comment: "Expired credentials")
return String(localized: "error.message.credentials-expired.%@", bundle: .module, comment: "Expired credentials")
} else {
return NSLocalizedString("Please try again later.", comment: "Try later")
return String(localized: "error.message.try-later", bundle: .module, comment: "Try later")
}
default:
return NSLocalizedString("Please try again later.", comment: "Try later")
return String(localized: "error.message.try-later", bundle: .module, comment: "Try later")
}
default:
return NSLocalizedString("Please try again later.", comment: "Try later")
return String(localized: "error.message.try-later", bundle: .module, comment: "Try later")
}
}

Expand All @@ -98,7 +98,7 @@ public enum AccountError: LocalizedError {
private extension AccountError {

func unknownError(_ error: Error, _ account: Account) -> String {
let localizedText = NSLocalizedString("An error occurred while processing the “%@” account: %@", comment: "Unknown error")
let localizedText = String(localized: "error.message.\(error.localizedDescription)", bundle: .module, comment: "Unknown error")
return NSString.localizedStringWithFormat(localizedText as NSString, account.nameForDisplay, error.localizedDescription) as String
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum CloudKitAccountDelegateError: LocalizedError {
case unknown

var errorDescription: String? {
return NSLocalizedString("An unexpected CloudKit error occurred.", comment: "An unexpected CloudKit error occurred.")
return String(localized: "error.cloudkit.localizedDescription", bundle: .module, comment: "An unexpected CloudKit error occurred.")
}
}

Expand Down
2 changes: 1 addition & 1 deletion Account/Sources/Account/CloudKit/CloudKitAccountZone.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import CloudKit
enum CloudKitAccountZoneError: LocalizedError {
case unknown
var errorDescription: String? {
return NSLocalizedString("An unexpected CloudKit error occurred.", comment: "An unexpected CloudKit error occurred.")
return String(localized: "error.cloudkit.localizedDescription", bundle: .module, comment: "An unexpected CloudKit error occurred.")
}
}
final class CloudKitAccountZone: CloudKitZone {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
import Foundation

public struct CloudKitWebDocumentation {
public static let limitationsAndSolutionsText = NSLocalizedString("iCloud Syncing Limitations & Solutions", comment: "iCloud Documentation")
public static let limitationsAndSolutionsText = String(localized: "label.text.icloud-syncing-limitations-title", bundle: .module, comment: "iCloud Documentation")
public static let limitationsAndSolutionsURL = URL(string: "https://netnewswire.com/help/iCloud")!
}
6 changes: 3 additions & 3 deletions Account/Sources/Account/CombinedRefreshProgress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ public struct CombinedRefreshProgress {
if isInprecise {
if numberOfDownloadsActive == 1 {
if let activeName = downloadProgressArray.first(where: { $0.isComplete == false })?.name {
let formatString = NSLocalizedString("Syncing %@", comment: "Status bar progress")
let formatString = String(localized: "message.activeName.syncing-%@", bundle: .module, comment: "Status bar progress")
label = NSString(format: formatString as NSString, activeName) as String
}
} else {
let formatString = NSLocalizedString("Syncing %@ accounts", comment: "Status bar progress")
let formatString = String(localized: "message.syncing-%@-accounts", bundle: .module, comment: "Status bar progress")
label = NSString(format: formatString as NSString, NSNumber(value: numberOfDownloadsActive)) as String
}
} else {
let formatString = NSLocalizedString("%@ of %@", comment: "Status bar progress")
let formatString = String(localized: "%@-of-%@", bundle: .module, comment: "Status bar progress")
label = NSString(format: formatString as NSString, NSNumber(value: numberCompleted), NSNumber(value: numberOfTasks)) as String
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public enum RedditFeedProviderError: LocalizedError {
public var errorDescription: String? {
switch self {
case .rateLimitExceeded:
return NSLocalizedString("Reddit API rate limit has been exceeded. Please wait a short time and try again.", comment: "Rate Limit")
return String(localized: "error.message.reddit-api-limit-exceeded", bundle: .module, comment: "Rate Limit")
case .accessFailure(let error):
return NSLocalizedString("An attempt to access your Reddit feed(s) failed.\n\nIf this problem persists, please deactivate and reactivate the Reddit extension to fix this problem.\n\n\(error.localizedDescription)", comment: "Reddit Access")
return String(localized: "error.message.reddit-access.failure.\n\n\(error.localizedDescription)", bundle: .module, comment: "Reddit Access")
case .unknown:
return NSLocalizedString("A Reddit Feed Provider error has occurred.", comment: "Unknown error")
return String(localized: "error.message.unknown-error-contact-support", bundle: .module, comment: "Unknown error")
}
}
}
Expand All @@ -45,8 +45,8 @@ public final class RedditFeedProvider: FeedProvider, RedditFeedProviderTokenRefr
private static let userAgentHeaders = UserAgent.headers() as! [String: String]

private static let pseudoSubreddits = [
"popular": NSLocalizedString("Popular", comment: "Popular"),
"all": NSLocalizedString("All", comment: "All")
"popular": String(localized: "message-popular", bundle: .module, comment: "Popular"),
"all": String(localized:"message-all", bundle: .module, comment: "All")
]

private let operationQueue = MainThreadOperationQueue()
Expand Down Expand Up @@ -126,7 +126,7 @@ public final class RedditFeedProvider: FeedProvider, RedditFeedProviderTokenRefr
// Reddit Home
let splitPath = path.split(separator: "/")
if path == "" || path == "/" || (splitPath.count == 1 && RedditSort(rawValue: String(splitPath[0])) != nil) {
let name = NSLocalizedString("Reddit Home", comment: "Reddit Home")
let name = String(localized: "reddit-home", bundle: .module, comment: "Reddit Home")
let metaData = FeedProviderFeedMetaData(name: name, homePageURL: Self.homeURL)
completion(.success(metaData))
return
Expand All @@ -147,7 +147,7 @@ public final class RedditFeedProvider: FeedProvider, RedditFeedProviderTokenRefr

// Reddit Popular, Reddit All, etc...
if let subredditName = Self.pseudoSubreddits[String(splitPath[1])] {
let localized = NSLocalizedString("Reddit %@", comment: "Reddit")
let localized = String(localized: "reddit-\(subredditName)", bundle: .module, comment: "Reddit")
let name = NSString.localizedStringWithFormat(localized as NSString, subredditName) as String
let metaData = FeedProviderFeedMetaData(name: name, homePageURL: homePageURL)
completion(.success(metaData))
Expand Down
10 changes: 5 additions & 5 deletions Account/Sources/Account/FeedProvider/Reddit/RedditSort.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ public enum RedditSort: String, CaseIterable {
var displayName: String {
switch self {
case .best:
return NSLocalizedString("Best", comment: "Best")
return String(localized: "displayname-best", bundle: .module, comment: "Best")
case .rising:
return NSLocalizedString("Rising", comment: "Rising")
return String(localized:"displayname-rising", bundle: .module, comment: "Rising")
case .hot:
return NSLocalizedString("Hot", comment: "Hot")
return String(localized:"displayname-hot", bundle: .module, comment: "Hot")
case .new:
return NSLocalizedString("New", comment: "New")
return String(localized:"displayname-new", bundle: .module, comment: "New")
case .top:
return NSLocalizedString("Top", comment: "Top")
return String(localized:"displayname-top", bundle: .module, comment: "Top")
}
}
}
26 changes: 13 additions & 13 deletions Account/Sources/Account/Feedly/FeedlyAccountDelegateError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,41 @@ enum FeedlyAccountDelegateError: LocalizedError {
var errorDescription: String? {
switch self {
case .notLoggedIn:
return NSLocalizedString("Please add the Feedly account again. If this problem persists, open Keychain Access and delete all feedly.com entries, then try again.", comment: "Feedly – Credentials not found.")
return String(localized: "error.feedly.credentials-not-found", bundle: .module, comment: "Feedly – Credentials not found.")

case .unexpectedResourceId(let resourceId):
let template = NSLocalizedString("Could not encode the identifier “%@”.", comment: "Feedly – Could not encode resource id to send to Feedly.")
let template = String(localized: "error.message.could-not-encode-identifier-\(resourceId)", bundle: .module, comment: "Feedly – Could not encode resource id to send to Feedly.")
return String(format: template, resourceId)

case .unableToAddFolder(let name):
let template = NSLocalizedString("Could not create a folder named “%@”.", comment: "Feedly – Could not create a folder/collection.")
let template = String(localized: "error.message.could-not-create-folder-\(name)", bundle: .module, comment: "Feedly – Could not create a folder/collection.")
return String(format: template, name)

case .unableToRenameFolder(let from, let to):
let template = NSLocalizedString("Could not rename “%@” to “%@”.", comment: "Feedly – Could not rename a folder/collection.")
let template = String(localized: "error.message.could-not-rename-folder", bundle: .module, comment: "Feedly – Could not rename a folder/collection.")
return String(format: template, from, to)

case .unableToRemoveFolder(let name):
let template = NSLocalizedString("Could not remove the folder named “%@”.", comment: "Feedly – Could not remove a folder/collection.")
let template = String(localized: "error.message.could-not-remove-folder-\(name)", bundle: .module, comment: "Feedly – Could not remove a folder/collection.")
return String(format: template, name)

case .unableToMoveFeedBetweenFolders(let feed, _, let to):
let template = NSLocalizedString("Could not move “%@” to “%@”.", comment: "Feedly – Could not move a feed between folders/collections.")
let template = String(localized: "error.message.could-not-move-feed", bundle: .module, comment: "Feedly – Could not move a feed between folders/collections.")
return String(format: template, feed.nameForDisplay, to.nameForDisplay)

case .addFeedChooseFolder:
return NSLocalizedString("Please choose a folder to contain the feed.", comment: "Feedly – Feed can only be added to folders.")
return String(localized: "error.message.folder-not-chosen", bundle: .module, comment: "Feedly – Feed can only be added to folders.")

case .addFeedInvalidFolder(let invalidFolder):
let template = NSLocalizedString("Feeds cannot be added to the “%@” folder.", comment: "Feedly – Feed can only be added to folders.")
let template = String(localized: "error.message.could-not-add-to-folder", bundle: .module, comment: "Feedly – Feed can only be added to folders.")
return String(format: template, invalidFolder.nameForDisplay)

case .unableToRenameFeed(let from, let to):
let template = NSLocalizedString("Could not rename “%@” to “%@”.", comment: "Feedly – Could not rename a feed.")
let template = String(localized: "error.message.could-not-rename-feed", bundle: .module, comment: "Feedly – Could not rename a feed.")
return String(format: template, from, to)

case .unableToRemoveFeed(let feed):
let template = NSLocalizedString("Could not remove “%@”.", comment: "Feedly – Could not remove a feed.")
let template = String(localized: "error.message.could-not-remove-feed", bundle: .module, comment: "Feedly – Could not remove a feed.")
return String(format: template, feed.nameForDisplay)
}
}
Expand All @@ -68,7 +68,7 @@ enum FeedlyAccountDelegateError: LocalizedError {
return nil

case .unexpectedResourceId:
let template = NSLocalizedString("Please contact NetNewsWire support.", comment: "Feedly – Recovery suggestion for not being able to encode a resource id to send to Feedly..")
let template = String(localized: "error.message.contact-support", bundle: .module, comment: "Feedly – Recovery suggestion for not being able to encode a resource id to send to Feedly..")
return String(format: template)

case .unableToAddFolder:
Expand All @@ -81,14 +81,14 @@ enum FeedlyAccountDelegateError: LocalizedError {
return nil

case .unableToMoveFeedBetweenFolders(let feed, let from, let to):
let template = NSLocalizedString("“%@” may be in both “%@” and “%@”.", comment: "Feedly – Could not move a feed between folders/collections.")
let template = String(localized: "error.message.unable-to-move-feed-between-folders", bundle: .module, comment: "Feedly – Could not move a feed between folders/collections.")
return String(format: template, feed.nameForDisplay, from.nameForDisplay, to.nameForDisplay)

case .addFeedChooseFolder:
return nil

case .addFeedInvalidFolder:
return NSLocalizedString("Please choose a different folder to contain the feed.", comment: "Feedly – Feed can only be added to folders recovery suggestion.")
return String(localized: "error.message.add-feed-invalid-folder", bundle: .module, comment: "Feedly – Feed can only be added to folders recovery suggestion.")

case .unableToRemoveFeed:
return nil
Expand Down
Loading