diff --git a/Ring/Ring/Account/CreateRingAccountViewModel.swift b/Ring/Ring/Account/CreateRingAccountViewModel.swift index 7dbd1921c148e4f2e40375c0af27b155ef36e61d..8667557525e9e3f8e99ac23893f9637155f35dca 100644 --- a/Ring/Ring/Account/CreateRingAccountViewModel.swift +++ b/Ring/Ring/Account/CreateRingAccountViewModel.swift @@ -140,11 +140,11 @@ class CreateRingAccountViewModel { .asObservable().map ({ status in switch status { case .lookingUp: - return L10n.Createaccount.lookingForUsernameAvailability.smartString + return L10n.Createaccount.lookingForUsernameAvailability case .invalid: - return L10n.Createaccount.invalidUsername.smartString + return L10n.Createaccount.invalidUsername case .alreadyTaken: - return L10n.Createaccount.usernameAlreadyTaken.smartString + return L10n.Createaccount.usernameAlreadyTaken default: return "" } @@ -232,22 +232,22 @@ extension AccountCreationError: LocalizedError { var title: String { switch self { case .generic: - return L10n.Alerts.accountCannotBeFoundTitle.smartString + return L10n.Alerts.accountCannotBeFoundTitle case .network: - return L10n.Alerts.accountNoNetworkTitle.smartString + return L10n.Alerts.accountNoNetworkTitle default: - return L10n.Alerts.accountDefaultErrorTitle.smartString + return L10n.Alerts.accountDefaultErrorTitle } } var message: String { switch self { case .generic: - return L10n.Alerts.accountDefaultErrorMessage.smartString + return L10n.Alerts.accountDefaultErrorMessage case .network: - return L10n.Alerts.accountNoNetworkMessage.smartString + return L10n.Alerts.accountNoNetworkMessage default: - return L10n.Alerts.accountDefaultErrorMessage.smartString + return L10n.Alerts.accountDefaultErrorMessage } } } diff --git a/Ring/Ring/Constants/Generated/Images.swift b/Ring/Ring/Constants/Generated/Images.swift index 1203345adaaa1c4448fe7a871f2aad805b633049..8778bbb5fa672ecbf3b9e03dbce62b552d8e13c7 100644 --- a/Ring/Ring/Constants/Generated/Images.swift +++ b/Ring/Ring/Constants/Generated/Images.swift @@ -1,47 +1,94 @@ -// Generated using SwiftGen, by O.Halligon — https://github.com/AliSoftware/SwiftGen +// Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen -#if os(iOS) || os(tvOS) || os(watchOS) - import UIKit.UIImage - public typealias Image = UIImage -#elseif os(OSX) +#if os(OSX) import AppKit.NSImage - public typealias Image = NSImage + typealias AssetColorTypeAlias = NSColor + typealias Image = NSImage +#elseif os(iOS) || os(tvOS) || os(watchOS) + import UIKit.UIImage + typealias AssetColorTypeAlias = UIColor + typealias Image = UIImage #endif -private class RingImagesBundleToken {} - // swiftlint:disable file_length -// swiftlint:disable line_length - -// swiftlint:disable type_body_length -public enum RingAsset: String { - case icContactPicture = "ic_contact_picture" - case logoRingBeta2Blanc = "logo-ring-beta2-blanc" - - /** - Loads from application's Bundle if image exists, then loads from current bundle, fatalError if image does not exist - */ - public var smartImage: Image { - if let appimage = Image(named: self.rawValue, in: nil, compatibleWith: nil) { - return appimage - } else if let fmkImage = Image(named: self.rawValue, in: Bundle(for: RingImagesBundleToken.self), compatibleWith: nil) { - return fmkImage - } else { - fatalError("Impossible to load image \(self.rawValue)") - } - } + +@available(*, deprecated, renamed: "ImageAsset") +typealias AssetType = ImageAsset + +struct ImageAsset { + fileprivate var name: String var image: Image { - if let img = Image(named: self.rawValue, in: Bundle(for: RingImagesBundleToken.self), compatibleWith: nil) { - return img - } - fatalError("Impossible to load image \(self.rawValue)") + let bundle = Bundle(for: BundleToken.self) + #if os(iOS) || os(tvOS) + let image = Image(named: name, in: bundle, compatibleWith: nil) + #elseif os(OSX) + let image = bundle.image(forResource: name) + #elseif os(watchOS) + let image = Image(named: name) + #endif + guard let result = image else { fatalError("Unable to load image named \(name).") } + return result } } -// swiftlint:enable type_body_length -public extension Image { - convenience init!(asset: RingAsset) { - self.init(named: asset.rawValue) +struct ColorAsset { + fileprivate var name: String + + #if swift(>=3.2) + @available(iOS 11.0, tvOS 11.0, watchOS 4.0, OSX 10.13, *) + var color: AssetColorTypeAlias { + return AssetColorTypeAlias(asset: self) } + #endif } + +// swiftlint:disable identifier_name line_length nesting type_body_length type_name +enum Asset { + static let icContactPicture = ImageAsset(name: "ic_contact_picture") + static let logoRingBeta2Blanc = ImageAsset(name: "logo-ring-beta2-blanc") + + // swiftlint:disable trailing_comma + static let allColors: [ColorAsset] = [ + ] + static let allImages: [ImageAsset] = [ + icContactPicture, + logoRingBeta2Blanc, + ] + // swiftlint:enable trailing_comma + @available(*, deprecated, renamed: "allImages") + static let allValues: [AssetType] = allImages +} +// swiftlint:enable identifier_name line_length nesting type_body_length type_name + +extension Image { + @available(iOS 1.0, tvOS 1.0, watchOS 1.0, *) + @available(OSX, deprecated, + message: "This initializer is unsafe on macOS, please use the ImageAsset.image property") + convenience init!(asset: ImageAsset) { + #if os(iOS) || os(tvOS) + let bundle = Bundle(for: BundleToken.self) + self.init(named: asset.name, in: bundle, compatibleWith: nil) + #elseif os(OSX) || os(watchOS) + self.init(named: asset.name) + #endif + } +} + +extension AssetColorTypeAlias { + #if swift(>=3.2) + @available(iOS 11.0, tvOS 11.0, watchOS 4.0, OSX 10.13, *) + convenience init!(asset: ColorAsset) { + let bundle = Bundle(for: BundleToken.self) + #if os(iOS) || os(tvOS) + self.init(named: asset.name, in: bundle, compatibleWith: nil) + #elseif os(OSX) + self.init(named: asset.name, bundle: bundle) + #elseif os(watchOS) + self.init(named: asset.name) + #endif + } + #endif +} + +private final class BundleToken {} diff --git a/Ring/Ring/Constants/Generated/Storyboards.swift b/Ring/Ring/Constants/Generated/Storyboards.swift index 1dedc6f11b68d0747d806c93d09b7f78afbec83c..b8449a5adf4ddad0b8b02670b7aac9ce7a279e58 100644 --- a/Ring/Ring/Constants/Generated/Storyboards.swift +++ b/Ring/Ring/Constants/Generated/Storyboards.swift @@ -1,87 +1,79 @@ // Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen +// swiftlint:disable sorted_imports import Foundation import UIKit // swiftlint:disable file_length -// swiftlint:disable line_length -// swiftlint:disable type_body_length -protocol StoryboardSceneType { +protocol StoryboardType { static var storyboardName: String { get } } -extension StoryboardSceneType { - static func storyboard() -> UIStoryboard { +extension StoryboardType { + static var storyboard: UIStoryboard { return UIStoryboard(name: self.storyboardName, bundle: Bundle(for: BundleToken.self)) } +} + +struct SceneType<T: Any> { + let storyboard: StoryboardType.Type + let identifier: String - static func initialViewController() -> UIViewController { - guard let vc = storyboard().instantiateInitialViewController() else { - fatalError("Failed to instantiate initialViewController for \(self.storyboardName)") + func instantiate() -> T { + guard let controller = storyboard.storyboard.instantiateViewController(withIdentifier: identifier) as? T else { + fatalError("ViewController '\(identifier)' is not of the expected class \(T.self).") } - return vc + return controller } } -extension StoryboardSceneType where Self: RawRepresentable, Self.RawValue == String { - func viewController() -> UIViewController { - return Self.storyboard().instantiateViewController(withIdentifier: self.rawValue) - } - static func viewController(identifier: Self) -> UIViewController { - return identifier.viewController() +struct InitialSceneType<T: Any> { + let storyboard: StoryboardType.Type + + func instantiate() -> T { + guard let controller = storyboard.storyboard.instantiateInitialViewController() as? T else { + fatalError("ViewController is not of the expected class \(T.self).") + } + return controller } } -protocol StoryboardSegueType: RawRepresentable { } +protocol SegueType: RawRepresentable { } extension UIViewController { - func perform<S: StoryboardSegueType>(segue: S, sender: Any? = nil) where S.RawValue == String { + func perform<S: SegueType>(segue: S, sender: Any? = nil) where S.RawValue == String { performSegue(withIdentifier: segue.rawValue, sender: sender) } } +// swiftlint:disable explicit_type_interface identifier_name line_length type_body_length type_name enum StoryboardScene { - enum LaunchScreen: StoryboardSceneType { + enum LaunchScreen: StoryboardType { static let storyboardName = "LaunchScreen" + + static let initialScene = InitialSceneType<UIViewController>(storyboard: LaunchScreen.self) } - enum Main: String, StoryboardSceneType { + enum Main: StoryboardType { static let storyboardName = "Main" - static func initialViewController() -> Ring.MainTabBarViewController { - guard let vc = storyboard().instantiateInitialViewController() as? Ring.MainTabBarViewController else { - fatalError("Failed to instantiate initialViewController for \(self.storyboardName)") - } - return vc - } + static let initialScene = InitialSceneType<Ring.MainTabBarViewController>(storyboard: Main.self) - case mainStoryboardScene = "MainStoryboard" - static func instantiateMainStoryboard() -> Ring.MainTabBarViewController { - guard let vc = StoryboardScene.Main.mainStoryboardScene.viewController() as? Ring.MainTabBarViewController - else { - fatalError("ViewController 'MainStoryboard' is not of the expected class Ring.MainTabBarViewController.") - } - return vc - } + static let mainStoryboard = SceneType<Ring.MainTabBarViewController>(storyboard: Main.self, identifier: "MainStoryboard") } - enum WalkthroughStoryboard: StoryboardSceneType { + enum WalkthroughStoryboard: StoryboardType { static let storyboardName = "WalkthroughStoryboard" - static func initialViewController() -> UINavigationController { - guard let vc = storyboard().instantiateInitialViewController() as? UINavigationController else { - fatalError("Failed to instantiate initialViewController for \(self.storyboardName)") - } - return vc - } + static let initialScene = InitialSceneType<UINavigationController>(storyboard: WalkthroughStoryboard.self) } } enum StoryboardSegue { - enum Main: String, StoryboardSegueType { + enum Main: String, SegueType { case showMessages = "ShowMessages" case accountDetails } - enum WalkthroughStoryboard: String, StoryboardSegueType { + enum WalkthroughStoryboard: String, SegueType { case accountToPermissionsSegue = "AccountToPermissionsSegue" case createProfileSegue = "CreateProfileSegue" case linkDeviceToAccountSegue = "LinkDeviceToAccountSegue" @@ -89,5 +81,6 @@ enum StoryboardSegue { case profileToLinkSegue = "ProfileToLinkSegue" } } +// swiftlint:enable explicit_type_interface identifier_name line_length type_body_length type_name private final class BundleToken {} diff --git a/Ring/Ring/Constants/Generated/Strings.swift b/Ring/Ring/Constants/Generated/Strings.swift index 1baf6ed7ed3e7eaa6d57fa76a9e0c914231fde60..459e574236f56d57be1bc6df6c929a26ef51e2f9 100644 --- a/Ring/Ring/Constants/Generated/Strings.swift +++ b/Ring/Ring/Constants/Generated/Strings.swift @@ -1,134 +1,98 @@ -// Generated using SwiftGen, by O.Halligon — https://github.com/AliSoftware/SwiftGen +// Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen import Foundation -private class RingStringsBundleToken {} - // swiftlint:disable file_length -// swiftlint:disable line_length - -// swiftlint:disable type_body_length -// swiftlint:disable nesting -// swiftlint:disable variable_name -// swiftlint:disable valid_docs +// swiftlint:disable explicit_type_interface identifier_name line_length nesting type_body_length type_name enum L10n { enum Alerts { /// Account Added - static let accountAddedTitle = L10n.tr("alerts.accountAddedTitle") + static let accountAddedTitle = L10n.tr("Localizable", "alerts.accountAddedTitle") /// Can't find account - static let accountCannotBeFoundTitle = L10n.tr("alerts.accountCannotBeFoundTitle") + static let accountCannotBeFoundTitle = L10n.tr("Localizable", "alerts.accountCannotBeFoundTitle") /// The account couldn't be created. - static let accountDefaultErrorMessage = L10n.tr("alerts.accountDefaultErrorMessage") + static let accountDefaultErrorMessage = L10n.tr("Localizable", "alerts.accountDefaultErrorMessage") /// Unknown error - static let accountDefaultErrorTitle = L10n.tr("alerts.accountDefaultErrorTitle") + static let accountDefaultErrorTitle = L10n.tr("Localizable", "alerts.accountDefaultErrorTitle") /// Could not add account because Ring couldn't connect to the distributed network. Check your device connectivity. - static let accountNoNetworkMessage = L10n.tr("alerts.accountNoNetworkMessage") + static let accountNoNetworkMessage = L10n.tr("Localizable", "alerts.accountNoNetworkMessage") /// Can't connect to the network - static let accountNoNetworkTitle = L10n.tr("alerts.accountNoNetworkTitle") + static let accountNoNetworkTitle = L10n.tr("Localizable", "alerts.accountNoNetworkTitle") /// Account couldn't be found on the Ring network. Make sure it was exported on Ring from an existing device, and that provided credentials are correct. - static let acountCannotBeFoundMessage = L10n.tr("alerts.acountCannotBeFoundMessage") + static let acountCannotBeFoundMessage = L10n.tr("Localizable", "alerts.acountCannotBeFoundMessage") } enum Createaccount { /// Choose strong password you will remember to protect your Ring account. - static let chooseStrongPassword = L10n.tr("createAccount.chooseStrongPassword") + static let chooseStrongPassword = L10n.tr("Localizable", "createAccount.chooseStrongPassword") /// Create your Ring account - static let createAccountFormTitle = L10n.tr("createAccount.createAccountFormTitle") + static let createAccountFormTitle = L10n.tr("Localizable", "createAccount.createAccountFormTitle") /// Enter new username - static let enterNewUsernamePlaceholder = L10n.tr("createAccount.enterNewUsernamePlaceholder") + static let enterNewUsernamePlaceholder = L10n.tr("Localizable", "createAccount.enterNewUsernamePlaceholder") /// Invalid username - static let invalidUsername = L10n.tr("createAccount.invalidUsername") + static let invalidUsername = L10n.tr("Localizable", "createAccount.invalidUsername") /// Loading... - static let loading = L10n.tr("createAccount.loading") + static let loading = L10n.tr("Localizable", "createAccount.loading") /// Looking for username availability... - static let lookingForUsernameAvailability = L10n.tr("createAccount.lookingForUsernameAvailability") + static let lookingForUsernameAvailability = L10n.tr("Localizable", "createAccount.lookingForUsernameAvailability") /// New Password - static let newPasswordPlaceholder = L10n.tr("createAccount.newPasswordPlaceholder") + static let newPasswordPlaceholder = L10n.tr("Localizable", "createAccount.newPasswordPlaceholder") /// 6 characters minimum - static let passwordCharactersNumberError = L10n.tr("createAccount.passwordCharactersNumberError") + static let passwordCharactersNumberError = L10n.tr("Localizable", "createAccount.passwordCharactersNumberError") /// Passwords do not match - static let passwordNotMatchingError = L10n.tr("createAccount.passwordNotMatchingError") + static let passwordNotMatchingError = L10n.tr("Localizable", "createAccount.passwordNotMatchingError") /// Register public username (experimental) - static let registerPublicUsername = L10n.tr("createAccount.registerPublicUsername") + static let registerPublicUsername = L10n.tr("Localizable", "createAccount.registerPublicUsername") /// Repeat new password - static let repeatPasswordPlaceholder = L10n.tr("createAccount.repeatPasswordPlaceholder") + static let repeatPasswordPlaceholder = L10n.tr("Localizable", "createAccount.repeatPasswordPlaceholder") /// Username already taken - static let usernameAlreadyTaken = L10n.tr("createAccount.usernameAlreadyTaken") + static let usernameAlreadyTaken = L10n.tr("Localizable", "createAccount.usernameAlreadyTaken") /// Adding account - static let waitCreateAccountTitle = L10n.tr("createAccount.waitCreateAccountTitle") + static let waitCreateAccountTitle = L10n.tr("Localizable", "createAccount.waitCreateAccountTitle") } enum Global { /// Home - static let homeTabBarTitle = L10n.tr("global.homeTabBarTitle") + static let homeTabBarTitle = L10n.tr("Localizable", "global.homeTabBarTitle") /// Me - static let meTabBarTitle = L10n.tr("global.meTabBarTitle") + static let meTabBarTitle = L10n.tr("Localizable", "global.meTabBarTitle") /// Ok - static let ok = L10n.tr("global.ok") + static let ok = L10n.tr("Localizable", "global.ok") } enum Smartlist { /// Conversations - static let conversations = L10n.tr("smartlist.conversations") + static let conversations = L10n.tr("Localizable", "smartlist.conversations") /// No results - static let noResults = L10n.tr("smartlist.noResults") + static let noResults = L10n.tr("Localizable", "smartlist.noResults") /// Searching... - static let searching = L10n.tr("smartlist.searching") + static let searching = L10n.tr("Localizable", "smartlist.searching") /// User found - static let userFound = L10n.tr("smartlist.userFound") + static let userFound = L10n.tr("Localizable", "smartlist.userFound") /// Yesterday - static let yesterday = L10n.tr("smartlist.yesterday") + static let yesterday = L10n.tr("Localizable", "smartlist.yesterday") } enum Welcome { /// Create a Ring account - static let createAccount = L10n.tr("welcome.createAccount") + static let createAccount = L10n.tr("Localizable", "welcome.createAccount") /// Link this device to an account - static let linkDeviceButton = L10n.tr("welcome.linkDeviceButton") + static let linkDeviceButton = L10n.tr("Localizable", "welcome.linkDeviceButton") /// A Ring account allows you to reach people securely in peer to peer through fully distributed network - static let text = L10n.tr("welcome.text") + static let text = L10n.tr("Localizable", "welcome.text") /// Welcome to Ring - static let title = L10n.tr("welcome.title") + static let title = L10n.tr("Localizable", "welcome.title") } } - - struct LocalizableString { - let key: String - let args: [CVarArg] - - /** - Returns String from Current Bundle - */ - public var string: String { - let format: String = NSLocalizedString(key, tableName: nil, bundle: Bundle(for: RingStringsBundleToken.self), value: "", comment: "") - return String(format: format, locale: Locale.current, arguments: args) - } - - /** - Returns String translated from App's Bundle is found, otherwise from Current Bundle - */ - public var smartString: String { - // Load from App's Bundle first - var format: String = NSLocalizedString(key, tableName: nil, bundle: Bundle.main, value: "", comment: "") - if format != "" && format != key { - return String(format: format, locale: Locale.current, arguments: args) - } - // Load from Current Bundle - format = NSLocalizedString(key, tableName: nil, bundle: Bundle(for: RingStringsBundleToken.self), value: "", comment: "") - - return String(format: format, locale: Locale.current, arguments: args) - } - } +// swiftlint:enable explicit_type_interface identifier_name line_length nesting type_body_length type_name extension L10n { - fileprivate static func tr(_ key: String, _ args: CVarArg...) -> LocalizableString { - return LocalizableString(key: key, args: args) + fileprivate static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String { + let format = NSLocalizedString(key, tableName: table, bundle: Bundle(for: BundleToken.self), comment: "") + return String(format: format, locale: Locale.current, arguments: args) } } -// swiftlint:enable type_body_length -// swiftlint:enable nesting -// swiftlint:enable variable_name -// swiftlint:enable valid_docs +private final class BundleToken {} diff --git a/Ring/Ring/Conversations/ConversationViewModel.swift b/Ring/Ring/Conversations/ConversationViewModel.swift index ae4bc628c6a1c31d4a4ecd99a17994b46836a087..30eddb749ec3452fe7fb90da1549366b4da8d5d3 100644 --- a/Ring/Ring/Conversations/ConversationViewModel.swift +++ b/Ring/Ring/Conversations/ConversationViewModel.swift @@ -138,7 +138,7 @@ class ConversationViewModel { if todayDay == day && todayMonth == month && todayYear == year { return hourFormatter.string(from: lastMessageDate) } else if day == todayDay - 1 { - return L10n.Smartlist.yesterday.smartString + return L10n.Smartlist.yesterday } else if todayYear == year && todayWeekOfYear == weekOfYear { return lastMessageDate.dayOfWeek() } else { diff --git a/Ring/Ring/Settings/MeViewController.swift b/Ring/Ring/Settings/MeViewController.swift index 8c80ae36bd3a24dcc0dd67e746f1fdda5aab9d2a..ae4c4df2d97755871578a130fac2ea085747fce1 100644 --- a/Ring/Ring/Settings/MeViewController.swift +++ b/Ring/Ring/Settings/MeViewController.swift @@ -32,8 +32,8 @@ class MeViewController: UIViewController, UITableViewDelegate, UITableViewDataSo override func viewDidLoad() { super.viewDidLoad() - self.title = L10n.Global.meTabBarTitle.smartString - self.navigationItem.title = L10n.Global.meTabBarTitle.smartString + self.title = L10n.Global.meTabBarTitle + self.navigationItem.title = L10n.Global.meTabBarTitle if !accountService.accounts.isEmpty { // let acc = accountService.accounts[0] diff --git a/Ring/Ring/Smartlist/SmartlistViewController.swift b/Ring/Ring/Smartlist/SmartlistViewController.swift index fc3d1fc62f9ad993407fe598b165d6ac7ea2675d..b881e7d5bd78e9d6eeda043dfa92e90e00379f27 100644 --- a/Ring/Ring/Smartlist/SmartlistViewController.swift +++ b/Ring/Ring/Smartlist/SmartlistViewController.swift @@ -70,8 +70,8 @@ class SmartlistViewController: UIViewController { func setupUI() { - self.title = L10n.Global.homeTabBarTitle.smartString - self.navigationItem.title = L10n.Global.homeTabBarTitle.smartString + self.title = L10n.Global.homeTabBarTitle + self.navigationItem.title = L10n.Global.homeTabBarTitle self.viewModel.hideNoConversationsMessage .bind(to: self.noConversationsView.rx.isHidden) diff --git a/Ring/Ring/Smartlist/SmartlistViewModel.swift b/Ring/Ring/Smartlist/SmartlistViewModel.swift index cf936d8751319bd3305501ad6d344c513bf9de27..190604f169aae0a8ae975dfc07941ebab93d5f83 100644 --- a/Ring/Ring/Smartlist/SmartlistViewModel.swift +++ b/Ring/Ring/Smartlist/SmartlistViewModel.swift @@ -88,11 +88,11 @@ class SmartlistViewModel { var sections = [ConversationSection]() if contactFoundConversation != nil { - sections.append(ConversationSection(header: L10n.Smartlist.userFound.smartString, items: [contactFoundConversation!])) + sections.append(ConversationSection(header: L10n.Smartlist.userFound, items: [contactFoundConversation!])) } if !filteredResults.isEmpty { - sections.append(ConversationSection(header: L10n.Smartlist.conversations.smartString, items: filteredResults)) + sections.append(ConversationSection(header: L10n.Smartlist.conversations, items: filteredResults)) } return sections @@ -133,7 +133,7 @@ class SmartlistViewModel { self.searchStatus.onNext("") } else { if self.filteredResults.value.isEmpty { - self.searchStatus.onNext(L10n.Smartlist.noResults.smartString) + self.searchStatus.onNext(L10n.Smartlist.noResults) } else { self.searchStatus.onNext("") } @@ -166,7 +166,7 @@ class SmartlistViewModel { } self.nameService.lookupName(withAccount: "", nameserver: "", name: text) - self.searchStatus.onNext(L10n.Smartlist.searching.smartString) + self.searchStatus.onNext(L10n.Smartlist.searching) } } diff --git a/Ring/Ring/Walkthrough/CreateRingAccountViewController.swift b/Ring/Ring/Walkthrough/CreateRingAccountViewController.swift index a67e13d1f0e275dcb6ae27034e7dcb9884316db1..4430f5d5e2d84afeb0aae406f9910d59fb0abbac 100644 --- a/Ring/Ring/Walkthrough/CreateRingAccountViewController.swift +++ b/Ring/Ring/Walkthrough/CreateRingAccountViewController.swift @@ -122,31 +122,31 @@ class CreateRingAccountViewController: UITableViewController { fileprivate func setupUI() { self.tableView.estimatedRowHeight = 44.0 self.tableView.rowHeight = UITableViewAutomaticDimension - self.createAccountTitleLabel.text = L10n.Createaccount.createAccountFormTitle.smartString + self.createAccountTitleLabel.text = L10n.Createaccount.createAccountFormTitle } fileprivate func setCreateAccountAsLoading() { log.debug("Creating account...") - self.createAccountButton.setTitle(L10n.Createaccount.loading.smartString, for: .normal) + self.createAccountButton.setTitle(L10n.Createaccount.loading, for: .normal) self.createAccountButton.isUserInteractionEnabled = false - HUD.show(.labeledProgress(title: L10n.Createaccount.waitCreateAccountTitle.smartString, subtitle: nil)) + HUD.show(.labeledProgress(title: L10n.Createaccount.waitCreateAccountTitle, subtitle: nil)) } fileprivate func setCreateAccountAsIdle() { - self.createAccountButton.setTitle(L10n.Welcome.createAccount.smartString, for: .normal) + self.createAccountButton.setTitle(L10n.Welcome.createAccount, for: .normal) self.createAccountButton.isUserInteractionEnabled = true HUD.hide() } fileprivate func showDeviceAddedAlert() { - HUD.flash(.labeledSuccess(title: L10n.Alerts.accountAddedTitle.smartString, subtitle: nil), delay: Durations.alertFlashDuration.value) + HUD.flash(.labeledSuccess(title: L10n.Alerts.accountAddedTitle, subtitle: nil), delay: Durations.alertFlashDuration.value) } fileprivate func showErrorAlert(_ error: AccountCreationError) { let alert = UIAlertController.init(title: error.title, message: error.message, preferredStyle: .alert) - alert.addAction(UIAlertAction.init(title: L10n.Global.ok.smartString, style: .default, handler: nil)) + alert.addAction(UIAlertAction.init(title: L10n.Global.ok, style: .default, handler: nil)) self.present(alert, animated: true, completion: nil) } @@ -191,7 +191,7 @@ class CreateRingAccountViewController: UITableViewController { if currentCellType == .registerPublicUsername { let cell = tableView.dequeueReusableCell(for: indexPath, cellType: SwitchCell.self) - cell.titleLabel.text = L10n.Createaccount.registerPublicUsername.smartString + cell.titleLabel.text = L10n.Createaccount.registerPublicUsername cell.titleLabel.textColor = .white cell.registerSwitch.rx.value.bind(to: self.accountViewModel.registerUsername).disposed(by: disposeBag) return cell @@ -199,7 +199,7 @@ class CreateRingAccountViewController: UITableViewController { let cell = tableView.dequeueReusableCell(for: indexPath, cellType: TextFieldCell.self) cell.textField.isSecureTextEntry = false - cell.textField.placeholder = L10n.Createaccount.enterNewUsernamePlaceholder.smartString + cell.textField.placeholder = L10n.Createaccount.enterNewUsernamePlaceholder //Binds the username field value to the ViewModel cell.textField.rx.text.orEmpty @@ -217,14 +217,14 @@ class CreateRingAccountViewController: UITableViewController { return cell } else if currentCellType == .passwordNotice { let cell = tableView.dequeueReusableCell(for: indexPath, cellType: TextCell.self) - cell.label.text = L10n.Createaccount.chooseStrongPassword.smartString + cell.label.text = L10n.Createaccount.chooseStrongPassword return cell } else if currentCellType == .newPasswordField { let cell = tableView.dequeueReusableCell(for: indexPath, cellType: TextFieldCell.self) cell.textField.isSecureTextEntry = true - cell.textField.placeholder = L10n.Createaccount.newPasswordPlaceholder.smartString - cell.errorMessageLabel.text = L10n.Createaccount.passwordCharactersNumberError.smartString + cell.textField.placeholder = L10n.Createaccount.newPasswordPlaceholder + cell.errorMessageLabel.text = L10n.Createaccount.passwordCharactersNumberError //Binds the password field value to the ViewModel cell.textField.rx.text.orEmpty.bind(to: self.accountViewModel.password).disposed(by: disposeBag) @@ -243,8 +243,8 @@ class CreateRingAccountViewController: UITableViewController { let cell = tableView.dequeueReusableCell(for: indexPath, cellType: TextFieldCell.self) cell.textField.isSecureTextEntry = true - cell.textField.placeholder = L10n.Createaccount.repeatPasswordPlaceholder.smartString - cell.errorMessageLabel.text = L10n.Createaccount.passwordNotMatchingError.smartString + cell.textField.placeholder = L10n.Createaccount.repeatPasswordPlaceholder + cell.errorMessageLabel.text = L10n.Createaccount.passwordNotMatchingError //Binds the repeat password field value to the ViewModel cell.textField.rx.text.orEmpty.bind(to: self.accountViewModel.repeatPassword).disposed(by: disposeBag) diff --git a/Ring/Ring/Walkthrough/WelcomeViewController.swift b/Ring/Ring/Walkthrough/WelcomeViewController.swift index 29892dd40a8b232f039aa12b601402a16c878aa2..0b2f408c37d0c356a0918d68e2991a2e5341b734 100644 --- a/Ring/Ring/Walkthrough/WelcomeViewController.swift +++ b/Ring/Ring/Walkthrough/WelcomeViewController.swift @@ -74,9 +74,9 @@ class WelcomeViewController: UIViewController { func setupUI() { - self.welcomeLabel.text = L10n.Welcome.title.smartString - self.descriptionLabel.text = L10n.Welcome.text.smartString - self.linkDeviceButton.setTitle(L10n.Welcome.linkDeviceButton.smartString, for: .normal) - self.createAccountButton.setTitle(L10n.Welcome.createAccount.smartString, for: .normal) + self.welcomeLabel.text = L10n.Welcome.title + self.descriptionLabel.text = L10n.Welcome.text + self.linkDeviceButton.setTitle(L10n.Welcome.linkDeviceButton, for: .normal) + self.createAccountButton.setTitle(L10n.Welcome.createAccount, for: .normal) } } diff --git a/Ring/swiftgen/images.stencil b/Ring/swiftgen/images.stencil deleted file mode 100644 index fbefe90cd56df50472f793e81b6e80dc9a8256f1..0000000000000000000000000000000000000000 --- a/Ring/swiftgen/images.stencil +++ /dev/null @@ -1,52 +0,0 @@ -// Generated using SwiftGen, by O.Halligon — https://github.com/AliSoftware/SwiftGen - -{% if images %} -#if os(iOS) || os(tvOS) || os(watchOS) - import UIKit.UIImage - public typealias Image = UIImage -#elseif os(OSX) - import AppKit.NSImage - public typealias Image = NSImage -#endif - -private class RingImagesBundleToken {} - -// swiftlint:disable file_length -// swiftlint:disable line_length - -// swiftlint:disable type_body_length -public enum Ring{{enumName}}: String { - {% for image in images %} - case {{image|swiftIdentifier|snakeToCamelCase|lowerFirstWord}} = "{{image}}" - {% endfor %} - - /** - Loads from application's Bundle if image exists, then loads from current bundle, fatalError if image does not exist - */ - public var smartImage: Image { - if let appimage = Image(named: self.rawValue, in: nil, compatibleWith: nil) { - return appimage - } else if let fmkImage = Image(named: self.rawValue, in: Bundle(for: RingImagesBundleToken.self), compatibleWith: nil) { - return fmkImage - } else { - fatalError("Impossible to load image \(self.rawValue)") - } - } - - var image: Image { - if let img = Image(named: self.rawValue, in: Bundle(for: RingImagesBundleToken.self), compatibleWith: nil) { - return img - } - fatalError("Impossible to load image \(self.rawValue)") - } -} -// swiftlint:enable type_body_length - -public extension Image { - convenience init!(asset: Ring{{enumName}}) { - self.init(named: asset.rawValue) - } -} -{% else %} -// No image found -{% endif %} diff --git a/Ring/swiftgen/storyboards.stencil b/Ring/swiftgen/storyboards.stencil deleted file mode 100644 index ad2d2fdcf5ed338b35d8ca4536c4df0e15c8841d..0000000000000000000000000000000000000000 --- a/Ring/swiftgen/storyboards.stencil +++ /dev/null @@ -1,120 +0,0 @@ -// Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen - -{% macro className scene %}{% if scene.customClass %}{% if scene.customModule %}{{scene.customModule}}.{% endif %}{{scene.customClass}}{% else %}UI{{scene.baseType}}{% endif %}{% endmacro %} -import Foundation -import UIKit -{% for module in modules where module != env.PRODUCT_MODULE_NAME and module != param.module %} -import {{module}} -{% endfor %} - -{% if storyboards %} -// swiftlint:disable file_length -// swiftlint:disable line_length -// swiftlint:disable type_body_length - -{# This first part of the code is static, same every time whatever Storyboard you have #} -protocol StoryboardSceneType { - static var storyboardName: String { get } -} - -extension StoryboardSceneType { - static func storyboard() -> UIStoryboard { - return UIStoryboard(name: self.storyboardName, bundle: Bundle(for: BundleToken.self)) - } - - static func initialViewController() -> UIViewController { - guard let vc = storyboard().instantiateInitialViewController() else { - fatalError("Failed to instantiate initialViewController for \(self.storyboardName)") - } - return vc - } -} - -extension StoryboardSceneType where Self: RawRepresentable, Self.RawValue == String { - func viewController() -> UIViewController { - return Self.storyboard().instantiateViewController(withIdentifier: self.rawValue) - } - static func viewController(identifier: Self) -> UIViewController { - return identifier.viewController() - } -} - -protocol StoryboardSegueType: RawRepresentable { } - -extension UIViewController { - func perform<S: StoryboardSegueType>(segue: S, sender: Any? = nil) where S.RawValue == String { - performSegue(withIdentifier: segue.rawValue, sender: sender) - } -} - -{# This is where the generation begins, this code depends on what you have in your Storyboards #} -{% set sceneEnumName %}{{param.sceneEnumName|default:"StoryboardScene"}}{% endset %} -enum {{sceneEnumName}} { - {% for storyboard in storyboards %} - {% set storyboardName %}{{storyboard.name|swiftIdentifier|escapeReservedKeywords}}{% endset %} - {% if storyboard.scenes %} - enum {{storyboardName}}: String, StoryboardSceneType { - static let storyboardName = "{{storyboard.name}}" - {% if storyboard.initialScene and storyboard.initialScene.baseType != "ViewController" %} - {% set initialSceneClass %}{% call className storyboard.initialScene %}{% endset %} - - static func initialViewController() -> {{initialSceneClass}} { - guard let vc = storyboard().instantiateInitialViewController() as? {{initialSceneClass}} else { - fatalError("Failed to instantiate initialViewController for \(self.storyboardName)") - } - return vc - } - {% endif %} - {% for scene in storyboard.scenes %} - {% set sceneID %}{{scene.identifier|swiftIdentifier|snakeToCamelCase|lowerFirstWord}}{% endset %} - - case {{sceneID}}Scene = "{{scene.identifier}}" - {% if scene.baseType != "ViewController" %} - {% set sceneClass %}{% call className scene %}{% endset %} - static func instantiate{{sceneID|snakeToCamelCase}}() -> {{sceneClass}} { - guard let vc = {{sceneEnumName}}.{{storyboardName}}.{{sceneID}}Scene.viewController() as? {{sceneClass}} - else { - fatalError("ViewController '{{scene.identifier}}' is not of the expected class {{sceneClass}}.") - } - return vc - } - {% else %} - static func instantiate{{sceneID|snakeToCamelCase}}() -> UIViewController { - return {{sceneEnumName}}.{{storyboardName}}.{{sceneID}}Scene.viewController() - } - {% endif %} - {% endfor %} - } - {% else %} - enum {{storyboardName}}: StoryboardSceneType { - static let storyboardName = "{{storyboard.name}}" - {% if storyboard.initialScene and storyboard.initialScene.baseType != "ViewController" %} - {% set initialSceneClass %}{% call className storyboard.initialScene %}{% endset %} - - static func initialViewController() -> {{initialSceneClass}} { - guard let vc = storyboard().instantiateInitialViewController() as? {{initialSceneClass}} else { - fatalError("Failed to instantiate initialViewController for \(self.storyboardName)") - } - return vc - } - {% endif %} - } - {% endif %} - {% endfor %} -} - -enum {{param.segueEnumName|default:"StoryboardSegue"}} { - {% for storyboard in storyboards where storyboard.segues %} - enum {{storyboard.name|swiftIdentifier|escapeReservedKeywords}}: String, StoryboardSegueType { - {% for segue in storyboard.segues %} - {% set segueID %}{{segue.identifier|swiftIdentifier|snakeToCamelCase|lowerFirstWord}}{% endset %} - case {{segueID|escapeReservedKeywords}}{% if segueID != segue.identifier %} = "{{segue.identifier}}"{% endif %} - {% endfor %} - } - {% endfor %} -} - -private final class BundleToken {} -{% else %} -// No storyboard found -{% endif %} diff --git a/Ring/swiftgen/strings.stencil b/Ring/swiftgen/strings.stencil deleted file mode 100644 index d7b96e394318a7386704632f763b383160edcd09..0000000000000000000000000000000000000000 --- a/Ring/swiftgen/strings.stencil +++ /dev/null @@ -1,83 +0,0 @@ -// Generated using SwiftGen, by O.Halligon — https://github.com/AliSoftware/SwiftGen - -{% if structuredStrings %} -import Foundation - -private class RingStringsBundleToken {} - -// swiftlint:disable file_length -// swiftlint:disable line_length - -// swiftlint:disable type_body_length -// swiftlint:disable nesting -// swiftlint:disable variable_name -// swiftlint:disable valid_docs -{% macro parametersBlock params %}{% for type in params.types %}_ p{{forloop.counter}}: {{type}}{% if not forloop.last %}, {% endif %}{% endfor %}{% endmacro %} -{% macro argumentsBlock params %}{% for type in params.types %}p{{forloop.counter}}{% if not forloop.last %}, {% endif %}{% endfor %}{% endmacro %} -{% macro recursiveBlock strings sp %} -{{sp}} {% for string in strings.strings %} -{{sp}} /// {{string.translation}} -{{sp}} {% if string.params %} -{{sp}} static func {{string.keytail|swiftIdentifier|snakeToCamelCase|lowerFirstWord|escapeReservedKeywords}}({% call parametersBlock string.params %}) -> LocalizableString { -{{sp}} return {{enumName}}.tr("{{string.key}}", {% call argumentsBlock string.params %}) -{{sp}} } -{{sp}} {% else %} -{{sp}} static let {{string.keytail|swiftIdentifier|snakeToCamelCase|lowerFirstWord|escapeReservedKeywords}} = {{enumName}}.tr("{{string.key}}") -{{sp}} {% endif %} -{{sp}} {% endfor %} -{{sp}} {% if strings.subenums %} -{{sp}} {% for subenum in strings.subenums %} - -{{sp}} enum {{subenum.name|swiftIdentifier|snakeToCamelCase}} { -{{sp}} {% set sp2 %}{{sp}} {% endset %} -{{sp}} {% call recursiveBlock subenum sp2 %} -{{sp}} } -{{sp}} {% endfor %} -{{sp}} {% endif %} -{% endmacro %} - -enum {{enumName}} { - {% call recursiveBlock structuredStrings sp %} -} - - struct LocalizableString { - let key: String - let args: [CVarArg] - - /** - Returns String from Current Bundle - */ - public var string: String { - let format: String = NSLocalizedString(key, tableName: nil, bundle: Bundle(for: RingStringsBundleToken.self), value: "", comment: "") - return String(format: format, locale: Locale.current, arguments: args) - } - - /** - Returns String translated from App's Bundle is found, otherwise from Current Bundle - */ - public var smartString: String { - // Load from App's Bundle first - var format: String = NSLocalizedString(key, tableName: nil, bundle: Bundle.main, value: "", comment: "") - if format != "" && format != key { - return String(format: format, locale: Locale.current, arguments: args) - } - // Load from Current Bundle - format = NSLocalizedString(key, tableName: nil, bundle: Bundle(for: RingStringsBundleToken.self), value: "", comment: "") - - return String(format: format, locale: Locale.current, arguments: args) - } - } - -extension {{enumName}} { - fileprivate static func tr(_ key: String, _ args: CVarArg...) -> LocalizableString { - return LocalizableString(key: key, args: args) - } -} - -// swiftlint:enable type_body_length -// swiftlint:enable nesting -// swiftlint:enable variable_name -// swiftlint:enable valid_docs -{% else %} -// No string found -{% endif %} diff --git a/Ring/swiftgen/swiftgen.sh b/Ring/swiftgen/swiftgen.sh index 0c4da0bc9688c99c8c1436602718b6662a3ca67e..b46576ca401add5d749773dcd236dd9c176d613a 100755 --- a/Ring/swiftgen/swiftgen.sh +++ b/Ring/swiftgen/swiftgen.sh @@ -1,5 +1,5 @@ #!/bin/bash -EXPECTED_VERSION="SwiftGen v4.2.1 (Stencil v0.9.0, StencilSwiftKit v1.0.2, SwiftGenKit v1.1.0)" +EXPECTED_VERSION="SwiftGen v5.1.1 (Stencil v0.9.0, StencilSwiftKit v2.1.0, SwiftGenKit v2.1.0)" # Here execute the various SwiftGen commands you need run_swiftgen() { @@ -9,9 +9,9 @@ run_swiftgen() { TPLDIR=$(dirname $0) echo "SwiftGen: Generating files..." - swiftgen storyboards "$SRCDIR" -p "$TPLDIR/storyboards.stencil" --output "$OUTDIR/Storyboards.swift" - swiftgen images "$SRCDIR/Resources/Images.xcassets" -p "$TPLDIR/images.stencil" --output "$OUTDIR/Images.swift" - swiftgen strings "$SRCDIR/Resources/en.lproj/Localizable.strings" -p "$TPLDIR/strings.stencil" --output "$OUTDIR/Strings.swift" + swiftgen storyboards "$SRCDIR" -t swift3 --output "$OUTDIR/Storyboards.swift" + swiftgen xcassets "$SRCDIR/Resources/Images.xcassets" -t swift3 --output "$OUTDIR/Images.swift" + swiftgen strings -t structured-swift3 "$SRCDIR/Resources/en.lproj/Localizable.strings" --output "$OUTDIR/Strings.swift" }