Skip to content
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

Sort lines correct alphabetic sorting with diacritics in Romanian #70920

Closed
akaleeroy opened this issue Mar 21, 2019 · 4 comments
Closed

Sort lines correct alphabetic sorting with diacritics in Romanian #70920

akaleeroy opened this issue Mar 21, 2019 · 4 comments
Assignees
Labels
editor-sorting Issues related to editor sorting functionality. *question Issue represents a question, should be posted to StackOverflow (VS Code)

Comments

@akaleeroy
Copy link

Issue Type: Bug

The correct order when it comes to Romanian diacritics would be a, ă, â, b, c ... i, î ... s, ș, t, ț, u, v ...

Alphabetical order - Wikipedia

But this is the result of Sort Lines Ascending on these lines:

Sălaj
Satu Mare
Sibiu
Suceava

Sălaj should come after Satu Mare

FWIW Sublime Text gets it worse, considering diacritics as continuing after the main latin alphabet: Sălaj comes after Suceava

VS Code version: Code 1.32.3 (a3db5be, 2019-03-14T23:43:35.476Z)
OS version: Windows_NT x64 6.1.7601

@vscodebot vscodebot bot added the editor-contrib Editor collection of extras label Mar 21, 2019
@akaleeroy
Copy link
Author

On the other hand it matches up with the sorting from LibreOffice Calc.

@isidorn
Copy link
Contributor

isidorn commented Mar 22, 2019

Sorting where? Are you talking about the explorer?

@isidorn isidorn added the info-needed Issue requires more information from poster label Mar 22, 2019
@akaleeroy
Copy link
Author

Sort Lines Ascending in the Command Palette.

@isidorn isidorn removed editor-contrib Editor collection of extras info-needed Issue requires more information from poster labels Mar 22, 2019
@bpasero bpasero assigned rebornix and unassigned bpasero Mar 22, 2019
@bpasero bpasero added the editor label Mar 22, 2019
@rebornix rebornix added the under-discussion Issue is under discussion for relevance, priority, approach label Aug 2, 2019
@alexdima
Copy link
Member

alexdima commented Oct 25, 2019

This is actually more complicated than I thought...

The reason is that different locales have different sort orders for the same characters. See a full example at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator

function letterSort(lang, letters) {
  letters.sort(new Intl.Collator(lang).compare);
  return letters;
}

console.log(letterSort('de', ['a','z','ä']));
// expected output: Array ["a", "ä", "z"]

console.log(letterSort('sv', ['a','z','ä']));
// expected output: Array ["a", "z", "ä"]

So there is no absolute order of letters, ordering letters/strings only makes sense in a given locale. We are currently using String.localeCompare. I believe that one falls to the locale defined in the OS, and on your machine I think that is English.

Testing the sorting:

function sort(lang, letters) {
  letters.sort(new Intl.Collator(lang).compare);
  return letters;
}

console.log(sort('en', ["Satu Mare", "Sălaj", "Sibiu", "Suceava"]));
// ==> ["Sălaj", "Satu Mare", "Sibiu", "Suceava"]

console.log(sort('ro', ["Satu Mare", "Sălaj", "Sibiu", "Suceava"]));
// ==> ["Satu Mare", "Sălaj", "Sibiu", "Suceava"]

So under English the sort order is indeed ["Sălaj", "Satu Mare", "Sibiu", "Suceava"], while under Romanian it is ["Satu Mare", "Sălaj", "Sibiu", "Suceava"]

I will change our code to instantiate a Intl.Collator, which is better than String.localeCompare from a performance point of view according to what I learned from MDN, but I think the only way to get the sort order you want is to change your OS locale to Romanian.

@alexdima alexdima assigned alexdima and unassigned rebornix Oct 25, 2019
@alexdima alexdima added editor-contrib Editor collection of extras *question Issue represents a question, should be posted to StackOverflow (VS Code) and removed editor under-discussion Issue is under discussion for relevance, priority, approach labels Oct 25, 2019
@vscodebot vscodebot bot locked and limited conversation to collaborators Dec 9, 2019
@hediet hediet added editor-sorting Issues related to editor sorting functionality. and removed editor-contrib Editor collection of extras labels Oct 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
editor-sorting Issues related to editor sorting functionality. *question Issue represents a question, should be posted to StackOverflow (VS Code)
Projects
None yet
Development

No branches or pull requests

6 participants