From b6d7655b6d6fefcfdc09d927b9cae7bcc0884522 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sat, 13 Apr 2019 18:42:34 +0200 Subject: [PATCH] Add translations to Credits --- .../Scenes/About/CreditsViewController.swift | 33 ++++++++++++++++++- .../Resources/en.lproj/Localizable.strings | 1 + Passepartout/Sources/AppConstants.swift | 4 +++ Passepartout/Sources/SwiftGen+Strings.swift | 4 +++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/Passepartout-iOS/Scenes/About/CreditsViewController.swift b/Passepartout-iOS/Scenes/About/CreditsViewController.swift index 6de0b359..393a9e88 100644 --- a/Passepartout-iOS/Scenes/About/CreditsViewController.swift +++ b/Passepartout-iOS/Scenes/About/CreditsViewController.swift @@ -30,7 +30,11 @@ class CreditsViewController: UITableViewController, TableModelHost { private let licenses = AppConstants.License.all private let notices = AppConstants.Notice.all - + + private let languages = AppConstants.Translations.authorByLanguage.keys.sorted { + return Utils.localizedCountry($0) < Utils.localizedCountry($1) + } + // MARK: TableModelHost var model: TableModel = TableModel() @@ -38,12 +42,15 @@ class CreditsViewController: UITableViewController, TableModelHost { func reloadModel() { model.add(.licenses) model.add(.notices) + model.add(.translations) model.setHeader(L10n.Credits.Sections.Licenses.header, for: .licenses) model.setHeader(L10n.Credits.Sections.Notices.header, for: .notices) + model.setHeader(L10n.Credits.Sections.Translations.header, for: .translations) model.set(.license, count: licenses.count, in: .licenses) model.set(.notice, count: notices.count, in: .notices) + model.set(.translation, count: languages.count, in: .translations) } // MARK: UIViewController @@ -54,6 +61,13 @@ class CreditsViewController: UITableViewController, TableModelHost { title = L10n.Credits.title reloadModel() } + + override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool { + guard let cell = sender as? SettingTableViewCell, let indexPath = tableView.indexPath(for: cell) else { + return false + } + return model.row(at: indexPath) != .translation + } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { guard let vc = segue.destination as? LabelViewController else { @@ -69,6 +83,9 @@ class CreditsViewController: UITableViewController, TableModelHost { case .notice: vc.text = notices[indexPath.row].statement + + default: + break } } } @@ -78,12 +95,16 @@ extension CreditsViewController { case licenses case notices + + case translations } enum RowType: Int { case license case notice + + case translation } override func numberOfSections(in tableView: UITableView) -> Int { @@ -110,6 +131,16 @@ extension CreditsViewController { let obj = notices[indexPath.row] cell.leftText = obj.name cell.rightText = nil + + case .translation: + let lang = languages[indexPath.row] + guard let author = AppConstants.Translations.authorByLanguage[lang] else { + fatalError("Author not found for language \(lang)") + } + cell.leftText = Utils.localizedCountry(lang) + cell.rightText = author + cell.accessoryType = .none + cell.isTappable = false } return cell } diff --git a/Passepartout/Resources/en.lproj/Localizable.strings b/Passepartout/Resources/en.lproj/Localizable.strings index be413f33..bbfd45d0 100644 --- a/Passepartout/Resources/en.lproj/Localizable.strings +++ b/Passepartout/Resources/en.lproj/Localizable.strings @@ -274,5 +274,6 @@ "credits.title" = "Credits"; "credits.sections.licenses.header" = "Licenses"; "credits.sections.notices.header" = "Notices"; +"credits.sections.translations.header" = "Translations"; "label.license.error" = "Unable to download full license content."; diff --git a/Passepartout/Sources/AppConstants.swift b/Passepartout/Sources/AppConstants.swift index 54a5e6dd..2e68f23f 100644 --- a/Passepartout/Sources/AppConstants.swift +++ b/Passepartout/Sources/AppConstants.swift @@ -153,6 +153,10 @@ public class AppConstants { public static let template = "I offer to translate to: " } + + public static let authorByLanguage: [String: String] = [ + "it": "Davide De Rosa" + ] } public class URLs { diff --git a/Passepartout/Sources/SwiftGen+Strings.swift b/Passepartout/Sources/SwiftGen+Strings.swift index b97ee4a3..c46d1964 100644 --- a/Passepartout/Sources/SwiftGen+Strings.swift +++ b/Passepartout/Sources/SwiftGen+Strings.swift @@ -287,6 +287,10 @@ public enum L10n { /// Notices public static let header = L10n.tr("Localizable", "credits.sections.notices.header") } + public enum Translations { + /// Translations + public static let header = L10n.tr("Localizable", "credits.sections.translations.header") + } } }