Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve syntax for CommonLocalizedString #4688

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RevenueCatUI/CustomerCenter/ButtonStyles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct DismissCircleButton: View {
)
}
.buttonStyle(.plain)
.accessibilityLabel(Text(localization.commonLocalizedString(for: .dismiss)))
.accessibilityLabel(Text(localization[.dismiss]))
}

}
Expand Down
4 changes: 2 additions & 2 deletions RevenueCatUI/CustomerCenter/ContactSupportUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extension CustomerCenterConfigData.Support {
}
let defaultBody =
"""
\(localization.commonLocalizedString(for: .defaultBody))
\(localization[.defaultBody])

---------------------------
\(infoToInclude.map { (key, value) in
Expand All @@ -40,7 +40,7 @@ extension CustomerCenterConfigData.Support {
}

private static func defaultData(_ localization: CustomerCenterConfigData.Localization) -> [(String, String)] {
let unknown = localization.commonLocalizedString(for: .unknown)
let unknown = localization[.unknown]
var osVersion = unknown
var deviceModel = unknown
#if canImport(UIKit) && !os(watchOS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class PurchaseDetailViewModel: ObservableObject {
switch purchaseInfo {
case .subscription(let subscriptionInfo):
subscriptionInfo.ownershipType == .familyShared
? localization.commonLocalizedString(for: .sharedThroughFamilyMember)
? localization[.sharedThroughFamilyMember]
: nil
case .nonSubscription:
nil
Expand Down Expand Up @@ -74,7 +74,6 @@ private extension PurchaseDetailViewModel {
]

items.append(contentsOf: purchaseInfo.purchaseDetailItems)

self.items = items
}
}
Expand Down
8 changes: 4 additions & 4 deletions RevenueCatUI/CustomerCenter/Views/AppUpdateWarningView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ struct AppUpdateWarningView: View {
List {
Section {
CompatibilityContentUnavailableView(
localization.commonLocalizedString(for: .updateWarningTitle),
localization[.updateWarningTitle],
systemImage: "arrow.up.circle.fill",
description: Text(localization.commonLocalizedString(for: .updateWarningDescription))
description: Text(localization[.updateWarningDescription])
)
}

Section {
Button(localization.commonLocalizedString(for: .updateWarningUpdate)) {
Button(localization[.updateWarningUpdate]) {
onUpdateAppClick()
}
.buttonStyle(ProminentButtonStyle())
.padding(.top, 4)

Button(localization.commonLocalizedString(for: .updateWarningIgnore)) {
Button(localization[.updateWarningIgnore]) {
onContinueAnywayClick()
}
.buttonStyle(TextButtonStyle())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ struct ManageSubscriptionsView: View {
Button {
viewModel.showPurchases = true
} label: {
Text(localization.commonLocalizedString(for: .seeAllPurchases))
Text(localization[.seeAllPurchases])
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
}
.buttonStyle(.plain)
Expand All @@ -102,7 +102,7 @@ struct ManageSubscriptionsView: View {
}
}
} else {
let fallbackDescription = localization.commonLocalizedString(for: .tryCheckRestore)
let fallbackDescription = localization[.tryCheckRestore]

Section {
CompatibilityContentUnavailableView(
Expand Down
6 changes: 3 additions & 3 deletions RevenueCatUI/CustomerCenter/Views/NoSubscriptionsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ struct NoSubscriptionsView: View {
}

var body: some View {
let fallbackDescription = localization.commonLocalizedString(for: .tryCheckRestore)
let fallbackTitle = localization.commonLocalizedString(for: .noSubscriptionsFound)
let fallbackDescription = localization[.tryCheckRestore]
let fallbackTitle = localization[.noSubscriptionsFound]

List {
Section {
Expand All @@ -57,7 +57,7 @@ struct NoSubscriptionsView: View {
}

Section {
Button(localization.commonLocalizedString(for: .restorePurchases)) {
Button(localization[.restorePurchases]) {
showRestoreAlert = true
}
.restorePurchasesAlert(isPresented: $showRestoreAlert)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ struct PromotionalOfferView: View {
Button {
self.dismissPromotionalOfferView(.declinePromotionalOffer)
} label: {
Text(self.localization.commonLocalizedString(for: .noThanks))
Text(self.localization[.noThanks])
}
.padding()
.frame(maxWidth: .infinity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct PurchaseDetailView: View {
Section {
ForEach(viewModel.items) { detailItem in
CompatibilityLabeledContent(
localization.commonLocalizedString(for: detailItem.label),
localization[detailItem.label],
content: content(detailItem: detailItem)
)
}
Expand Down Expand Up @@ -59,7 +59,7 @@ struct PurchaseDetailView: View {
case .status(let value),
.periodType(let value),
.store(let value):
return localization.commonLocalizedString(for: value)
return localization[value]

case .purchaseDate(let value),
.expiresDate(let value),
Expand All @@ -74,8 +74,8 @@ struct PurchaseDetailView: View {

case .sandbox(let value):
return value
? localization.commonLocalizedString(for: .answerYes)
: localization.commonLocalizedString(for: .answerNo)
? localization[.answerYes]
: localization[.answerNo]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct PurchaseHistoryView: View {
} else if let info = viewModel.customerInfo {
if !info.activeSubscriptions.isEmpty {
Section(header: Text(
localization.commonLocalizedString(for: .activeSubscriptions)
localization[.activeSubscriptions]
)) {
ForEach(viewModel.activeSubscriptions) { activeSubscription in
Button {
Expand All @@ -48,7 +48,7 @@ struct PurchaseHistoryView: View {
}

Section(header: Text(
localization.commonLocalizedString(for: .expiredSubscriptions)
localization[.expiredSubscriptions]
)) {
ForEach(viewModel.inactiveSubscriptions) { inactiveSubscription in
Button {
Expand All @@ -64,7 +64,7 @@ struct PurchaseHistoryView: View {
// Non-Subscription Purchases Section
if !viewModel.nonSubscriptions.isEmpty {
Section(header: Text(
localization.commonLocalizedString(for: .otherPurchases)
localization[.otherPurchases]
)) {
ForEach(viewModel.nonSubscriptions) { inactiveSubscription in
Button {
Expand All @@ -79,22 +79,22 @@ struct PurchaseHistoryView: View {

// Account Details Section
Section(header: Text(
localization.commonLocalizedString(for: .accountDetails)
localization[.accountDetails]
)) {
CompatibilityLabeledContent(
localization.commonLocalizedString(for: .dateWhenAppWasPurchased),
localization[.dateWhenAppWasPurchased],
content: dateFormatter.string(from: info.originalPurchaseDate!)
)

CompatibilityLabeledContent(
localization.commonLocalizedString(for: .userId),
localization[.userId],
content: info.originalAppUserId
)
.contextMenu {
Button {
UIPasteboard.general.string = info.originalAppUserId
} label: {
Text(localization.commonLocalizedString(for: .copy))
Text(localization[.copy])
Image(systemName: "doc.on.clipboard")
}
}
Expand All @@ -108,7 +108,7 @@ struct PurchaseHistoryView: View {
PurchaseDetailView(
viewModel: PurchaseDetailViewModel(purchaseInfo: $0))
}
.navigationTitle(localization.commonLocalizedString(for: .purchaseHistory))
.navigationTitle(localization[.purchaseHistory])
.listStyle(.insetGrouped)
.onAppear {
Task {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct PurchaseLinkView: View {
}

private var purchasedOnLocalized: String {
localization.commonLocalizedString(for: .purchaseInfoPurchasedOnDate)
localization[.purchaseInfoPurchasedOnDate]
.replacingOccurrences(of: L10n.date, with: formattedDate(purchaseInfo.purchaseDate))
}

Expand All @@ -70,14 +70,14 @@ struct PurchaseLinkView: View {
}

guard purchaseInfo.isActive else {
return localization.commonLocalizedString(for: .purchaseInfoExpiredOnDate)
return localization[.purchaseInfoExpiredOnDate]
.replacingOccurrences(of: L10n.date, with: formattedDate(expiresDate))
}

return purchaseInfo.willRenew
? localization.commonLocalizedString(for: .purchaseInfoRenewsOnDate)
? localization[.purchaseInfoRenewsOnDate]
.replacingOccurrences(of: L10n.date, with: formattedDate(expiresDate))
: localization.commonLocalizedString(for: .purchaseInfoExpiresOnDate)
: localization[.purchaseInfoExpiresOnDate]
.replacingOccurrences(of: L10n.date, with: formattedDate(expiresDate))
}

Expand Down
26 changes: 13 additions & 13 deletions RevenueCatUI/CustomerCenter/Views/RestorePurchasesAlert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct RestorePurchasesAlert: ViewModifier {

private var supportURL: URL? {
guard let supportInformation = self.supportInformation else { return nil }
let subject = self.localization.commonLocalizedString(for: .defaultSubject)
let subject = self.localization[.defaultSubject]
let body = supportInformation.calculateBody(self.localization)
return URLUtilities.createMailURLIfPossible(email: supportInformation.email,
subject: subject,
Expand Down Expand Up @@ -72,7 +72,7 @@ struct RestorePurchasesAlert: ViewModifier {
case .purchasesRecovered:
return [
AlertOrConfirmationDialog.AlertAction(
title: localization.commonLocalizedString(for: .dismiss),
title: localization[.dismiss],
role: .cancel,
action: dismissAlert
)
Expand All @@ -85,7 +85,7 @@ struct RestorePurchasesAlert: ViewModifier {
customerCenterViewModel.shouldShowAppUpdateWarnings {
actions.append(
AlertOrConfirmationDialog.AlertAction(
title: localization.commonLocalizedString(for: .updateWarningUpdate),
title: localization[.updateWarningUpdate],
role: nil,
action: onUpdateAppClick
)
Expand All @@ -95,7 +95,7 @@ struct RestorePurchasesAlert: ViewModifier {
if let url = supportURL {
actions.append(
AlertOrConfirmationDialog.AlertAction(
title: localization.commonLocalizedString(for: .contactSupport),
title: localization[.contactSupport],
role: nil,
action: { Task { openURL(url) } }
)
Expand All @@ -104,7 +104,7 @@ struct RestorePurchasesAlert: ViewModifier {

actions.append(
AlertOrConfirmationDialog.AlertAction(
title: localization.commonLocalizedString(for: .dismiss),
title: localization[.dismiss],
role: .cancel,
action: dismissAlert
)
Expand All @@ -115,7 +115,7 @@ struct RestorePurchasesAlert: ViewModifier {
case .restorePurchases:
return [
AlertOrConfirmationDialog.AlertAction(
title: localization.commonLocalizedString(for: .checkPastPurchases),
title: localization[.checkPastPurchases],
role: nil,
action: {
Task {
Expand All @@ -125,7 +125,7 @@ struct RestorePurchasesAlert: ViewModifier {
}
),
AlertOrConfirmationDialog.AlertAction(
title: localization.commonLocalizedString(for: .cancel),
title: localization[.cancel],
role: .cancel,
action: dismissAlert
)
Expand All @@ -137,26 +137,26 @@ struct RestorePurchasesAlert: ViewModifier {
private func alertTitle() -> String {
switch self.alertType {
case .purchasesRecovered:
return localization.commonLocalizedString(for: .purchasesRecovered)
return localization[.purchasesRecovered]
case .purchasesNotFound:
return ""
case .restorePurchases:
return localization.commonLocalizedString(for: .restorePurchases)
return localization[.restorePurchases]
}
}

private func alertMessage() -> String {
switch self.alertType {
case .purchasesRecovered:
return localization.commonLocalizedString(for: .purchasesRecoveredExplanation)
return localization[.purchasesRecoveredExplanation]
case .purchasesNotFound:
var message = localization.commonLocalizedString(for: .purchasesNotRecovered)
var message = localization[.purchasesNotRecovered]
if customerCenterViewModel.shouldShowAppUpdateWarnings {
message += "\n\n" + localization.commonLocalizedString(for: .updateWarningDescription)
message += "\n\n" + localization[.updateWarningDescription]
}
return message
case .restorePurchases:
return localization.commonLocalizedString(for: .goingToCheckPurchases)
return localization[.goingToCheckPurchases]
}
}

Expand Down
Loading