Utilize localization for Hop pluralization

This commit is contained in:
Brent Petit 2024-12-19 10:03:33 -06:00
parent 564fadd017
commit 5bb8d3e1a6
2 changed files with 47 additions and 26 deletions

View file

@ -27,6 +27,16 @@
},
"%@" : {
},
"%@ - %@" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "%1$@ - %2$@"
}
}
}
},
"%@ - %@ - %@" : {
"localizations" : {
@ -47,19 +57,6 @@
}
}
}
},
"%@ - %d %@" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "%1$@ - %2$d %3$@"
}
}
}
},
"%@ - Direct" : {
},
"%@ - No Response" : {
"localizations" : {
@ -171,6 +168,34 @@
},
"%d" : {
},
"%d Hops" : {
"localizations" : {
"en" : {
"variations" : {
"plural" : {
"one" : {
"stringUnit" : {
"state" : "translated",
"value" : "%d Hop"
}
},
"other" : {
"stringUnit" : {
"state" : "new",
"value" : "%d Hops"
}
},
"zero" : {
"stringUnit" : {
"state" : "translated",
"value" : "Direct"
}
}
}
}
}
}
},
"%d%%" : {

View file

@ -37,25 +37,21 @@ struct TraceRouteLog: View {
VStack {
List(node.traceRoutes?.reversed() as? [TraceRouteEntity] ?? [], id: \.self, selection: $selectedRoute) { route in
Label {
if route.response && route.hopsTowards == 0 && route.hopsBack == 0 {
Text("\(route.time?.formatted() ?? "unknown".localized) - Direct")
.font(.caption)
} else if route.response && route.hopsTowards == route.hopsBack {
let hopLabel = route.hopsTowards == 1 ? "Hop" : "Hops"
Text("\(route.time?.formatted() ?? "unknown".localized) - \(route.hopsTowards) \(hopLabel)")
let routeTime = route.time?.formatted() ?? "unknown".localized
if route.response && route.hopsTowards == route.hopsBack {
let hopString = String(localized: "\(route.hopsTowards) Hops")
Text("\(routeTime) - \(hopString)")
.font(.caption)
} else if route.response {
let hopTowardsLabel = route.hopsTowards == 1 ? "Hop" : "Hops"
let hopBackLabel = route.hopsBack == 1 ? "Hop" : "Hops"
let hopTowardsString = (route.hopsTowards == 0) ? "Direct" : "\(route.hopsTowards) \(hopTowardsLabel)"
let hopBackString = (route.hopsBack == 0) ? "Direct" : "\(route.hopsBack) \(hopBackLabel)"
Text("\(route.time?.formatted() ?? "unknown".localized) - \(hopTowardsString) Towards \(hopBackString) Back")
let hopTowardsString = String(localized: "\(route.hopsTowards) Hops")
let hopBackString = String(localized: "\(route.hopsBack) Hops")
Text("\(routeTime) - \(hopTowardsString) Towards \(hopBackString) Back")
.font(.caption)
} else if route.sent {
Text("\(route.time?.formatted() ?? "unknown".localized) - No Response")
Text("\(routeTime) - No Response")
.font(.caption)
} else {
Text("\(route.time?.formatted() ?? "unknown".localized) - Not Sent")
Text("\(routeTime) - Not Sent")
.font(.caption)
}
} icon: {