damus

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

commit 34970b38bbec1699b98c5b66650c2927cfa6dcf5
parent 0f89d98513b42335b35d0aa315a8589af7422e01
Author: Terry Yiu <963907+tyiu@users.noreply.github.com>
Date:   Sat, 29 Apr 2023 14:56:47 -0400

Fix plurality on sats

Diffstat:
Mdamus.xcodeproj/project.pbxproj | 4++++
Mdamus/Views/Zaps/CustomizeZapView.swift | 7++++++-
Mdamus/en-US.lproj/Localizable.stringsdict | 20++++++++++++++++++--
AdamusTests/CustomZapViewTests.swift | 34++++++++++++++++++++++++++++++++++
MdamusTests/ProfileViewTests.swift | 11+++++++++++
5 files changed, 73 insertions(+), 3 deletions(-)

diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj @@ -29,6 +29,7 @@ 3ACB685F297633BC00C46468 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 3ACB685D297633BC00C46468 /* Localizable.strings */; }; 3ACBCB78295FE5C70037388A /* TimeAgoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ACBCB77295FE5C70037388A /* TimeAgoTests.swift */; }; 3AE45AF6297BB2E700C1D842 /* LibreTranslateServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE45AF5297BB2E700C1D842 /* LibreTranslateServer.swift */; }; + 3AFBF3FD29FDA7CC00E79C7C /* CustomZapViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AFBF3FC29FDA7CC00E79C7C /* CustomZapViewTests.swift */; }; 4C06670128FC7C5900038D2A /* RelayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C06670028FC7C5900038D2A /* RelayView.swift */; }; 4C06670428FC7EC500038D2A /* Kingfisher in Frameworks */ = {isa = PBXBuildFile; productRef = 4C06670328FC7EC500038D2A /* Kingfisher */; }; 4C06670628FCB08600038D2A /* ImageCarousel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C06670528FCB08600038D2A /* ImageCarousel.swift */; }; @@ -413,6 +414,7 @@ 3AF6336829884C6B0005672A /* pt-PT */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-PT"; path = "pt-PT.lproj/InfoPlist.strings"; sourceTree = "<group>"; }; 3AF6336929884C6B0005672A /* pt-PT */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-PT"; path = "pt-PT.lproj/Localizable.strings"; sourceTree = "<group>"; }; 3AF6336A29884C6B0005672A /* pt-PT */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = "pt-PT"; path = "pt-PT.lproj/Localizable.stringsdict"; sourceTree = "<group>"; }; + 3AFBF3FC29FDA7CC00E79C7C /* CustomZapViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomZapViewTests.swift; sourceTree = "<group>"; }; 4C06670028FC7C5900038D2A /* RelayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayView.swift; sourceTree = "<group>"; }; 4C06670528FCB08600038D2A /* ImageCarousel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCarousel.swift; sourceTree = "<group>"; }; 4C06670828FDE64700038D2A /* damus-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "damus-Bridging-Header.h"; sourceTree = "<group>"; }; @@ -1275,6 +1277,7 @@ 3A30410029AB12AA008A0F29 /* EventGroupViewTests.swift */, 4C8D00D329E3C5D40036AF10 /* NIP19Tests.swift */, 501F8C812A0224EB001AFC1D /* KeychainStorageTests.swift */, + 3AFBF3FC29FDA7CC00E79C7C /* CustomZapViewTests.swift */, ); path = damusTests; sourceTree = "<group>"; @@ -1815,6 +1818,7 @@ 4C8D00D429E3C5D40036AF10 /* NIP19Tests.swift in Sources */, 3A30410129AB12AA008A0F29 /* EventGroupViewTests.swift in Sources */, 501F8C822A0224EB001AFC1D /* KeychainStorageTests.swift in Sources */, + 3AFBF3FD29FDA7CC00E79C7C /* CustomZapViewTests.swift in Sources */, 3ACBCB78295FE5C70037388A /* TimeAgoTests.swift in Sources */, DD597CBD2963D85A00C64D32 /* MarkdownTests.swift in Sources */, 3A3040EF29A8FEE9008A0F29 /* EventDetailBarTests.swift in Sources */, diff --git a/damus/Views/Zaps/CustomizeZapView.swift b/damus/Views/Zaps/CustomizeZapView.swift @@ -39,6 +39,11 @@ func get_zap_amount_items(_ default_zap_amt: Int) -> [ZapAmountItem] { return entries } +func satsString(_ count: Int, locale: Locale = Locale.current) -> String { + let format = localizedStringFormat(key: "sats", locale: locale) + return String(format: format, locale: locale, count) +} + struct CustomizeZapView: View { let state: DamusState let event: NostrEvent @@ -147,7 +152,7 @@ struct CustomizeZapView: View { self.custom_amount_sats = nil } } - Text(custom_amount_sats == 1 ? "sat" : "sats", comment: "Shortened form of satoshi, display unit of measure where 1,000,000,000 satoshis is 1 Bitcoin. Used to indicate how many sats will be zapped to a note, configured through the custom zap view.") + Text(verbatim: satsString(custom_amount_sats ?? 0)) .font(.system(size: 18, weight: .heavy)) } } diff --git a/damus/en-US.lproj/Localizable.stringsdict b/damus/en-US.lproj/Localizable.stringsdict @@ -210,6 +210,22 @@ <string>Reposts</string> </dict> </dict> + <key>sats</key> + <dict> + <key>NSStringLocalizedFormatKey</key> + <string>%#@SATS@</string> + <key>SATS</key> + <dict> + <key>NSStringFormatSpecTypeKey</key> + <string>NSStringPluralRuleType</string> + <key>NSStringFormatValueTypeKey</key> + <string>d</string> + <key>one</key> + <string>sat</string> + <key>other</key> + <string>sats</string> + </dict> + </dict> <key>sats_count</key> <dict> <key>NSStringLocalizedFormatKey</key> @@ -253,9 +269,9 @@ <key>NSStringFormatValueTypeKey</key> <string>@</string> <key>one</key> - <string>You received %2$@ sat from %3$@: "%4$@"</string> + <string>You received %2$@ sat from %3$@: &quot;%4$@&quot;</string> <key>other</key> - <string>You received %2$@ sats from %3$@: "%4$@"</string> + <string>You received %2$@ sats from %3$@: &quot;%4$@&quot;</string> </dict> </dict> <key>zapped_tagged_in_3</key> diff --git a/damusTests/CustomZapViewTests.swift b/damusTests/CustomZapViewTests.swift @@ -0,0 +1,34 @@ +// +// CustomZapViewTests.swift +// damusTests +// +// Created by Terry Yiu on 4/29/23. +// + +import XCTest +@testable import damus + +final class CustomZapViewTests: XCTestCase { + + let enUsLocale = Locale(identifier: "en-US") + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + func testSatsString() throws { + XCTAssertEqual(satsString(0, locale: enUsLocale), "sats") + XCTAssertEqual(satsString(1, locale: enUsLocale), "sat") + XCTAssertEqual(satsString(2, locale: enUsLocale), "sats") + Bundle.main.localizations.map { Locale(identifier: $0) }.forEach { + for count in 1...10 { + XCTAssertNoThrow(satsString(count, locale: $0)) + } + } + } + +} diff --git a/damusTests/ProfileViewTests.swift b/damusTests/ProfileViewTests.swift @@ -31,6 +31,17 @@ final class ProfileViewTests: XCTestCase { } } + func testFollowingCountString() throws { + XCTAssertEqual(followingCountString(0, locale: enUsLocale), "Following") + XCTAssertEqual(followingCountString(1, locale: enUsLocale), "Following") + XCTAssertEqual(followingCountString(2, locale: enUsLocale), "Following") + Bundle.main.localizations.map { Locale(identifier: $0) }.forEach { + for count in 1...10 { + XCTAssertNoThrow(followingCountString(count, locale: $0)) + } + } + } + func testRelaysCountString() throws { XCTAssertEqual(relaysCountString(0, locale: enUsLocale), "Relays") XCTAssertEqual(relaysCountString(1, locale: enUsLocale), "Relay")