Joplin: Implement locale based sorting for notebooks

Created on 5 Feb 2020  ·  25Comments  ·  Source: laurent22/joplin

When a notebook is sorted by title, special chars like the German “ä”, “ö”, “ü” are placed at the very end of the list e.g.

wasser
zweifel
äpfel

They should be handled like normal char e.g. ä => a while sorting notebooks:

affe
äpfel
bett

bug desktop good first issue

All 25 comments

@laurent22 I saw you labeled this issue with "desktop".

I'm facing this problem on my Mac, but also on my iPhone (iOS 13.3.1, Joplin 10.0.43). I'm running both operating systems in English.

If it's fixed for desktop, it will be fixed for mobile as the code is shared.

They should be handled like normal char e.g. ä => a while sorting notebooks:

affe
äpfel
bett

Wrong. The sorting should be language specific.

For example:

In the Swedish alphabet, there are three extra vowels placed at its end (..., X, Y, Z, Å, Ä, Ö), similar to the Danish and Norwegian alphabet, but with different glyphs and a different collating order. The letter "W" has been treated as a variant of "V", but in the 13th edition of Svenska Akademiens ordlista (2006) "W" was considered a separate letter.

Should it then be checked from the operating system what keyboard layout/language the user has selected?

Well it should be sorted according to the locale obviously. I didn't mean to hard code a specific order just for German or whatever language.

Can I work on this issue? @laurent22

Yes sure, please go ahead.

Of course @Perkolator is right, it should be a solution that works for all languages, not just German.

I would prefer if the settings could be used to control how sorting is done. Using the keyboard as a reference is bad for those who change language frequently.

Unfortunately, I can't see the last message from @rheo-chiti here which I got by email...

I think @rheo-chiti has the same problem as me. But he reversed the sorting. "wasser" is in the alphabet before "zweifel"...

I searched for various methods to sort special character strings and got this Intl.Collator as a good inbuilt function to sort based on locales language.
notes.sort(new Intl.Collator(locale).compare);
Here locale will be language selected by user in configuration settings.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator

That sounds reasonable to me. I use array.sort(key=locale.strxfrm) in Python to sort lists with special characters (https://docs.python.org/3/library/locale.html).

If the value can be read out by an application, the language setting of the system could be used as default.

If the value can be read out by an application, the language setting of the system could be used as default.

Hmm. Are you sure that would work as expected? For example, I have "English (United States)" as the system language but "Finnish" as the keyboard layout/input method.

Should we sort on the basis of language selected by user in configuration settings?
@Perkolator

I have selected "English US" (or UK, both seem to be same, sort wise) from Joplin settings. I created the following notes and the sorting for my language (..., X, Y, Z, Å, Ä, Ö) isn't exactly correct:

Zzz
Äää
Ååå
Ööö

Forgot to add: personally I'm not troubled that much of that little sorting error (for my language), at least the special characters are sorted in the end of the alphabets. I just put that example here for being precise about this.. in case somebody wants to fix this sorting thing correctly for all. :)

@laurent22 I tried solving this issue for mobile and found out that Intl.Collator and locale don't work correctly for android(for ios it works fine),can you give some other direction on how to solve this issue?

@tessus I looked at your PR #2453 and I’m thinking of using the same approach to solve this issue, I’ve been spending quite some time looking for where to start from and but for some reason I’m not seeing a starting point, can you please point out a file I should focus on to start working on this issue?, that will be very helpful, thanks

I've clarified that what we want is "locale based sorting" (which is different from natural sort order).

Thanks for the clarification @laurent22, you also mentioned that the code for this is shared, so if it’s solved for Desktop, it’s solved for mobile. Can you show me the file/functions that contains the code to be modified

The sorting itself should be done in models/Folder.js. On the UI, you would look at SideBar.jsx to see how it gets the list of folders.

Thanks a lot @laurent22 , this a very helpful information.

@Runo-saduwa are you working on this issue?

Not yet, please go ahead, im working on another issue

@coderrsid are you working on it ?

Was this page helpful?
0 / 5 - 0 ratings