Closed
Bug 1209135
Opened 10 years ago
Closed 10 years ago
[Music][NGA] Switch sorting logic to use String.prototype.localeCompare()
Categories
(Firefox OS Graveyard :: Gaia::Music, defect)
Tracking
(Not tracked)
RESOLVED
FIXED
People
(Reporter: justindarc, Assigned: squib)
References
Details
Attachments
(1 file)
For a better l10n experience, String.prototype.localeCompare() should be used. This should provide correct, locale-specific sorting and should also sort numbers correctly (e.g. 1, 2, ... 10 vs. 1, 10, 2, ... ).
| Reporter | ||
Comment 1•10 years ago
|
||
Assigning to :squib.
Setting NI? for :gandalf regarding usage of String.prototype.localeCompare(). Do we need to get the current locale somehow to use String.prototype.localeCompare()? Or does it automatically detect the current locale?
Comment 2•10 years ago
|
||
The pattern we use is to pass `navigator.languages` to it. In the future we may want to pass document.l10n.languages or sth similar (the difference being - navigator.languages knows languages requested by the user, document.l10n.languages would know languages that were resolved by language negotiation and ones that we actually use).
The interesting bits for you will be about IntlHelper. If you compare in a loop, using localeCompare will not be fast [0].
It's better to create an Intl.Collator object and then use it on the strings.
IntlHelper will help you cache the collator and allow you to easily define the observer on a function to be fired when the object is reset. (Currently we reset Collator only on languageschange, but we may add more triggers in the future).
[0] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#Performance
Flags: needinfo?(gandalf)
Comment 8•10 years ago
|
||
| Assignee | ||
Updated•10 years ago
|
Attachment #8669095 -
Flags: review?(jdarcangelo)
| Reporter | ||
Comment 10•10 years ago
|
||
Comment on attachment 8669095 [details] [review]
[gaia] jimporter:music-sort > mozilla-b2g:master
Overall looks good! Nice cleanup as well. See my nits in the PR as well as some directions for rebasing the additional script loading.
Attachment #8669095 -
Flags: review?(jdarcangelo) → review+
| Assignee | ||
Comment 11•10 years ago
|
||
Forgot to resolve this. Landed: https://github.com/mozilla-b2g/gaia/commit/2a5f1f2819c05bb3d8e5a732d18be1739f66bc76
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•