Skip to content

[Paywalls V2] Improves fuzzy matching locale when the region doesn't match#2355

Merged
JayShortway merged 3 commits into
mainfrom
pw2-locale-fuzzy-match-region
Apr 14, 2025
Merged

[Paywalls V2] Improves fuzzy matching locale when the region doesn't match#2355
JayShortway merged 3 commits into
mainfrom
pw2-locale-fuzzy-match-region

Conversation

@JayShortway

@JayShortway JayShortway commented Apr 11, 2025

Copy link
Copy Markdown
Member

Bug

We were still not always properly localizing the paywall when the region doesn't match between the device and the paywall configuration.

Cause

This is caused by the fact that in this scenario we use a LocaleId containing only the language and script, without the region. If we then try to find this LocaleId in the paywall's localizations map, we can't find any, because the localizations map contains a region.

Fix

We use the matched locale ID as it exists in the paywall config, instead of a permutation.

Comment on lines -131 to +136
languageScriptId?.takeIf { javaLocales.any { it.language == language && it.script == script } }
?: languageId.takeIf { javaLocales.any { it.language == language } }
javaLocales.firstOrNull { it.language == language && it.script == script }?.toLocaleId()
?: javaLocales.firstOrNull { it.language == language }?.toLocaleId()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is the fix. Instead of returning our permutation (languageScriptId or languageId) when we find a match, we return the matching paywall locale (unmodified) instead.

// Even though there's an exact language and region match for simplified Chinese, we pick
// traditional Chinese as that has higher device priority.
expected = "zh-Hant",
expected = "zh-Hant-HK",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think this was also actually wrong. We now consistently pick a locale from the paywallLocales.

@codecov

codecov Bot commented Apr 11, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.92%. Comparing base (5d37aae) to head (4b604d2).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2355   +/-   ##
=======================================
  Coverage   79.92%   79.92%           
=======================================
  Files         284      284           
  Lines       10133    10133           
  Branches     1431     1431           
=======================================
  Hits         8099     8099           
  Misses       1418     1418           
  Partials      616      616           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JayShortway JayShortway enabled auto-merge April 14, 2025 06:33
@JayShortway JayShortway added this pull request to the merge queue Apr 14, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 14, 2025
@JayShortway JayShortway added this pull request to the merge queue Apr 14, 2025
Merged via the queue into main with commit 11e0557 Apr 14, 2025
@JayShortway JayShortway deleted the pw2-locale-fuzzy-match-region branch April 14, 2025 08:16
github-merge-queue Bot pushed a commit that referenced this pull request Apr 15, 2025
**This is an automatic release.**

## RevenueCat SDK
### 🐞 Bugfixes
* Add missing response fields to `CustomerInfo`. Including transaction
Prices (#2128) via Cesar de la Vega (@vegaro)

## RevenueCatUI SDK
### Paywallv2
#### 🐞 Bugfixes
* [Paywalls v2] Fixes timeline layout when width is Fit (#2354) via
JayShortway (@JayShortway)
* [Paywalls V2] Improves fuzzy matching locale when the region doesn't
match (#2355) via JayShortway (@JayShortway)
* [Paywalls V2] Norwegian Bokmål and Norwegian Nynorsk fall back to
Norwegian. (#2329) via JayShortway (@JayShortway)
### Customer Center
#### 🐞 Bugfixes
* Clean up on restoring functionality in customer center (#2316) via
Cesar de la Vega (@vegaro)

### 🔄 Other Changes
* [Paywalls v2] Adds the unsupported Background type to the error
message (#2350) via JayShortway (@JayShortway)
* [Paywalls v2] Uses a fixed date for template previews to avoid daily
changes. (#2351) via JayShortway (@JayShortway)
* [Paywalls v2] Adds a default case to `Background` and
`ButtonComponent` (#2347) via JayShortway (@JayShortway)
* [Paywalls v2] Improves `PaywallComponentsTemplatePreviewRecorder`
stability (#2352) via JayShortway (@JayShortway)
* [Paywalls v2] Adds a default case to most enums and sealed types
(#2346) via JayShortway (@JayShortway)
* Adds `EnumDeserializerWithDefault` and `SealedDeserializerWithDefault`
(#2345) via JayShortway (@JayShortway)
* [Paywalls V2] Renders template previews in a fixed resolution using
Paparazzi (#2214) via JayShortway (@JayShortway)
* Bump fastlane from 2.227.0 to 2.227.1 (#2344) via dependabot[bot]
(@dependabot[bot])
* Migrate root gradle file to KTS (#2343) via Jaewoong Eum (@skydoves)
* Migrate tester modules to KTS format (#2340) via Jaewoong Eum
(@skydoves)
* Introduce purchases-bom package (#2339) via Jaewoong Eum (@skydoves)
* [AUTOMATIC][Paywalls V2] Updates paywall-preview-resources submodule
(#2338) via RevenueCat Git Bot (@RCGitBot)
* [Diagnostics] Removes Android 7 requirement (#2335) via JayShortway
(@JayShortway)
* [Paywalls v2] Fixes `update-paywall-preview-resources-submodule` CI
job (#2337) via JayShortway (@JayShortway)
* Make purchases module to transitive dependency for the ui module
(#2334) via Jaewoong Eum (@skydoves)
* Migrate settings.gradle to KTS and add the dependency resolutions
(#2328) via Jaewoong Eum (@skydoves)

Co-authored-by: revenuecat-ops <ops@revenuecat.com>
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.

3 participants