codemaid icon indicating copy to clipboard operation
codemaid copied to clipboard

Add option to override system locale for sorting

Open pavel-machyniak opened this issue 4 years ago • 2 comments

Environment

  • Visual Studio version: Microsoft Visual Studio Professional 2019/16.11.2
  • CodeMaid version: 11.2
  • Code language: C++

Description

When I want to sort chunk of lines, eg.:

current
changes
case

I end up with this result:

case
current
changes

And I would expect this:

case
changes
current

I think the issue is due to the fact that my Windows has locale setup for Slovakia/Slovak language, where ch is treated as special letter with ordering between h and i. I do not want to change my Windows locale for this to work correctly. I would like to have a setting for codemaid, where I can override default system locale.

Steps to recreate

  1. Setup Windows locale for Slovakia/Slovak language
  2. Type following lines into c++ file:
current
changes
case
  1. Select the block
  2. Let codemaid to do the sorting of the block

Current behavior

Lines are in this order:

case
current
changes

Expected behavior

I would like to have it sorted as in english locale:

case
changes
current

Thanks

pavel-machyniak avatar Sep 09 '21 21:09 pavel-machyniak

Thanks for the suggestion. We do leverage StringComparison.CurrentCulture for sorting and in a few other places. It seems like for most users we would want to stick to that option but in your case you would want a configuration option to set that to StringComparison.InvariantCulture?

https://github.com/codecadwallader/codemaid/blob/dev/CodeMaid/Integration/Commands/SortLinesCommand.cs#L117

codecadwallader avatar Sep 24 '21 11:09 codecadwallader

Thanks for the reply. I think StringComparison.InvariantCulture would not help, it probably applies only more rules. Instead I would like to have an option to specify the culture (via GUI, registry, ...) and use it instead of the default CurrentCulture:

myCulture = "en-US";
...
StringComparison.CurrentCulture = CultureInfo.CreateSpecificCulture(myCulture);

pavel-machyniak avatar Sep 27 '21 08:09 pavel-machyniak