Merge branch 'credit-translators'
This commit is contained in:
commit
d64df68f8f
|
@ -31,6 +31,10 @@ class CreditsViewController: UITableViewController, TableModelHost {
|
||||||
|
|
||||||
private let notices = AppConstants.Notice.all
|
private let notices = AppConstants.Notice.all
|
||||||
|
|
||||||
|
private let languages = AppConstants.Translations.authorByLanguage.keys.sorted {
|
||||||
|
return Utils.localizedCountry($0) < Utils.localizedCountry($1)
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: TableModelHost
|
// MARK: TableModelHost
|
||||||
|
|
||||||
var model: TableModel<SectionType, RowType> = TableModel()
|
var model: TableModel<SectionType, RowType> = TableModel()
|
||||||
|
@ -38,12 +42,15 @@ class CreditsViewController: UITableViewController, TableModelHost {
|
||||||
func reloadModel() {
|
func reloadModel() {
|
||||||
model.add(.licenses)
|
model.add(.licenses)
|
||||||
model.add(.notices)
|
model.add(.notices)
|
||||||
|
model.add(.translations)
|
||||||
|
|
||||||
model.setHeader(L10n.Credits.Sections.Licenses.header, for: .licenses)
|
model.setHeader(L10n.Credits.Sections.Licenses.header, for: .licenses)
|
||||||
model.setHeader(L10n.Credits.Sections.Notices.header, for: .notices)
|
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(.license, count: licenses.count, in: .licenses)
|
||||||
model.set(.notice, count: notices.count, in: .notices)
|
model.set(.notice, count: notices.count, in: .notices)
|
||||||
|
model.set(.translation, count: languages.count, in: .translations)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: UIViewController
|
// MARK: UIViewController
|
||||||
|
@ -55,6 +62,13 @@ class CreditsViewController: UITableViewController, TableModelHost {
|
||||||
reloadModel()
|
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?) {
|
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
||||||
guard let vc = segue.destination as? LabelViewController else {
|
guard let vc = segue.destination as? LabelViewController else {
|
||||||
return
|
return
|
||||||
|
@ -69,6 +83,9 @@ class CreditsViewController: UITableViewController, TableModelHost {
|
||||||
|
|
||||||
case .notice:
|
case .notice:
|
||||||
vc.text = notices[indexPath.row].statement
|
vc.text = notices[indexPath.row].statement
|
||||||
|
|
||||||
|
default:
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,12 +95,16 @@ extension CreditsViewController {
|
||||||
case licenses
|
case licenses
|
||||||
|
|
||||||
case notices
|
case notices
|
||||||
|
|
||||||
|
case translations
|
||||||
}
|
}
|
||||||
|
|
||||||
enum RowType: Int {
|
enum RowType: Int {
|
||||||
case license
|
case license
|
||||||
|
|
||||||
case notice
|
case notice
|
||||||
|
|
||||||
|
case translation
|
||||||
}
|
}
|
||||||
|
|
||||||
override func numberOfSections(in tableView: UITableView) -> Int {
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||||
|
@ -110,6 +131,16 @@ extension CreditsViewController {
|
||||||
let obj = notices[indexPath.row]
|
let obj = notices[indexPath.row]
|
||||||
cell.leftText = obj.name
|
cell.leftText = obj.name
|
||||||
cell.rightText = nil
|
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.localizedLanguage(lang)
|
||||||
|
cell.rightText = author
|
||||||
|
cell.accessoryType = .none
|
||||||
|
cell.isTappable = false
|
||||||
}
|
}
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
|
@ -274,5 +274,6 @@
|
||||||
"credits.title" = "Credits";
|
"credits.title" = "Credits";
|
||||||
"credits.sections.licenses.header" = "Licenses";
|
"credits.sections.licenses.header" = "Licenses";
|
||||||
"credits.sections.notices.header" = "Notices";
|
"credits.sections.notices.header" = "Notices";
|
||||||
|
"credits.sections.translations.header" = "Translations";
|
||||||
|
|
||||||
"label.license.error" = "Unable to download full license content.";
|
"label.license.error" = "Unable to download full license content.";
|
||||||
|
|
|
@ -153,6 +153,10 @@ public class AppConstants {
|
||||||
|
|
||||||
public static let template = "I offer to translate to: "
|
public static let template = "I offer to translate to: "
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static let authorByLanguage: [String: String] = [
|
||||||
|
"it": "Davide De Rosa"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
public class URLs {
|
public class URLs {
|
||||||
|
|
|
@ -287,6 +287,10 @@ public enum L10n {
|
||||||
/// Notices
|
/// Notices
|
||||||
public static let header = L10n.tr("Localizable", "credits.sections.notices.header")
|
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")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -138,6 +138,10 @@ public class Utils {
|
||||||
return String(format: format, locale: Locale.current)
|
return String(format: format, locale: Locale.current)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static func localizedLanguage(_ code: String) -> String? {
|
||||||
|
return Locale.current.localizedString(forLanguageCode: code)
|
||||||
|
}
|
||||||
|
|
||||||
private init() {
|
private init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue