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

Rename Text to Localized #905

Merged
merged 3 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
48 changes: 27 additions & 21 deletions Planetary.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Shared/Extensions/Bool+YesOrNo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ import Foundation

extension Bool {
var yesOrNo: String {
self ? Text.yes.text : Text.no.text
self ? Localized.yes.text : Localized.no.text
}
}
2 changes: 1 addition & 1 deletion Shared/Extensions/Text+Gradient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import SwiftUI

extension SwiftUI.Text {
extension Text {

/// Colors the text with the given gradient
public func foregroundLinearGradient(colors: [Color], startPoint: UnitPoint, endPoint: UnitPoint) -> some View {
Expand Down
16 changes: 8 additions & 8 deletions Shared/Extensions/UIViewController+Alert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ protocol AlertRouter {
extension UIViewController: AlertRouter {

func alert(error: Error) {
let controller = UIAlertController(title: Text.error.text,
let controller = UIAlertController(title: Localized.error.text,
message: error.localizedDescription,
preferredStyle: .alert)
controller.view.tintColor = UIColor.tint.system

let cancelAction = UIAlertAction(title: Text.cancel.text,
let cancelAction = UIAlertAction(title: Localized.cancel.text,
style: .cancel) { _ in
controller.dismiss(animated: true)
}
Expand All @@ -48,7 +48,7 @@ extension UIViewController: AlertRouter {
func alert(from sourceView: AnyObject? = nil,
title: String? = nil,
message: String,
cancelTitle: String = Text.cancel.text,
cancelTitle: String = Localized.cancel.text,
cancelClosure: (() -> Void)? = nil) {

let cancel = UIAlertAction(title: cancelTitle, style: .cancel) { _ in
Expand All @@ -65,7 +65,7 @@ extension UIViewController: AlertRouter {
from sourceView: AnyObject? = nil,
title: String? = nil,
message: String,
cancelTitle: String = Text.cancel.text
cancelTitle: String = Localized.cancel.text
) async {

await withCheckedContinuation { continuation in
Expand All @@ -92,9 +92,9 @@ extension UIViewController: AlertRouter {
title: String? = nil,
message: String,
isDestructive: Bool = false,
cancelTitle: String = Text.cancel.text,
cancelTitle: String = Localized.cancel.text,
cancelClosure: (() -> Void)? = nil,
confirmTitle: String = Text.ok.text,
confirmTitle: String = Localized.ok.text,
confirmClosure: @escaping (() -> Void)) {

let confirm = UIAlertAction(title: confirmTitle,
Expand All @@ -116,8 +116,8 @@ extension UIViewController: AlertRouter {
title: String? = nil,
message: String,
isDestructive: Bool = false,
cancelTitle: String = Text.cancel.text,
confirmTitle: String = Text.ok.text
cancelTitle: String = Localized.cancel.text,
confirmTitle: String = Localized.ok.text
) async -> Bool {

await withCheckedContinuation { continuation in
Expand Down
2 changes: 1 addition & 1 deletion Shared/Extensions/UIViewController+NavigationItems.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension UIViewController {

func addDismissBarButtonItem() {
let item = UIBarButtonItem(image: UIImage.verse.dismiss, style: .plain, target: self, action: #selector(didPressDismiss))
item.accessibilityLabel = Text.done.text
item.accessibilityLabel = Localized.done.text
self.navigationItem.leftBarButtonItem = item
}

Expand Down
6 changes: 3 additions & 3 deletions Source/App/AppController+Push.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ extension AppController {
) {
let controller = viewController ?? self
controller.confirm(
title: Text.Push.title.text,
message: Text.Push.prompt.text,
title: Localized.Push.title.text,
message: Localized.Push.prompt.text,
isDestructive: false,
cancelClosure: { completion?(status) },
confirmTitle: Text.settings.text,
confirmTitle: Localized.settings.text,
confirmClosure: AppController.shared.openOSSettings
)
}
Expand Down
4 changes: 2 additions & 2 deletions Source/App/AppController+URL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ extension AppController {
let controller = UIAlertController(title: "This is an invite to a Pub",
message: "Are you sure you want to redeem this invite?",
preferredStyle: .alert)
var action = UIAlertAction(title: Text.cancel.text, style: .cancel) {
var action = UIAlertAction(title: Localized.cancel.text, style: .cancel) {
_ in
controller.dismiss(animated: true, completion: nil)
}
controller.addAction(action)

action = UIAlertAction(title: Text.yes.text, style: .default) { [weak self] _ in
action = UIAlertAction(title: Localized.yes.text, style: .default) { [weak self] _ in
controller.dismiss(animated: false, completion: nil)
self?.showProgress()
let star = Star(invite: invite)
Expand Down
10 changes: 5 additions & 5 deletions Source/App/AppDelegate+Push.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,34 +82,34 @@ extension AppDelegate: UNUserNotificationCenterDelegate {

let content = UNMutableNotificationContent()

let nameToShow = about?.nameOrIdentity ?? Text.Report.somebody.text
let nameToShow = about?.nameOrIdentity ?? Localized.Report.somebody.text

// swiftlint:disable legacy_objc_type
switch report.reportType {
case .feedFollowed:
content.title = NSString.localizedUserNotificationString(
forKey: Text.Report.feedFollowed.text,
forKey: Localized.Report.feedFollowed.text,
arguments: [nameToShow]
)
case .postReplied:
content.title = NSString.localizedUserNotificationString(
forKey: Text.Report.postReplied.text,
forKey: Localized.Report.postReplied.text,
arguments: [nameToShow]
)
if let what = report.message.content.post?.text {
content.body = what.withoutGallery().decodeMarkdown().string
}
case .feedMentioned:
content.title = NSString.localizedUserNotificationString(
forKey: Text.Report.feedMentioned.text,
forKey: Localized.Report.feedMentioned.text,
arguments: [nameToShow]
)
if let what = report.message.content.post?.text {
content.body = what.withoutGallery().decodeMarkdown().string
}
case .messageLiked:
content.title = NSString.localizedUserNotificationString(
forKey: Text.Report.messageLiked.text,
forKey: Localized.Report.messageLiked.text,
arguments: [nameToShow]
)
}
Expand Down
4 changes: 2 additions & 2 deletions Source/App/AppError+LocalizedError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ extension AppError: LocalizedError {
var errorDescription: String? {
switch self {
case .unexpected:
return Text.Error.unexpected.text
return Localized.Error.unexpected.text
case .invalidInvite:
return Text.Error.unexpected.text
return Localized.Error.unexpected.text
}
}
}
8 changes: 4 additions & 4 deletions Source/Bot/BotError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ enum BotError: Error, LocalizedError {
case .notLoggedIn:
return "Not logged in"
case .forkProtection:
return Text.Error.cannotPublishBecauseRestoring.text
return Localized.Error.cannotPublishBecauseRestoring.text
case .invalidAppConfiguration:
return Text.Error.invalidAppConfiguration.text
return Localized.Error.invalidAppConfiguration.text
case .restoring:
return Text.Error.restoring.text
return Localized.Error.restoring.text
case .internalError:
return Text.Error.unexpected.text
return Localized.Error.unexpected.text
}
}
}
2 changes: 1 addition & 1 deletion Source/Bot/Operations/RedeemInviteOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class RedeemInviteOperation: AsynchronousOperation {
// Construct a better error message before returning
Bots.current.about(identity: self.star.feed) { about, _ in
let starName = about?.name ?? self.star.feed
let localizedMessage = Text.Error.invitationRedemptionFailed.text(["starName": starName])
let localizedMessage = Localized.Error.invitationRedemptionFailed.text(["starName": starName])
let userError = NSError(
domain: String(describing: type(of: self)),
code: 0,
Expand Down
28 changes: 14 additions & 14 deletions Source/Controller/AboutViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class AboutViewController: ContentViewController {

var actions = [UIAlertAction]()

let sharePublicIdentifier = UIAlertAction(title: Text.sharePublicIdentifier.text, style: .default) { _ in
let sharePublicIdentifier = UIAlertAction(title: Localized.sharePublicIdentifier.text, style: .default) { _ in
Analytics.shared.trackDidSelectAction(actionName: "share_public_identifier")

let activityController = UIActivityViewController(
Expand All @@ -246,11 +246,11 @@ class AboutViewController: ContentViewController {
actions.append(sharePublicIdentifier)

if let publicLink = self.identity.publicLink {
let share = UIAlertAction(title: Text.shareThisProfile.text, style: .default) { _ in
let share = UIAlertAction(title: Localized.shareThisProfile.text, style: .default) { _ in
Analytics.shared.trackDidSelectAction(actionName: "share_profile")

let nameOrIdentity = self.about?.name ?? self.identity
let text = Text.shareThisProfileText.text([
let text = Localized.shareThisProfileText.text([
"who": nameOrIdentity,
"link": publicLink.absoluteString
])
Expand All @@ -267,28 +267,28 @@ class AboutViewController: ContentViewController {

if !identity.isCurrentUser {
let block = UIAlertAction(
title: Text.blockUser.text,
title: Localized.blockUser.text,
style: .destructive,
handler: self.didSelectBlockAction(action:)
)
actions.append(block)

let report = UIAlertAction(
title: Text.reportUser.text,
title: Localized.reportUser.text,
style: .destructive,
handler: self.didSelectReportAction(action:)
)
actions.append(report)
} else {
let manageAliases = UIAlertAction(
title: Text.Alias.manageAliases.text,
title: Localized.Alias.manageAliases.text,
style: .default,
handler: self.didSelectManageAliasesAction(actionName:)
)
actions.append(manageAliases)
}

let cancel = UIAlertAction(title: Text.cancel.text, style: .cancel) { _ in }
let cancel = UIAlertAction(title: Localized.cancel.text, style: .cancel) { _ in }
actions.append(cancel)

AppController.shared.choose(from: actions, sourceView: sender)
Expand Down Expand Up @@ -371,7 +371,7 @@ class AboutViewController: ContentViewController {

var actions = [UIAlertAction]()

let sharePublicIdentifier = UIAlertAction(title: Text.sharePublicIdentifier.text, style: .default) { _ in
let sharePublicIdentifier = UIAlertAction(title: Localized.sharePublicIdentifier.text, style: .default) { _ in
Analytics.shared.trackDidSelectAction(actionName: "share_public_identifier")

let activityController = UIActivityViewController(
Expand All @@ -384,11 +384,11 @@ class AboutViewController: ContentViewController {
actions.append(sharePublicIdentifier)

if let publicLink = self.identity.publicLink {
let sharePublicLink = UIAlertAction(title: Text.shareThisProfile.text, style: .default) { _ in
let sharePublicLink = UIAlertAction(title: Localized.shareThisProfile.text, style: .default) { _ in
Analytics.shared.trackDidSelectAction(actionName: "share_profile")

let nameOrIdentity = self.about?.name ?? self.identity
let text = Text.shareThisProfileText.text([
let text = Localized.shareThisProfileText.text([
"who": nameOrIdentity,
"link": publicLink.absoluteString
])
Expand All @@ -403,7 +403,7 @@ class AboutViewController: ContentViewController {
actions.append(sharePublicLink)
}

let cancel = UIAlertAction(title: Text.cancel.text, style: .cancel) { _ in }
let cancel = UIAlertAction(title: Localized.cancel.text, style: .cancel) { _ in }
actions.append(cancel)

AppController.shared.choose(from: actions, sourceView: sender)
Expand Down Expand Up @@ -435,9 +435,9 @@ class AboutViewController: ContentViewController {
let newTicketVC = Support.shared.newTicketViewController(reporter: currentIdentity, profile: profile)
guard let controller = newTicketVC else {
AppController.shared.alert(
title: Text.error.text,
message: Text.Error.supportNotConfigured.text,
cancelTitle: Text.ok.text
title: Localized.error.text,
message: Localized.Error.supportNotConfigured.text,
cancelTitle: Localized.ok.text
)
return
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Controller/BlockedUsersViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class BlockedUsersViewController: ContentViewController, AboutTableViewDelegate
// MARK: Lifecycle

init() {
super.init(scrollable: false, dynamicTitle: Text.Blocking.blockedUsers.text)
super.init(scrollable: false, dynamicTitle: Localized.Blocking.blockedUsers.text)
}

required init?(coder aDecoder: NSCoder) {
Expand Down
2 changes: 1 addition & 1 deletion Source/Controller/ChannelsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ extension ChannelsViewController: UITableViewDataSource {
cell.selectionStyle = .none
cell.backgroundColor = .cardBackground

let postText = (hashtag.count == 1) ? Text.Post.one.text : Text.Post.many.text
let postText = (hashtag.count == 1) ? Localized.Post.one.text : Localized.Post.many.text

cell.detailTextLabel?.text = "\(hashtag.count) \(postText)"

Expand Down
2 changes: 1 addition & 1 deletion Source/Controller/ConnectedPeerListCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ enum ConnectedPeerListError: LocalizedError {
var errorDescription: String? {
switch self {
case .identityNotFound:
return Text.identityNotFound.text
return Localized.identityNotFound.text
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Controller/ContactsViewControllers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ContactsViewController: ContentViewController, AboutTableViewDelegate {
return view
}()

init(title: Text, identity: Identity, identities: [Identity] = []) {
init(title: Localized, identity: Identity, identities: [Identity] = []) {
self.identity = identity
self.dataSource = AboutTableViewDataSource(identities: identities)
super.init(scrollable: false, dynamicTitle: title.text(["count": "\(identities.count)"]))
Expand Down
4 changes: 2 additions & 2 deletions Source/Controller/ContentViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ContentViewController: UIViewController, KeyboardHandling {

// `dynamicTitle` is used to provide a string at runtime instead of the strongly-typed `title` Text object.
// it will not be used if `title` is also provided
init(scrollable: Bool = true, title: Text? = nil, dynamicTitle: String? = nil) {
init(scrollable: Bool = true, title: Localized? = nil, dynamicTitle: String? = nil) {
self.scrollable = scrollable
super.init(nibName: nil, bundle: nil)
self.title = title?.text ?? dynamicTitle
Expand Down Expand Up @@ -204,7 +204,7 @@ class ContentViewController: UIViewController, KeyboardHandling {
let view = UILabel.forAutoLayout()
view.textAlignment = .center
view.numberOfLines = 2
view.text = Text.loadingUpdates.text
view.text = Localized.loadingUpdates.text
view.textColor = UIColor.tint.default
return view
}()
Expand Down
16 changes: 8 additions & 8 deletions Source/Controller/DirectoryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class DirectoryViewController: ContentViewController, AboutTableViewDelegate, He
controller.searchResultsUpdater = self
controller.searchBar.delegate = self
controller.searchBar.isTranslucent = false
controller.searchBar.placeholder = Text.searchForUsers.text
controller.searchBar.placeholder = Localized.searchForUsers.text
controller.obscuresBackgroundDuringPresentation = false
controller.hidesNavigationBarDuringPresentation = false
return controller
Expand Down Expand Up @@ -173,7 +173,7 @@ class DirectoryViewController: ContentViewController, AboutTableViewDelegate, He

/// Loads the message with the given id from the database and displays it if it's still valid.
func loadAndDisplayMessage(with msgID: MessageIdentifier) {
AppController.shared.showProgress(after: 0.3, statusText: Text.searching.text)
AppController.shared.showProgress(after: 0.3, statusText: Localized.searching.text)
Task.detached(priority: .high) { [weak self] in
var result: Either<Message, MessageIdentifier>
do {
Expand Down Expand Up @@ -254,13 +254,13 @@ extension DirectoryViewController: UITableViewDataSource {

switch section {
case .communityPubs:
return Text.pubServers.text
return Localized.pubServers.text
case .users:
return Text.users.text
return Localized.users.text
case .posts:
return Text.posts.text
return Localized.posts.text
case .network:
return Text.usersInYourNetwork.text
return Localized.usersInYourNetwork.text
}
}

Expand Down Expand Up @@ -300,10 +300,10 @@ extension DirectoryViewController: UITableViewDataSource {
let cell = UITableViewCell(style: .default, reuseIdentifier: nil)

if let post = searchedPost {
cell.textLabel?.text = Text.openPost.text(["postID": post.key])
cell.textLabel?.text = Localized.openPost.text(["postID": post.key])
cell.textLabel?.textColor = UIColor.tint.default
} else {
cell.textLabel?.text = Text.postNotFound.text
cell.textLabel?.text = Localized.postNotFound.text
}

return cell
Expand Down
Loading