ListSort and collation

ListSort and collation

  

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

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?

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

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...

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

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


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 :(

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


Solution

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!

Hi Tomasz,

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

Hi,

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

Regards

Tomasz