-
-
Notifications
You must be signed in to change notification settings - Fork 484
Restructure Intl implementation to use ICU4X's locale preferences #4589
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
c1c339c to
796ca0b
Compare
Test262 conformance changes
Fixed tests (1): |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4589 +/- ##
==========================================
+ Coverage 47.24% 56.50% +9.26%
==========================================
Files 476 547 +71
Lines 46892 60036 +13144
==========================================
+ Hits 22154 33926 +11772
- Misses 24738 26110 +1372 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| result | ||
| } | ||
|
|
||
| fn intersection(&self, other: &Self) -> Self { |
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.
Preferences have a merge operation already
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.
This the opposite though; it takes two preference objects and gets the preferences that are the same in both.
We need this because ECMA402 requires correctly setting up the locale with the extensions that were "used" by the locale resolution algorithm. Here I implemented that by first extending the locale prefs with the option prefs, then taking the intersection of the full prefs with the locale prefs to see which ones were not changed.
| }); | ||
| } | ||
|
|
||
| fn as_unicode(&self) -> unicode::Unicode { |
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 think in some cases we have impl From Preferences for 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 also thought that, but after looking at the preferences code, it seems like it was commented out:
https://github.com/unicode-org/icu4x/blob/5fb31d7ae061d304088f1e79897f7435f1846da6/components/locale_core/src/preferences/mod.rs#L519-L533
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.
Probably there just wasnt a need for it yet.
| fn validate(&mut self, id: &LanguageIdentifier, provider: &IntlProvider) { | ||
| self.collation_type = self.collation_type.take().filter(|co| { | ||
| let attr = DataMarkerAttributes::from_str_or_panic(co.as_str()); | ||
| co != &CollationType::Search |
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.
Good, this is Ecma specific functionality so it should be here in boa
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.
Yep, extension validation like this seems to be a good candidate for a future "icu4x-ecma402" glue crate
A pending task after migrating to ICU4X 2.0 was to use the newly introduced locale preferences to clean up our Intl implementation. This PR takes care of that by introducing the
ServicePreferencestrait and removing theService::resolvemethod, which makes the code much more modular overall.cc @sffc, it might be interesting to see if we can upstream parts of the
ServicePreferencestrait, likeas_unicodeorintersection.