Bug 168175 - natural sort does not use the locale of the sort descriptor
Summary: natural sort does not use the locale of the sort descriptor
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
26.2.0.0 alpha0+ master
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: target:26.2.0
Keywords: implementationError
Depends on:
Blocks: Sorting
  Show dependency treegraph
 
Reported: 2025-08-29 12:46 UTC by Regina Henschel
Modified: 2025-09-13 21:37 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
Spreadsheet with database range for testing (10.51 KB, application/vnd.oasis.opendocument.spreadsheet)
2025-08-29 12:46 UTC, Regina Henschel
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Regina Henschel 2025-08-29 12:46:30 UTC
Created attachment 202580 [details]
Spreadsheet with database range for testing

Open attached document. Select Database Range "myData". Start "Sort" dialog and go to "Options" page. Enable "Enable natural sort" and select "German (Germany)" as language. OK. Make a note of the sorting result. Again start "Sort" dialog and now set language to "English (USA)" on page "Options". "Enable natural sort" should still be enabled. OK. Compare the sort result with the previous one.
Error: The results are identical.
The source
    Item
    K2,5
    K2,501
    K1,104
    K1,2
    K2,40
should result in
    Item
    K1,104
    K1,2
    K2,40
    K2,5
    K2,501
in a German locale, because the comma is decimal separator and thus the source is interpreted as
    K  2,5
    K  2,501
    K  1,104
    K  1,2
    K  2,40

The result should be
    K1,2
    K1,104
    K2,5
    K2,40
    K2,501
in an English locale, because the dot is decimal separator and thus the comma is interpreted as ordinary character and the source is interpreted as
    K  1  ,  104
    K  1  ,  2
    K  2  ,  40
    K  2  ,  5
    K  2  ,  501

Go to Tools > Options > Languages and Locales > General and in section 'Formats' set field 'Locale setting' to 'German(Germany)'. Then open the attached document, select the database range and enable natural sort. OK. Now you get the German sort result.

Now set 'Locale setting' to 'English (USA)' in Tools > Options and open the attached document. Select the Database Range and enable natural sort. OK. Now you get the English sort result.

Error: It doesn't matter, whether the language in the sort dialog is set to 'German' or 'English' or is 'Default'. The result always uses the global setting.

Expected behavior: If the language is set in the sort dialog, then that language has to be used for the decision about the decimal separator. Only if the language is not set in the dialog, that is the field has 'Default', then the global locale is used.

The setting 'Enable natural sort' is not saved to file. Therefore you need to enable it each time you load the document. That is bug 161948.


The local of a sort is given as attributes table:country, table:language, table:script and table:rfc-language-tag in element <table:sort>> in ODF.
https://docs.oasis-open.org/office/OpenDocument/v1.4/cs01/part3-schema/OpenDocument-v1.4-cs01-part3-schema.html#__RefHeading__1415678_253892949
LibreOffice reads and writes it correctly.

These infos are bundled in property "CollatorLocal" (SC_UNONAME_COLLLOC) in LibreOffice API and located in struct css::table::TableSortField.
Comment 1 m_a_riosv 2025-08-29 21:03:38 UTC
Reproducible
Version: 26.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 77b3fe6e8564ea579d8e9a5fc82c5eadf532072e
CPU threads: 16; OS: Windows 11 X86_64 (build 26100); UI render: Skia/Raster; VCL: win
Locale: de-DE (es_ES); UI: en-US
Calc: CL threaded
Comment 2 Commit Notification 2025-09-11 06:56:18 UTC
Regina Henschel committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/b0732e1ba9944a07aed737dcc52ef9e7614c38df

tdf#168175 Use sort parameter language in natural sort

It will be available in 26.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.