From 16156f4d9ae04f30ae8ff44b9ccc5ef3a3876042 Mon Sep 17 00:00:00 2001 From: Terry Yiu <963907+tyiu@users.noreply.github.com> Date: Sun, 26 Feb 2023 08:21:33 +1300 Subject: [PATCH] Fix number formatting for Arabic and other languages --- damus/Util/LocalizationUtil.swift | 6 ------ damus/Views/ActionBar/EventDetailBar.swift | 9 +++------ damus/Views/ProfileView.swift | 9 +++------ .../Localized Contents/en-US.xliff | 5 +++++ .../damus/en-US.lproj/Localizable.strings | Bin 60986 -> 61370 bytes 5 files changed, 11 insertions(+), 18 deletions(-) diff --git a/damus/Util/LocalizationUtil.swift b/damus/Util/LocalizationUtil.swift index de496d60..3abb3e9a 100644 --- a/damus/Util/LocalizationUtil.swift +++ b/damus/Util/LocalizationUtil.swift @@ -11,9 +11,3 @@ func bundleForLocale(locale: Locale) -> Bundle { let path = Bundle.main.path(forResource: locale.identifier, ofType: "lproj") return path != nil ? (Bundle(path: path!) ?? Bundle.main) : Bundle.main } - -func formatInt(_ int: Int) -> String { - let numberFormatter = NumberFormatter() - numberFormatter.numberStyle = .decimal - return numberFormatter.string(from: NSNumber(integerLiteral: int)) ?? "\(int)" -} diff --git a/damus/Views/ActionBar/EventDetailBar.swift b/damus/Views/ActionBar/EventDetailBar.swift index c9005855..799f0925 100644 --- a/damus/Views/ActionBar/EventDetailBar.swift +++ b/damus/Views/ActionBar/EventDetailBar.swift @@ -26,18 +26,16 @@ struct EventDetailBar: View { HStack { if bar.boosts > 0 { NavigationLink(destination: RepostsView(damus_state: state, model: RepostsModel(state: state, target: target))) { - let count = Text(verbatim: "\(formatInt(bar.boosts))").font(.body.bold()) let noun = Text(verbatim: "\(repostsCountString(bar.boosts))").foregroundColor(.gray) - Text("\(count) \(noun)", comment: "Sentence composed of 2 variables to describe how many reposts. In source English, the first variable is the number of reposts, and the second variable is 'Repost' or 'Reposts'.") + Text("\(Text("\(bar.boosts)").font(.body.bold())) \(noun)", comment: "Sentence composed of 2 variables to describe how many reposts. In source English, the first variable is the number of reposts, and the second variable is 'Repost' or 'Reposts'.") } .buttonStyle(PlainButtonStyle()) } if bar.likes > 0 { NavigationLink(destination: ReactionsView(damus_state: state, model: ReactionsModel(state: state, target: target))) { - let count = Text(verbatim: "\(formatInt(bar.likes))").font(.body.bold()) let noun = Text(verbatim: "\(reactionsCountString(bar.likes))").foregroundColor(.gray) - Text("\(count) \(noun)", comment: "Sentence composed of 2 variables to describe how many reactions there are on a post. In source English, the first variable is the number of reactions, and the second variable is 'Reaction' or 'Reactions'.") + Text("\(Text("\(bar.likes)").font(.body.bold())) \(noun)", comment: "Sentence composed of 2 variables to describe how many reactions there are on a post. In source English, the first variable is the number of reactions, and the second variable is 'Reaction' or 'Reactions'.") } .buttonStyle(PlainButtonStyle()) } @@ -45,9 +43,8 @@ struct EventDetailBar: View { if bar.zaps > 0 { let dst = ZapsView(state: state, target: .note(id: target, author: target_pk)) NavigationLink(destination: dst) { - let count = Text(verbatim: "\(formatInt(bar.zaps))").font(.body.bold()) let noun = Text(verbatim: "\(zapsCountString(bar.zaps))").foregroundColor(.gray) - Text("\(count) \(noun)", comment: "Sentence composed of 2 variables to describe how many zap payments there are on a post. In source English, the first variable is the number of zap payments, and the second variable is 'Zap' or 'Zaps'.") + Text("\(Text("\(bar.zaps)").font(.body.bold())) \(noun)", comment: "Sentence composed of 2 variables to describe how many zap payments there are on a post. In source English, the first variable is the number of zap payments, and the second variable is 'Zap' or 'Zaps'.") } .buttonStyle(PlainButtonStyle()) } diff --git a/damus/Views/ProfileView.swift b/damus/Views/ProfileView.swift index 7fe3b55c..8e4c3272 100644 --- a/damus/Views/ProfileView.swift +++ b/damus/Views/ProfileView.swift @@ -342,9 +342,8 @@ struct ProfileView: View { .foregroundColor(.gray) } else { let followerCount = followers.count! - let count_text = Text(verbatim: "\(formatInt(followerCount))").font(.subheadline.weight(.medium)) let noun_text = Text(verbatim: "\(followersCountString(followerCount))").font(.subheadline).foregroundColor(.gray) - Text("\(count_text) \(noun_text)", comment: "Sentence composed of 2 variables to describe how many people are following a user. In source English, the first variable is the number of followers, and the second variable is 'Follower' or 'Followers'.") + Text("\(Text("\(followerCount)").font(.subheadline.weight(.medium))) \(noun_text)", comment: "Sentence composed of 2 variables to describe how many people are following a user. In source English, the first variable is the number of followers, and the second variable is 'Follower' or 'Followers'.") } } } @@ -368,9 +367,8 @@ struct ProfileView: View { let following_model = FollowingModel(damus_state: damus_state, contacts: contacts) NavigationLink(destination: FollowingView(damus_state: damus_state, following: following_model, whos: profile.pubkey)) { HStack { - let count_text = Text(verbatim: "\(formatInt(profile.following))").font(.subheadline.weight(.medium)) let noun_text = Text("Following", comment: "Text on the user profile page next to the number of accounts a user is following.").font(.subheadline).foregroundColor(.gray) - Text("\(count_text) \(noun_text)", comment: "Sentence composed of 2 variables to describe how many profiles a user is following. In source English, the first variable is the number of profiles being followed, and the second variable is 'Following'.") + Text("\(Text("\(profile.following)").font(.subheadline.weight(.medium))) \(noun_text)", comment: "Sentence composed of 2 variables to describe how many profiles a user is following. In source English, the first variable is the number of profiles being followed, and the second variable is 'Following'.") } } .buttonStyle(PlainButtonStyle()) @@ -393,9 +391,8 @@ struct ProfileView: View { if let relays = profile.relays { // Only open relay config view if the user is logged in with private key and they are looking at their own profile. - let count_text = Text(verbatim: "\(formatInt(relays.keys.count))").font(.subheadline.weight(.medium)) let noun_text = Text(verbatim: "\(relaysCountString(relays.keys.count))").font(.subheadline).foregroundColor(.gray) - let relay_text = Text("\(count_text) \(noun_text)", comment: "Sentence composed of 2 variables to describe how many relay servers a user is connected. In source English, the first variable is the number of relay servers, and the second variable is 'Relay' or 'Relays'.") + let relay_text = Text("\(Text("\(relays.keys.count)").font(.subheadline.weight(.medium))) \(noun_text)", comment: "Sentence composed of 2 variables to describe how many relay servers a user is connected. In source English, the first variable is the number of relay servers, and the second variable is 'Relay' or 'Relays'.") if profile.pubkey == damus_state.pubkey && damus_state.is_privkey_user { NavigationLink(destination: RelayConfigView(state: damus_state)) { relay_text diff --git a/damus/en-US.xcloc/Localized Contents/en-US.xliff b/damus/en-US.xcloc/Localized Contents/en-US.xliff index 0ce1a9f5..686f43af 100644 --- a/damus/en-US.xcloc/Localized Contents/en-US.xliff +++ b/damus/en-US.xcloc/Localized Contents/en-US.xliff @@ -58,6 +58,11 @@ Sentence composed of 2 variables to describe how many people are following a use %@. Tip your friend's posts and stack sats with Bitcoin⚡️, the native currency of the internet. Explanation of what can be done by users to earn money. There is a heading that precedes this explanation which is a variable to this string. + + %lld + %lld + No comment provided by engineer. + %lld/%lld %lld/%lld diff --git a/damus/en-US.xcloc/Source Contents/damus/en-US.lproj/Localizable.strings b/damus/en-US.xcloc/Source Contents/damus/en-US.lproj/Localizable.strings index cf836b489db95f455ee4da1c973a1dab660d6a27..c4ac875aab91ec67f8ec58d23d45ed17451c0b0d 100644 GIT binary patch delta 383 zcmdmWhk4h1W~TrDCQlFx5L9JwU{GREV6X*ZB?cgGa$}qH*sR30jbm~` z3(Mpcj2WBPF)v}<{EclIle!*58bdxq9zzL(27?|$5|Ew3Pzhz_0NEN0njkp2n^V$| zNVP!gRT+#JRDcc$Y!L?9m$k9XhIz7vzS!mrRx!p<1qLk!eFiRw8-Z3KJD`}M6zGTy zhE#?`pyfFXnLwwd0@aiQ$xMcHpbW&Jxj=pjP^6S07vaD_Dw&1wz~+-e&6$%IWZ6u< ZSCcS#K?2+4pqhZm6WVw-d)0m@005xCSjGSV delta 79 zcmdmWpLy3EW~TrDHm~E`z`Xe%=K{vfaY8zblRX4VHqYXo#WeYWu*75s5sAqH9XuQB j1UNTGh?HbbR!Cx-oL3hxSs}+}GDlqkNOJS3x(@{aA?P2y