In Korean some problem on sortBy('title', 'asc')

Hello, I’m trying to make a website with Kirby. All contents are Korean. In some pages, I want to sort all titles by Korean alphabetical order. But sortBy(‘title’, ‘asc’) is not working on my localhost. It is sorted by only English alphabetical order. In addition, in panel sort: title asc, too. I don’t know why. Am I missing something?

Have you tried setting the locale option to Korean? PHP doesn’t know that you are trying to sort in Korean otherwise.

1 Like

The same problem on the Russian (Cyrillic). The locale is set.

1 Like

Thank you for a reply.

Yes. I tried already like this:

c::set('locale', 'ko_KR.UTF8');

or

c::set('locale', array(
  LC_COLLATE  => 'ko_KR.UTF8',
  LC_MONETARY => 'ko_KR.UTF8',
  LC_NUMERIC  => 'ko_KR.UTF8',
  LC_TIME     => 'ko_KR.UTF8',
  LC_MESSAGES => 'ko_KR.UTF8',
  LC_CTYPE    => 'ko_KR.UTF8'
));

But it’s not working, unfortunately. For your information, I’m using MAMP on my localhost.

Anyone knows?

1 Like

I think some (?) Russian users have similar problem. After this, I tested with Japanese, but it works perfectly without setting locale. That’s interesting.

I was trying to translate Kirby’s panel in Korean, and It’s almost done. I think I have to wait until this puzzle is solved. If this is a bug, I hope it will be fixed soon.

Should I return to Wordpress? I hope I don’t.

To be honest I don’t have much experience with sorting non-ASCII strings in PHP. But if Japanese works and Korean/Russian doesn’t, that would definitely be a PHP issue as Kirby doesn’t have any special treatment for Japanese. So WordPress will have the same issue. :wink:

Translating Kirby to Korean: That’s very awesome, we are looking forward to your translation! :slight_smile:

1 Like

I think I found the reason.

/kirby/toolkit/lib/collection.php (line 343) str::ascii

${"param_$i"}[$index] = str::ascii(is_array($row) ? str::lower($row[$param]) : str::lower($row->$param()));

If replaced by

${"param_$i"}[$index] = str::lower(is_array($row) ? str::lower($row[$param]) : str::lower($row->$param()));

That Russian sorts correctly (in panel sort also correctly).

@eb3ha4 try to check out this solution for the Korean.

@bastianallgeier to check this, plz.

1 Like

Amazing! Thanks to you.

It works without setting locale. I don’t know why exactly, though. I wonder the difference between str::ascii and str::lower. @lukasbestle

Thanks. I hope to share the translation soon, too.

Anyway, I think the problem is solved, right?

Only not use it! We do not know that this may break elsewhere. Let’s wait what will they say developers.

1 Like

As far as I know str::ascii was used to fix issues with sorting strings containing umlauts or accents.

1 Like

I just fixed this on the develop branch and it will be in 2.4.1

1 Like