diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index 845488b78..0af995f61 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -485,8 +485,7 @@ import Sparkle } @objc func updateDockBadge() { - let label = unreadCount > 0 ? "\(unreadCount)" : "" - NSApplication.shared.dockTile.badgeLabel = label + NSApplication.shared.dockTile.badgeLabel = UnreadCountFormatter.string(from: unreadCount) } // MARK: - Actions diff --git a/Mac/MainWindow/Sidebar/Cell/SidebarCell.swift b/Mac/MainWindow/Sidebar/Cell/SidebarCell.swift index 7cefbd021..5d90408a0 100644 --- a/Mac/MainWindow/Sidebar/Cell/SidebarCell.swift +++ b/Mac/MainWindow/Sidebar/Cell/SidebarCell.swift @@ -113,7 +113,8 @@ class SidebarCell : NSTableCellView { override func accessibilityLabel() -> String? { if unreadCount > 0 { let unreadLabel = NSLocalizedString("unread", comment: "Unread label for accessiblity") - return "\(name) \(unreadCount) \(unreadLabel)" + let unreadCountString = UnreadCountFormatter.string(from: unreadCount) + return "\(name) \(unreadCountString) \(unreadLabel)" } else { return name } diff --git a/Mac/MainWindow/Sidebar/UnreadCountView.swift b/Mac/MainWindow/Sidebar/UnreadCountView.swift index 2205036b6..fc5886658 100644 --- a/Mac/MainWindow/Sidebar/UnreadCountView.swift +++ b/Mac/MainWindow/Sidebar/UnreadCountView.swift @@ -27,7 +27,7 @@ final class UnreadCountView : NSView { } } var unreadCountString: String { - return unreadCount < 1 ? "" : "\(unreadCount)" + UnreadCountFormatter.string(from: unreadCount) } private var intrinsicContentSizeIsValid = false diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index d99cac1d8..b3bcdc895 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -495,6 +495,8 @@ 84F9EAF3213660A100CF2DE4 /* testCurrentArticleIsNil.applescript in Sources */ = {isa = PBXBuildFile; fileRef = 84F9EAE0213660A100CF2DE4 /* testCurrentArticleIsNil.applescript */; }; 84F9EAF4213660A100CF2DE4 /* testGenericScript.applescript in Sources */ = {isa = PBXBuildFile; fileRef = 84F9EAE1213660A100CF2DE4 /* testGenericScript.applescript */; }; 84F9EAF5213660A100CF2DE4 /* establishMainWindowStartingState.applescript in Sources */ = {isa = PBXBuildFile; fileRef = 84F9EAE2213660A100CF2DE4 /* establishMainWindowStartingState.applescript */; }; + 84FCB8742CCDFB7800CCC2F8 /* UnreadCountFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84FCB8732CCDFB7800CCC2F8 /* UnreadCountFormatter.swift */; }; + 84FCB8752CCDFB7800CCC2F8 /* UnreadCountFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84FCB8732CCDFB7800CCC2F8 /* UnreadCountFormatter.swift */; }; B24E9ADC245AB88400DA5718 /* NSAttributedString+NetNewsWire.swift in Sources */ = {isa = PBXBuildFile; fileRef = B24E9ABA245AB88300DA5718 /* NSAttributedString+NetNewsWire.swift */; }; B24E9ADE245AB88400DA5718 /* NSAttributedString+NetNewsWire.swift in Sources */ = {isa = PBXBuildFile; fileRef = B24E9ABA245AB88300DA5718 /* NSAttributedString+NetNewsWire.swift */; }; B27EEBF9244D15F3000932E6 /* stylesheet.css in Resources */ = {isa = PBXBuildFile; fileRef = B27EEBDF244D15F2000932E6 /* stylesheet.css */; }; @@ -1116,6 +1118,7 @@ 84F9EAE1213660A100CF2DE4 /* testGenericScript.applescript */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.applescript; path = testGenericScript.applescript; sourceTree = ""; }; 84F9EAE2213660A100CF2DE4 /* establishMainWindowStartingState.applescript */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.applescript; path = establishMainWindowStartingState.applescript; sourceTree = ""; }; 84F9EAE4213660A100CF2DE4 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 84FCB8732CCDFB7800CCC2F8 /* UnreadCountFormatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnreadCountFormatter.swift; sourceTree = ""; }; B24E9ABA245AB88300DA5718 /* NSAttributedString+NetNewsWire.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSAttributedString+NetNewsWire.swift"; sourceTree = ""; }; B24EFD482330FF99006C6242 /* NetNewsWire-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NetNewsWire-Bridging-Header.h"; sourceTree = ""; }; B24EFD5923310109006C6242 /* WKPreferencesPrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WKPreferencesPrivate.h; sourceTree = ""; }; @@ -2025,6 +2028,7 @@ 511B9805237DCAC90028BCAA /* UserInfoKey.swift */, 844933D12BA953590068AC51 /* ArticlePathInfo.swift */, 8454C3F2263F2D8700E3F9C7 /* IconImageCache.swift */, + 84FCB8732CCDFB7800CCC2F8 /* UnreadCountFormatter.swift */, 845122752B8CEA9B00480DB0 /* SidebarItem */, 51C452AD2265102800C03939 /* Timeline */, 84702AB31FA27AE8006B8943 /* Commands */, @@ -3179,6 +3183,7 @@ 51627A6923861DED007B3B4B /* FeedsViewController+Drop.swift in Sources */, 514219372352510100E07E2C /* ImageScrollView.swift in Sources */, 516AE9B32371C372007DEEAA /* FeedTableViewSectionHeaderLayout.swift in Sources */, + 84FCB8752CCDFB7800CCC2F8 /* UnreadCountFormatter.swift in Sources */, D3555BF524664566005E48C3 /* ArticleSearchBar.swift in Sources */, 8454C3F3263F2D8700E3F9C7 /* IconImageCache.swift in Sources */, B24E9ADE245AB88400DA5718 /* NSAttributedString+NetNewsWire.swift in Sources */, @@ -3265,6 +3270,7 @@ 849A975C1ED9EB0D007D329B /* DefaultFeedsImporter.swift in Sources */, 84A37CB5201ECD610087C5AF /* RenameWindowController.swift in Sources */, 84A14FF320048CA70046AD9A /* SendToMicroBlogCommand.swift in Sources */, + 84FCB8742CCDFB7800CCC2F8 /* UnreadCountFormatter.swift in Sources */, 849A97891ED9ECEF007D329B /* ArticleTheme.swift in Sources */, 84B7178C201E66580091657D /* SidebarViewController+ContextualMenus.swift in Sources */, 84A1500520048DDF0046AD9A /* SendToMarsEditCommand.swift in Sources */, diff --git a/Shared/UnreadCountFormatter.swift b/Shared/UnreadCountFormatter.swift new file mode 100644 index 000000000..6b6342c14 --- /dev/null +++ b/Shared/UnreadCountFormatter.swift @@ -0,0 +1,27 @@ +// +// UnreadCountFormatter.swift +// NetNewsWire +// +// Created by Brent Simmons on 10/26/24. +// Copyright © 2024 Ranchero Software. All rights reserved. +// + +import Foundation + +@MainActor struct UnreadCountFormatter { + + private static let formatter: NumberFormatter = { + let nf = NumberFormatter() + nf.locale = Locale.current + nf.numberStyle = .decimal + return nf + }() + + static func string(from unreadCount: Int) -> String { + if unreadCount < 1 { + return "" + } + + return formatter.string(from: NSNumber(value: unreadCount))! + } +} diff --git a/iOS/Feeds/Cell/FeedTableViewCell.swift b/iOS/Feeds/Cell/FeedTableViewCell.swift index 7916fbede..f539a9c95 100644 --- a/iOS/Feeds/Cell/FeedTableViewCell.swift +++ b/iOS/Feeds/Cell/FeedTableViewCell.swift @@ -26,7 +26,8 @@ class FeedTableViewCell : VibrantTableViewCell { get { if unreadCount > 0 { let unreadLabel = NSLocalizedString("unread", comment: "Unread label for accessiblity") - return "\(name) \(unreadCount) \(unreadLabel)" + let unreadCountString = UnreadCountFormatter.string(from: unreadCount) + return "\(name) \(unreadCountString) \(unreadLabel)" } else { return name } diff --git a/iOS/Feeds/Cell/FeedTableViewSectionHeader.swift b/iOS/Feeds/Cell/FeedTableViewSectionHeader.swift index 9dcd5ad2b..0beea7691 100644 --- a/iOS/Feeds/Cell/FeedTableViewSectionHeader.swift +++ b/iOS/Feeds/Cell/FeedTableViewSectionHeader.swift @@ -23,7 +23,8 @@ class FeedTableViewSectionHeader: UITableViewHeaderFooterView { get { if unreadCount > 0 { let unreadLabel = NSLocalizedString("unread", comment: "Unread label for accessiblity") - return "\(name) \(unreadCount) \(unreadLabel) \(expandedStateMessage) " + let unreadCountString = UnreadCountFormatter.string(from: unreadCount) + return "\(name) \(unreadCountString) \(unreadLabel) \(expandedStateMessage) " } else { return "\(name) \(expandedStateMessage) " } diff --git a/iOS/Feeds/Cell/FeedUnreadCountView.swift b/iOS/Feeds/Cell/FeedUnreadCountView.swift index f85e2abc5..f41213b06 100644 --- a/iOS/Feeds/Cell/FeedUnreadCountView.swift +++ b/iOS/Feeds/Cell/FeedUnreadCountView.swift @@ -35,7 +35,7 @@ class FeedUnreadCountView : UIView { } var unreadCountString: String { - return unreadCount < 1 ? "" : "\(unreadCount)" + UnreadCountFormatter.string(from: unreadCount) } private var contentSizeIsValid = false