From 67a96cfc55b67e48e7ca3d48ffa91efb5ccf17e0 Mon Sep 17 00:00:00 2001 From: Max Radermacher Date: Mon, 25 Jul 2022 08:55:32 -0700 Subject: [PATCH] Fix a few issues with badge expiration body text MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Boost case used `String(format:...)` even though there aren’t any string replacements in the body text. We should avoid formatting strings that don’t have format specifiers. There was also a typo in the localized string key. This also separates the monthly donation call to action string so that it can be reused for gift badges. --- .../Donations/BadgeExpirationSheet.swift | 30 ++++++++++++------- .../BadgeExpirationSheetStateTest.swift | 9 ++++-- .../translations/en.lproj/Localizable.strings | 7 +++-- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/Signal/src/ViewControllers/AppSettings/Donations/BadgeExpirationSheet.swift b/Signal/src/ViewControllers/AppSettings/Donations/BadgeExpirationSheet.swift index 6606993a0f..2ed0448e50 100644 --- a/Signal/src/ViewControllers/AppSettings/Donations/BadgeExpirationSheet.swift +++ b/Signal/src/ViewControllers/AppSettings/Donations/BadgeExpirationSheet.swift @@ -65,11 +65,14 @@ public class BadgeExpirationSheetState { } }() - public lazy var body: Body = { - func format(_ formatText: String) -> String { - String(format: formatText, badge.localizedName) - } + private var monthlyDonationCallToAction: String { + NSLocalizedString( + "BADGE_EXPIRED_MONTHLY_CALL_TO_ACTION", + comment: "Shown when a non-monthly badge expires to suggest starting a recurring donation." + ) + } + public lazy var body: Body = { switch mode { case let .subscriptionExpiredBecauseOfChargeFailure(chargeFailure): let failureSpecificText = Self.getChargeFailureSpecificText(chargeFailure: chargeFailure) @@ -79,17 +82,22 @@ public class BadgeExpirationSheetState { case .subscriptionExpiredBecauseNotRenewed: let formatText = NSLocalizedString("BADGE_SUBSCRIPTION_EXPIRED_BECAUSE_OF_INACTIVITY_BODY_FORMAT", comment: "Body of the sheet shown when your subscription is canceled due to inactivity") - return Body(format(formatText), hasLearnMoreLink: true) + return Body(String(format: formatText, badge.localizedName), hasLearnMoreLink: true) case let .boostExpired(hasCurrentSubscription): - let formatText: String + var bodyText = [String]() if hasCurrentSubscription { - formatText = NSLocalizedString("BADGE_EXIPRED_BOOST_CURRENT_SUSTAINER_BODY_FORMAT", - comment: "String explaining to the user that their boost badge has expired while they are a current subscription sustainer on the badge expiry sheet.") + bodyText.append(NSLocalizedString( + "BADGE_EXPIRED_BOOST_CURRENT_SUSTAINER_BODY", + comment: "String explaining to the user that their boost badge has expired while they are a current subscription sustainer on the badge expiry sheet." + )) } else { - formatText = NSLocalizedString("BADGE_EXIPRED_BOOST_BODY_FORMAT", - comment: "String explaining to the user that their boost badge has expired on the badge expiry sheet.") + bodyText.append(NSLocalizedString( + "BADGE_EXPIRED_BOOST_BODY", + comment: "String explaining to the user that their boost badge has expired on the badge expiry sheet." + )) + bodyText.append(self.monthlyDonationCallToAction) } - return Body(format(formatText)) + return Body(bodyText.joined(separator: "\n\n")) } }() diff --git a/Signal/test/ViewControllers/BadgeExpirationSheetStateTest.swift b/Signal/test/ViewControllers/BadgeExpirationSheetStateTest.swift index 624104d91d..4abd5a4243 100644 --- a/Signal/test/ViewControllers/BadgeExpirationSheetStateTest.swift +++ b/Signal/test/ViewControllers/BadgeExpirationSheetStateTest.swift @@ -138,13 +138,16 @@ class BadgeExpirationSheetStateTest: XCTestCase { ), ( State(badge: getSubscriptionBadge(), mode: .boostExpired(hasCurrentSubscription: false)), - NSLocalizedString("BADGE_EXIPRED_BOOST_BODY_FORMAT", - comment: "String explaining to the user that their boost badge has expired on the badge expiry sheet."), + NSLocalizedString("BADGE_EXPIRED_BOOST_BODY", + comment: "String explaining to the user that their boost badge has expired on the badge expiry sheet.") + + "\n\n" + + NSLocalizedString("BADGE_EXPIRED_MONTHLY_CALL_TO_ACTION", + comment: "Shown when a non-monthly badge expires to suggest starting a recurring donation."), false ), ( State(badge: getSubscriptionBadge(), mode: .boostExpired(hasCurrentSubscription: true)), - NSLocalizedString("BADGE_EXIPRED_BOOST_CURRENT_SUSTAINER_BODY_FORMAT", + NSLocalizedString("BADGE_EXPIRED_BOOST_CURRENT_SUSTAINER_BODY", comment: "String explaining to the user that their boost badge has expired while they are a current subscription sustainer on the badge expiry sheet."), false ) diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 9f70544d55..409e5dad51 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -368,10 +368,10 @@ "BADGE_DETAILS_GIVE_A_BOOST" = "Give Signal a Boost"; /* String explaining to the user that their boost badge has expired on the badge expiry sheet. */ -"BADGE_EXIPRED_BOOST_BODY_FORMAT" = "Your Boost badge has expired and is no longer available to be displayed on your profile.\n\nYou can keep using Signal but to support technology that is built for you, consider becoming a sustainer by making a monthly donation."; +"BADGE_EXPIRED_BOOST_BODY" = "Your Boost badge has expired and is no longer available to be displayed on your profile."; /* String explaining to the user that their boost badge has expired while they are a current subscription sustainer on the badge expiry sheet. */ -"BADGE_EXIPRED_BOOST_CURRENT_SUSTAINER_BODY_FORMAT" = "Your Boost badge has expired and is no longer available to be displayed on your profile.\n\nYou can reactivate your Boost badge for another 30 days with a one-time contribution."; +"BADGE_EXPIRED_BOOST_CURRENT_SUSTAINER_BODY" = "Your Boost badge has expired and is no longer available to be displayed on your profile.\n\nYou can reactivate your Boost badge for another 30 days with a one-time contribution."; /* Button title for boost on the badge expiration sheet, used if the user is not already a sustainer. */ "BADGE_EXPIRED_BOOST_RENEWAL_BUTTON" = "Become a Sustainer"; @@ -385,6 +385,9 @@ /* Text for the 'learn more' link in the badge expiration sheet, shown when a badge expires due to a charge failure */ "BADGE_EXPIRED_LEARN_MORE_LINK" = "Learn more."; +/* Shown when a non-monthly badge expires to suggest starting a recurring donation. */ +"BADGE_EXPIRED_MONTHLY_CALL_TO_ACTION" = "You can keep using Signal but to support technology that is built for you, consider becoming a sustainer by making a monthly donation."; + /* Button text when a badge expires, asking you to renew your subscription */ "BADGE_EXPIRED_SUBSCRIPTION_RENEWAL_BUTTON" = "Renew Subscription";