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

Paywalls: improve PaywallData.config(for:) disambiguation #3605

Merged
merged 3 commits into from
Jan 29, 2024

Conversation

NachoSoto
Copy link
Contributor

@NachoSoto NachoSoto commented Jan 26, 2024

This fixes an issue with PaywallData picking the wrong Locale when the configuration has multiple translations sharing the same language code.

The fix replaces comparing Language.languageCode with the smarter Language.isEquivalent(to:).

Other changes:

  • Removed the duplicate zh_TW since it was the same as zh_Hant (we don't have that specific language in the dashboard either)
  • Added configuration to be able to test this on PaywallsTester
  • Renamed zh_HK to zh_Hant for consistency with Hans

Simulator Screenshot - iPhone 15 Pro Max - 2024-01-26 at 12 57 29
Simulator Screenshot - iPhone 15 Pro Max - 2024-01-26 at 11 17 14

This fixes an issue with `PaywallData` picking the wrong `Locale` when the configuration has multiple translations sharing the same language code.

The fix replaces comparing `Language.languageCode` with the smarter `Language.isEquivalent(to:)`.

### Other changes:
- Removed the duplicate `zh_TW` since it was the same as `zh_Hant`. This is covered in tests too.
- Added configuration to be able to test this on `PaywallsTester`
- Renamed `zh_HK` to `zh-Hant` for consistency with `Hans`
@NachoSoto NachoSoto requested a review from a team January 26, 2024 19:22
@@ -524,7 +524,7 @@ private extension Locale {

func sharesLanguageCode(with other: Locale) -> Bool {
if #available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) {
return self.language.languageCode == other.language.languageCode
return self.language.isEquivalent(to: other.language)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the core of the fix.

@NachoSoto NachoSoto force-pushed the paywallsls-chinese-localization branch from b643af8 to 54f70c5 Compare January 26, 2024 20:02
NachoSoto added a commit to RevenueCat/purchases-android that referenced this pull request Jan 26, 2024
iOS equivalent: RevenueCat/purchases-ios#3605

See also https://medium.com/fabiohub/chinese-locale-in-android-part-2-d1cfe87b3fb2:

> In order to support zh-rHK, zh-rHK_#Hant and zh-rHK_#Hans to fall back correctly on both pre & post Android 7.0 devices, you need these resources:
- `zh-rHK` (Traditional Chinese)
- `zh-rTW` (Traditional Chinese)
- `zh` (Simplified Chinese)
NachoSoto added a commit to RevenueCat/purchases-android that referenced this pull request Jan 26, 2024
iOS equivalent: RevenueCat/purchases-ios#3605

See also https://medium.com/fabiohub/chinese-locale-in-android-part-2-d1cfe87b3fb2:

> In order to support zh-rHK, zh-rHK_#Hant and zh-rHK_#Hans to fall back correctly on both pre & post Android 7.0 devices, you need these resources:
- `zh-rHK` (Traditional Chinese)
- `zh-rTW` (Traditional Chinese)
- `zh` (Simplified Chinese)
NachoSoto added a commit to RevenueCat/purchases-android that referenced this pull request Jan 26, 2024
iOS equivalent: RevenueCat/purchases-ios#3605

See also https://medium.com/fabiohub/chinese-locale-in-android-part-2-d1cfe87b3fb2:

> In order to support zh-rHK, zh-rHK_#Hant and zh-rHK_#Hans to fall back correctly on both pre & post Android 7.0 devices, you need these resources:
- `zh-rHK` (Traditional Chinese)
- `zh-rTW` (Traditional Chinese)
- `zh` (Simplified Chinese)
@NachoSoto NachoSoto enabled auto-merge (squash) January 29, 2024 15:12
@NachoSoto NachoSoto merged commit b0b7afb into main Jan 29, 2024
24 checks passed
@NachoSoto NachoSoto deleted the paywallsls-chinese-localization branch January 29, 2024 16:47
NachoSoto pushed a commit that referenced this pull request Jan 30, 2024
**This is an automatic release.**

### RevenueCatUI
* `Paywalls`: fix template 5 scrolling on iOS 15 (#3608) via NachoSoto
(@NachoSoto)
* `Paywalls`: improve `PaywallData.config(for:)` disambiguation (#3605)
via NachoSoto (@NachoSoto)
### Dependency Updates
* Bump cocoapods from 1.14.3 to 1.15.0 (#3607) via dependabot[bot]
(@dependabot[bot])
* Bump fastlane-plugin-revenuecat_internal from `e6ba247` to `9c82c7a`
(#3606) via dependabot[bot] (@dependabot[bot])
### Other Changes
* `Integration Tests`: disable failure expectation on `iOS 17.4` (#3604)
via NachoSoto (@NachoSoto)
NachoSoto added a commit that referenced this pull request Feb 5, 2024
This was a regression introduced by #3605.

### Example:

Consider a paywall configuration with these locales: `en_US`, `de_DE`.
Running on a device with locale `en_IN` for example.

Before #3605, `PaywallData.localizedConfiguration` would have returned the `en_US` localization. However, that change made it so that it could no longer find a matching localization with a different region.'

This fix improves the locale lookup so that if it doesn't find a matching localization with both language AND region, it then tries to look it up with only the language, before falling back to the default localization.
NachoSoto added a commit that referenced this pull request Feb 5, 2024
This was a regression introduced by #3605.

### Example:

Consider a paywall configuration with these locales: `en_US`, `de_DE`.
Running on a device with locale `en_IN` for example.

Before #3605, `PaywallData.localizedConfiguration` would have returned
the `en_US` localization. However, that change made it so that it could
no longer find a matching localization with a different region.

This fix improves the locale lookup so that if it doesn't find a
matching localization with both language AND region, it then tries to
look it up with only the language, before falling back to the default
localization.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants