Reuse enabled/disabled strings in configuration

This commit is contained in:
Davide De Rosa 2019-03-27 17:00:45 +01:00
parent baff0435e8
commit 250c3399da
3 changed files with 27 additions and 35 deletions

View File

@ -227,6 +227,7 @@ extension ConfigurationViewController: UITableViewDataSource, UITableViewDelegat
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let row = model.row(at: indexPath)
let V = L10n.Configuration.Cells.self
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
if !isEditable {
@ -260,17 +261,16 @@ extension ConfigurationViewController: UITableViewDataSource, UITableViewDelegat
case .tlsWrapping:
cell.leftText = L10n.Configuration.Cells.TlsWrapping.caption
let V = L10n.Configuration.Cells.TlsWrapping.Value.self
if let strategy = configuration.tlsWrap?.strategy {
switch strategy {
case .auth:
cell.rightText = V.auth
cell.rightText = V.TlsWrapping.Value.auth
case .crypt:
cell.rightText = V.crypt
cell.rightText = V.TlsWrapping.Value.crypt
}
} else {
cell.rightText = V.disabled
cell.rightText = V.All.Value.disabled
}
cell.accessoryType = .none
cell.isTappable = false
@ -283,11 +283,10 @@ extension ConfigurationViewController: UITableViewDataSource, UITableViewDelegat
case .compressionAlgorithm:
cell.leftText = L10n.Configuration.Cells.CompressionAlgorithm.caption
let V = L10n.Configuration.Cells.CompressionAlgorithm.Value.self
if let compressionAlgorithm = configuration.compressionAlgorithm {
cell.rightText = compressionAlgorithm.cellDescription
} else {
cell.rightText = V.disabled
cell.rightText = V.All.Value.disabled
}
cell.accessoryType = .none
cell.isTappable = false
@ -303,22 +302,20 @@ extension ConfigurationViewController: UITableViewDataSource, UITableViewDelegat
case .keepAlive:
cell.leftText = L10n.Configuration.Cells.KeepAlive.caption
let V = L10n.Configuration.Cells.KeepAlive.Value.self
if let keepAlive = configuration.keepAliveInterval, keepAlive > 0 {
cell.rightText = V.seconds(Int(keepAlive))
cell.rightText = V.KeepAlive.Value.seconds(Int(keepAlive))
} else {
cell.rightText = V.never
cell.rightText = V.All.Value.disabled
}
cell.accessoryType = .none
cell.isTappable = false
case .renegSeconds:
cell.leftText = L10n.Configuration.Cells.RenegotiationSeconds.caption
let V = L10n.Configuration.Cells.RenegotiationSeconds.Value.self
if let reneg = configuration.renegotiatesAfter, reneg > 0 {
cell.rightText = V.after(TimeInterval(reneg).localized)
cell.rightText = V.RenegotiationSeconds.Value.after(TimeInterval(reneg).localized)
} else {
cell.rightText = V.never
cell.rightText = V.All.Value.disabled
}
cell.accessoryType = .none
cell.isTappable = false
@ -398,32 +395,32 @@ extension ConfigurationViewController: UITableViewDataSource, UITableViewDelegat
private extension SessionProxy.CompressionFraming {
var cellDescription: String {
let V = L10n.Configuration.Cells.CompressionFraming.Value.self
let V = L10n.Configuration.Cells.self
switch self {
case .disabled:
return V.disabled
return V.All.Value.disabled
case .compLZO:
return V.lzo
return V.CompressionFraming.Value.lzo
case .compress:
return V.compress
return V.CompressionFraming.Value.compress
}
}
}
private extension SessionProxy.CompressionAlgorithm {
var cellDescription: String {
let V = L10n.Configuration.Cells.CompressionAlgorithm.Value.self
let V = L10n.Configuration.Cells.self
switch self {
case .disabled:
return V.disabled
return V.All.Value.disabled
case .LZO:
return V.lzo
return V.CompressionAlgorithm.Value.lzo
case .other:
return V.other
return V.CompressionAlgorithm.Value.other
}
}
}

View File

@ -162,22 +162,19 @@
"configuration.cells.tls_wrapping.caption" = "Wrapping";
"configuration.cells.tls_wrapping.value.auth" = "Authentication";
"configuration.cells.tls_wrapping.value.crypt" = "Encryption";
"configuration.cells.tls_wrapping.value.disabled" = "Disabled";
"configuration.cells.dns_server.caption" = "Address";
"configuration.cells.compression_framing.caption" = "Framing";
"configuration.cells.compression_framing.value.disabled" = "Disabled";
"configuration.cells.compression_framing.value.lzo" = "--comp-lzo";
"configuration.cells.compression_framing.value.compress" = "--compress";
"configuration.cells.compression_algorithm.caption" = "Algorithm";
"configuration.cells.compression_algorithm.value.disabled" = "Disabled";
"configuration.cells.compression_algorithm.value.lzo" = "LZO";
"configuration.cells.compression_algorithm.value.other" = "Unsupported";
"configuration.cells.keep_alive.caption" = "Keep-alive";
"configuration.cells.keep_alive.value.seconds" = "%d seconds";
"configuration.cells.keep_alive.value.never" = "Disabled";
"configuration.cells.renegotiation_seconds.caption" = "Renegotiation";
"configuration.cells.renegotiation_seconds.value.after" = "after %@";
"configuration.cells.renegotiation_seconds.value.never" = "Disabled";
"configuration.cells.all.value.enabled" = "Enabled";
"configuration.cells.all.value.disabled" = "Disabled";
"debug_log.buttons.previous" = "Previous";
"debug_log.buttons.next" = "Next";

View File

@ -98,6 +98,14 @@ public enum L10n {
public enum Configuration {
public enum Cells {
public enum All {
public enum Value {
/// Disabled
public static let disabled = L10n.tr("Localizable", "configuration.cells.all.value.disabled")
/// Enabled
public static let enabled = L10n.tr("Localizable", "configuration.cells.all.value.enabled")
}
}
public enum Cipher {
/// Cipher
public static let caption = L10n.tr("Localizable", "configuration.cells.cipher.caption")
@ -116,8 +124,6 @@ public enum L10n {
/// Algorithm
public static let caption = L10n.tr("Localizable", "configuration.cells.compression_algorithm.caption")
public enum Value {
/// Disabled
public static let disabled = L10n.tr("Localizable", "configuration.cells.compression_algorithm.value.disabled")
/// LZO
public static let lzo = L10n.tr("Localizable", "configuration.cells.compression_algorithm.value.lzo")
/// Unsupported
@ -130,8 +136,6 @@ public enum L10n {
public enum Value {
/// --compress
public static let compress = L10n.tr("Localizable", "configuration.cells.compression_framing.value.compress")
/// Disabled
public static let disabled = L10n.tr("Localizable", "configuration.cells.compression_framing.value.disabled")
/// --comp-lzo
public static let lzo = L10n.tr("Localizable", "configuration.cells.compression_framing.value.lzo")
}
@ -152,8 +156,6 @@ public enum L10n {
/// Keep-alive
public static let caption = L10n.tr("Localizable", "configuration.cells.keep_alive.caption")
public enum Value {
/// Disabled
public static let never = L10n.tr("Localizable", "configuration.cells.keep_alive.value.never")
/// %d seconds
public static func seconds(_ p1: Int) -> String {
return L10n.tr("Localizable", "configuration.cells.keep_alive.value.seconds", p1)
@ -168,8 +170,6 @@ public enum L10n {
public static func after(_ p1: String) -> String {
return L10n.tr("Localizable", "configuration.cells.renegotiation_seconds.value.after", p1)
}
/// Disabled
public static let never = L10n.tr("Localizable", "configuration.cells.renegotiation_seconds.value.never")
}
}
public enum ResetOriginal {
@ -184,8 +184,6 @@ public enum L10n {
public static let auth = L10n.tr("Localizable", "configuration.cells.tls_wrapping.value.auth")
/// Encryption
public static let crypt = L10n.tr("Localizable", "configuration.cells.tls_wrapping.value.crypt")
/// Disabled
public static let disabled = L10n.tr("Localizable", "configuration.cells.tls_wrapping.value.disabled")
}
}
}