-
Notifications
You must be signed in to change notification settings - Fork 349
Allow choosing the locale for a PaywallView
#4833
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
base: main
Are you sure you want to change the base?
Conversation
…i(Internal), for now)
PaywallView
PaywallView
@@ -22,7 +22,7 @@ struct PaywallViewConfiguration { | |||
let useDraftPaywall: Bool | |||
var introEligibility: TrialOrIntroEligibilityChecker? | |||
var purchaseHandler: PurchaseHandler | |||
var locale: Locale |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized that the locale
of PaywallViewConfiguration
was actually redundant. It was always holding Locale.current
, as the init
had .current
as the default value for the locale
parameter and this locale
parameter was never used.
That's why I've replaced it with preferredLocale
, which will now potentially come from the integrator's side
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In those places where a locale
is non-optional (basically in v1 paywalls, if I'm not mistaken), I've replaced the use of self.locale
to self.preferredLocale ?? .current
to keep the existing behavior if preferredLocale
is not specified
@@ -22,7 +22,7 @@ struct PaywallViewConfiguration { | |||
let useDraftPaywall: Bool | |||
var introEligibility: TrialOrIntroEligibilityChecker? | |||
var purchaseHandler: PurchaseHandler | |||
var locale: Locale | |||
var preferredLocale: Locale? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! We should probably add it to the presentPaywallIfNeeded()
api too, as well as Android (and hybrids 🫠).
Hello @ajpallares! I came across this PR while looking into some related issues, and I found it very helpful—great work! I’m reaching out from the React Native side, where we typically don’t rely on the device’s system language. Instead, most apps use an i18n package to manage localization dynamically. Because of this, when a user changes the app’s language, we update the locale at the JavaScript level, but the native iOS paywall still follows the device’s language. It would be incredibly useful to have a way to pass the preferred locale from React Native to ensure that the paywall aligns with the app’s selected language. Thank you! |
Thank you for the feedback @ferrannp! I honestly didn't know that fact about React Native and it makes this even more necessary. We don't have an exact timeline for it, but we definitely do intend to finish the work on this soon! |
Thanks @ajpallares ! FYI, I patched this library to make it work for now in my project. I was struggling with some stuff and I realized that here:
|
Checklist
purchases-android
and hybridsMotivation
Currently, the
PaywallPreview
is displayed using a locale decided by the SDK (based on the device's locales preferences). There have been some requests to allow specifying the locale to use when presenting the paywall.Description
This PR introduces the
preferredLocale
inPaywallView
. Initially, this parameter is only included under@_spi(Internal)
, but the idea is to make this public in the short term.Notes
Why
preferredLocale
?The SDK can't guarantee that any locale specified by the caller will be available for a specific paywall. That's why the name
preferredLocale
was chosen. To highlight the fact that it will be used for the paywall only when possible. If that locale isn't available for the paywall, then the SDK will fall back to the current behavior of choosing the locale based on the device's locales preferences.