-
Notifications
You must be signed in to change notification settings - Fork 382
Improve resolution of locale in paywalls components localizations #5316
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
Conversation
…s components The new implementation uses the API `Bundle.preferredLocalizations(from:forPreferences:)`
@RCGitBot please test |
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.
So much simpler! Just a request for 1 more test.
/// Returns the elements in `identifiers` that best match the any language in `preferredLanguages` | ||
/// (i.e. same language code), sorted by best match. | ||
/// | ||
/// This method takes into account the order of `preferredLanguages` to determine the best match. | ||
/// E.g. | ||
/// if `preferredLanguages` is `["en-US", "es-ES"]`, then the identifier `en-GB` | ||
/// will be preferred over `es-ES`. | ||
/// | ||
/// - important: As specified in the documentation of `Bundle.preferredLocalizations(from:forPreferences:)` | ||
/// "_This method doesn’t return all localizations in order of user preference. To get this information, | ||
/// you can call this method repeatedly, each time removing the identifiers returned by the previous call._" | ||
/// This means that not all matches will be returned, but only the best ones based on `preferredLanguages`. |
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'm a bit confused by these 2 statements:
[...] sorted by best match.
and
[...] doesn’t return all localizations in order of user preference.
They seem to contradict each other, but I'm probably misunderstanding.
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.
You're right that it's confusing. I'll rephrase that.
Anyway, I'm struggling a lot when trying to explain it because what the method Bundle.preferredLocalizations(from:forPreferences:)
returns is also very confusing! 😅
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.
Simplified implementation and documentation in d761e7f
func test_es_MX_Matches_es_before_es_ES() { | ||
let localizations = [ | ||
"en": ["wrong": "this is en"], | ||
"es_ES": ["wrong": "this is es_ES"], | ||
"es": Self.expectedTranslations | ||
] |
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.
Could we add another test to check that es_MX
matches es_ES
if that's the only available Spanish language?
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.
Makes sense! Done in be52a72
This is closely related to #5309, as the solution in that PR was not correct.
Checklist
Motivation
Before this PR, the SDK would have a custom implementation to resolve the best locale from
ui_config.localizations
based on a paywall's locale. This would cause some bugs:es_MX
was not being matched withes_419
(see Fix paywall locale receiving UN M.49 standard localization #5309)Locale
(ex:zh_CN
will look forzh_Hans
) #4870)Description
This PR now uses the system's
Bundle.preferredLocalizations(from:forPreferences:)
API, which takes care of these special cases for us.