Use FormatJS Intl.Collator polyfill to fix missing locales in Chromium (e.g. "se") - #2025
Conversation
1 new issue
|
| // fall back to non-numeric sort to ensure a consistent order | ||
| return strA.localeCompare(strB, lang, { sensitivity: 'variant' }) | ||
| return this.$fallbackCollator.compare(strA, strB) | ||
| } |
…ing locales in Chromium
33e4f01 to
daa8d8a
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2025 +/- ##
=========================================
Coverage 70.42% 70.42%
Complexity 1703 1703
=========================================
Files 34 34
Lines 4436 4436
=========================================
Hits 3124 3124
Misses 1312 1312 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds a client-side Intl.Collator polyfill path to fix incorrect concept sorting for locales missing in Chromium (e.g. se), and updates the hierarchy sidebar sorting to use Intl.Collator instances.
Changes:
- Add
@formatjs/intl-collatornpm dependency. - Load the Collator polyfill via dynamic
import()and expose a global readiness Promise. - Replace
localeCompare()sorting in the hierarchy sidebar with sharedIntl.Collatorinstances and wait for the polyfill before starting the app.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/view/scripts.inc.twig |
Adds import map + module loader that conditionally imports the FormatJS Collator polyfill and exposes window.intlCollatorReady. |
resource/js/tab-hierarchy.js |
Switches hierarchy sorting to use $collator.compare() and waits for the polyfill Promise before starting. |
package.json |
Adds @formatjs/intl-collator dependency. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
UnniKohonen
left a comment
There was a problem hiding this comment.
Collation seems to be working correctly in Chrome. Moving the polyfill code to a separate file would make scripts.inc a little cleaner but it's not necessary IMO. Error handling in tab-hierarchy.js suggested by copilot should probably be implemented but otherwise this implementation seems fine to me.
Maybe the existence of #tab-hierarchy in DOM could be checked before loading the polyfill if you haven't tried that already.
…thout the hierarchy (e.g. landing page)
I've now made the polyfill loading even lazier: it will only be loaded if the hierarchy initialization code needs it. This means that it will not be loaded on e.g. the landing and feedback pages which don't have a hierarchy element. |
Reasons for creating this PR
The hierarchy sidebar does not sort concepts correctly in Northern Sami locale (se) on Chromium based browsers, see #2016. This PR fixes the issue by using the Intl.Collator polyfill from FormatJS which can be used to retrofit wider locale support to JavaScript environments. The polyfill is quite heavy and it is only loaded when actually needed: in my tests using Chromium, it will be loaded when the content language is set to Northern Sámi and the page includes a hierarchy sidebar (even if it's not the currently active tab). In all other cases (e.g. Firefox browser, a content language other than Northern Sámi, or a page without the hierarchy tab), the polyfill will not be loaded at all!
Link to relevant issue(s), if any
Description of the changes in this PR
formatjs/intl-collatoras a dependency managed by npmKnown problems or uncertainties in this PR
src/view/scripts.inc.twigor would it be better to move it into its own small.jsfile?Checklist
.sr-onlyclass, color contrast)