damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 016dfa54f32d6cca0591ef571d69e8186d3cc0e3
parent 887eb902bf60a0169dfbf619125b17f284bfb45e
Author: Terry Yiu <963907+tyiu@users.noreply.github.com>
Date:   Sat,  7 Jan 2023 19:26:03 -0500

Internationalize amount formatting for sats

Diffstat:
Mdamus/Models/Mentions.swift | 18++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/damus/Models/Mentions.swift b/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.") } } }