Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special Characters Sorting Issue on Sections #1913

Closed
afbora opened this issue Jul 12, 2019 · 6 comments

Comments

@afbora
Copy link

commented Jul 12, 2019

I'm using Turkish language and there are some special characters in our language (Ç,Ğ,İ,Ö,Ş,Ü).
If title or sorting field have these characters, sorting not working properly.

Blueprint

customSection:
    type: pages
    headline: Custom Section
    sortBy: title asc

Screenshots
FireShot Capture 704 - PixelShop - http___pixelshop com_panel_site

Expected sort

  1. Katalog
  2. Kategoriler
  3. Özellikler
  4. Üretici Firmalar
  5. Yorumlar

Tried following setting locales but I didn't get the result I expected:

return [
    ...
    'locale' => [
        'tr_TR'
    ]
    ...
];

return [
    ...
    'locale' => [
        LC_ALL  => 'tr_TR.utf-8',
    ],
    ...
];

Kirby Version
3.2.2

Desktop:

  • Windows 10
  • Chrome 75.0.3770.100 (64 bit)
@lukasbestle

This comment has been minimized.

Copy link
Contributor

commented Jul 12, 2019

PHP's array_multisort() function, which we use internally for sorting, doesn't respect the locale by default. It has a special flag called SORT_LOCALE_STRING for that. We don't pass it by default because it caused all sorts of issues in the past and therefore should only be used explicitly by the user.

Please try the following (where the 5 is the internal PHP value of SORT_LOCALE_STRING):

customSection:
    type: pages
    headline: Custom Section
    sortBy: title 5
@afbora

This comment has been minimized.

Copy link
Author

commented Jul 12, 2019

Yes, I have the same problem with different methods for Turkish characters (strtolower, ucfirst, ucwords, etc..)

I have tested like your said but nothing happened. I tried following formats:

sortBy: title 5
sortBy: title asc 5
sortBy: title SORT_LOCALE_STRING
sortBy: title asc SORT_LOCALE_STRING

To give you an idea; only worked for sortBy: title asc when I changed this line:

https://github.com/getkirby/kirby/blob/master/src/Toolkit/Collection.php#L922

with that:

$params[] = $field['flags'] ?? SORT_LOCALE_STRING; // works great

As I understand that the number 5 we set doesn't reach the last condition to #L911

lukasbestle added a commit that referenced this issue Jul 12, 2019

@lukasbestle lukasbestle self-assigned this Jul 12, 2019

@lukasbestle lukasbestle added this to the 3.2.3 milestone Jul 12, 2019

@lukasbestle

This comment has been minimized.

Copy link
Contributor

commented Jul 12, 2019

Ah, yes. The blueprint option is only converted to a string and not to the numeric value of the constant. I have now implemented this feature in #1916, so you should be able to use any of these two variants:

sortBy: title SORT_LOCALE_STRING
sortBy: title asc SORT_LOCALE_STRING

Please let me know if it works for you.

@afbora

This comment has been minimized.

Copy link
Author

commented Jul 12, 2019

Works perfect! 👍

sortBy: title SORT_LOCALE_STRING
sortBy: title asc SORT_LOCALE_STRING
@lukasbestle

This comment has been minimized.

Copy link
Contributor

commented Jul 12, 2019

Thanks for checking, will be in the next release. :)

bastianallgeier added a commit that referenced this issue Jul 29, 2019

@bastianallgeier

This comment has been minimized.

Copy link
Contributor

commented Jul 29, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants
You can’t perform that action at this time.