392
Views
11
Comments
Solved
ListSort and collation
Question

Hi,

is it possible to include collation when sorting programmatically, i.e. using ListSort or SortRecordList?

An example. Let's consider two names: "Bak" and "Bal". I'd like to sort them using Polish collation (as in MS SQL: Polish_CI_AS). When querying them from a database, using SQL and explicit collate (just to be independent of the column's collation), I get the proper order: Bal, Bak. But when I sort the obtained list using ListSort, I get the improper order: Bak, Bal.

Any suggestions?

Regards

Tomasz

UserImage.jpg
Tomasz M Lipinski
Solution

Hi Kilian,

If it doesn't work for you I guess you set only Thread.CurrentThread.CurrentCulture. This doesn't work for me, too. I think that every call to an extension's method creates a new thread that starts with system locale settings.

But if you set also (or: instead) CultureInfo.DefaultThreadCurrentCulture, every consecutive call (and its thread) uses this culture instead of the system one.

Fortunately all extensions work in the same application domain and the above trick works also between different extensions. Therefore my sorting (now) works.

Thanks for the inspiration!

Regards

Tomasz


2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Tomasz,

I assume that ListSort uses the default collation for the current locale, which will probably be en-US. Assuming the ListSort is implemented in .NET, did you try to set the current locale in an extension and see what happens with the ListSort?

Perhaps a bit off-topic, but Polish sorts l before k?

UserImage.jpg
Tomasz M Lipinski

Hi Kilian,

Current application's locale is set to pl-PL. ListSort is the OS's system action. If the current locale doesn't go into extensions (and especially - into the system one), I'm a little bit helpless.

In Polish the order is: k first, then l. But also: a first, then a.  Therefore Bal should be before Bak.

Regards

Tomasz

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Tomasz,

There's the locale that the Platform uses, but that's not the locale that .NET uses. We have a number of formatting Actions in an extension, and we also have a "SetLocale" Action in that extension, since the Platform locale is not the .NET locale.

As for ordering, it seems Unicode characters get stripped or something, weird...

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

(Testing: éèëüal??????ecš??e?t?)

UserImage.jpg
Tomasz M Lipinski

Kilian,

As I understand, you suggest that I should make my own copy of e.g. SortRecordList, this time with Locale parameter, don't you? 

Tomasz


2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Tomasz,

No, I suggest you create an extension with an Action that sets the .NET locale, and see whether it affects the built-in ListSort.

EDIT: I tried it myself, but it doesn't seem to work :(

UserImage.jpg
Tomasz M Lipinski
Solution

Hi Kilian,

If it doesn't work for you I guess you set only Thread.CurrentThread.CurrentCulture. This doesn't work for me, too. I think that every call to an extension's method creates a new thread that starts with system locale settings.

But if you set also (or: instead) CultureInfo.DefaultThreadCurrentCulture, every consecutive call (and its thread) uses this culture instead of the system one.

Fortunately all extensions work in the same application domain and the above trick works also between different extensions. Therefore my sorting (now) works.

Thanks for the inspiration!

Regards

Tomasz


2019-09-24 18-41-25
Jorge Martins
 
MVP

Hi Tomasz,

Just from reading your use case for this, if feels like lots of other people might be facing this same challenge. Would you consider publishing your extension to the Forge? For all us special-character-impaired countries it would be a great tool to have under the belt!

Thanks!

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Tomasz,

Great to hear you got it solved! And I indeed only set the CurrentThread, not the DefaultThread, so that explains it all.

UserImage.jpg
Tomasz M Lipinski

Hi,

I've created a new support case by OS Support Center. Let's wait for their conclusions.

Regards

Tomasz

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.