Browse Source

Internationalize amount formatting for sats

translations_damus-localizations-en-us-xcloc-localized-contents-en-us-xliff--master_es_419
Terry Yiu 2 years ago
parent
commit
016dfa54f3
No known key found for this signature in database GPG Key ID: 108645AE8A19B71A
  1. 18
      damus/Models/Mentions.swift

18
damus/Models/Mentions.swift

@ -187,12 +187,22 @@ enum Amount: Equatable {
func amount_sats_str() -> String {
switch self {
case .any:
return "Any"
return NSLocalizedString("Any", comment: "Any amount of sats")
case .specific(let amt):
if amt < 1000 {
return "\(Double(amt) / 1000.0) sats"
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .decimal
numberFormatter.minimumFractionDigits = 0
numberFormatter.maximumFractionDigits = 3
numberFormatter.roundingMode = .down
let sats = NSNumber(value: (Double(amt) / 1000.0))
let formattedSats = numberFormatter.string(from: sats) ?? sats.stringValue
if formattedSats == numberFormatter.string(from: 1) {
return NSLocalizedString("\(formattedSats) sat", comment: "Amount of 1 sat.")
}
return "\(amt / 1000) sats"
return NSLocalizedString("\(formattedSats) sats", comment: "Amount of sats.")
}
}
}

Loading…
Cancel
Save