Untitled
unknown
swift
3 years ago
826 B
8
Indexable
extension Int {
// Get localization key based on the value and type
func adjustedPluralKey(component: String) -> String {
guard self != 0 else { return "plural.\(component).zero" }
let code = Bundle.main.preferredLocalizations.first ?? "en"
guard code == "ru" else {
return self == 1 ? "plural.\(component).one" : "plural.\(component).many"
}
let xy = Int(floor(Double(self)).truncatingRemainder(dividingBy: 100))
let y = Int(floor(Double(self)).truncatingRemainder(dividingBy: 10))
if y == 0 || y > 4 || (xy > 10 && xy < 15) { return "plural.\(component).many"}
if y > 1 && y < 5 && (xy < 10 || xy > 20) { return "plural.\(component).few" }
if y == 1 && xy != 11 { return "plural.\(component).one" }
return component
}
}Editor is loading...