Skip to content

Commit

Permalink
Utilize localization for Hop pluralization
Browse files Browse the repository at this point in the history
  • Loading branch information
bjpetit committed Dec 19, 2024
1 parent 564fadd commit 5bb8d3e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 22 deletions.
43 changes: 34 additions & 9 deletions Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,35 @@
"%@" : {

},
"%@ - %@ - %@" : {
"%@ - %@" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "%1$@ - %2$@ - %3$@"
"value" : "%1$@ - %2$@"
}
}
}
},
"%@ - %@ Towards %@ Back" : {
"%@ - %@ - %@" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "%1$@ - %2$@ Towards %3$@ Back"
"value" : "%1$@ - %2$@ - %3$@"
}
}
}
},
"%@ - %d %@" : {
"%@ - %@ Towards %@ Back" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "%1$@ - %2$d %3$@"
"value" : "%1$@ - %2$@ Towards %3$@ Back"
}
}
}
},
"%@ - Direct" : {

},
"%@ - No Response" : {
"localizations" : {
Expand Down Expand Up @@ -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%%" : {

Expand Down
22 changes: 9 additions & 13 deletions Meshtastic/Views/Nodes/TraceRouteLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 5bb8d3e

Please sign in to comment.