Alphabetical sorting for different locale, possible?

Hello, my tattoo site is using dynamic locale for czech and international visitors. I'm having album directories in english and so in english "version" they are sorted correctly (like "american, ankle, back, celtic .. etc.), but switched to czech, the sorting looks like .. kind of "completely unsorted" ;-)

I'm wondering if there's a way how to sort albums custom by language. It doesn't need to rely on dynamic locale, just the different locale, as I'm thinking now.

Any ideas please?

As I do research, it could be somehow done by selecting TITLE from albums SQL table, as follows example: "a:3:{s:5:"cs_CZ";s:6:"anděl";s:5:"en_US";s:5:"angel";s:5:"nl_NL";s:5:"engel";}"

but before I start coding my "patch", as I'm not very skilled coder, isn't there any other solution?

Many thanks
Filip

Comments

  • acrylian Administrator, Developer
    You can sort by title. I suggest you try the current release first before trying anything since you are using 1.2.8.

    If you think sorting does not work correctly with 1.3 as well please open a ticket.

    Besides if you are using the multilingual you can't sort by a query using the title field as that is serialized (as you posted).
  • Wow, it's working now. I found the menu option and had it set right. The confusion was made probably by czech translation where one was "name" and second was "title". This is great, it makes the gallery much more clean, sorted now ;-)

    Anyway I'm having another issue to solve now - it put's diacritical beginning characters in front of all instead of where it belongs.

    But I understand this is regional issue. Anyway any idea how to solve it by hardrecoding somewhere?

    Thanks
    ps: I'm going to upgrade to 1.3 asap, just have to make some backups and testing, etc.
  • There are some issues with sorting strings with some diacritical characters. I am afraid we do not yet know of a solution to the issue. Seems not to be a sort that does both "natural" order and handles diacritical characters.
  • I'll try to do some research about this, as in my language this must have been solved elsewhere for sure. To make it easier for me, can you point me to the section of code (which file?) where this sorting is being done?
  • There is a function named `sortByMultilingual()` in functions.php which is used for the title sorts. However, there are other places where this solution would be needed--for instance, sorting the Tags. There is a parameter for normal sorts, `SORT_LOCALE_STRING` that handles this, but with these sorts, numbers are not sorted the way people expect. (Orders end up like 1,10,2,3...)
  • Ok, I'll try to do some research and local consultations about this.
  • Good news everyone. Solved ;-)

    This function used after natcasesort on $temp make it right for czech language. Unfortunately this is language specific.

    <?php

    // sada funkci pro ceske razeni
    //
    // moodlecscoll_sort (&$array)
    // moodlecscoll_charat ($string, $index)
    // moodlecscoll_strcoll ($a, $b)

    /**
    * Setridi pole predane jako parametr se zachovanim klicu podle ceskeho
    * lexikografickeho trideni bez ohledu na velikost pismen
    *
    * Funkce nic nevraci, primo zmeni pole predane referenci!
    *
    * @param array[string] &$array pole stringu v UTF-8 k setrideni, predava se referenci a tridi "na miste"
    */
    function moodlecscoll_sort (&$array) {
    uasort($array, 'moodlecscoll_strcoll');
    }

    /**
    * Vrati znak na pozici $index z retezce $string, pracuje v UTF-8
    *
    * @param string $string retezec v UTF-8, ze ktereho znak vybirame
    * @param int $index pozice znaku, ktery chceme vratit
    * @return char znak v UTF-8 na pozici $index v retezci $string
    */
    function moodlecscoll_charat ($string, $index) {
    return mb_substr($string, $index, 1, 'UTF-8');
    }

    /**
    * Lexikograficky komparator pro stringy v UTF-8 podle priblizneho
    * ceskeho narodniho trizeni bez ohledu na velikost pismen
    *
    * Zamenou promenne $abeceda jde pouzit libovolne jine trizeni, jen
    * ch je zadratovane vevnitr
    *
    * @param string $a prvni retezec ke trizeni
    * @param string $b druhy retezec ke trizeni
    * @return int 1 pokud je $a vetsi, 0 pokud jsou stejne, -1 pokud je $a mensi
    */
    function moodlecscoll_strcoll ($a, $b) {
    // tridici sekvence, obecne muze byt jakakoli, hlavne malymi pismeny
    // jednina podporovana dvojhlaska je ch kvuli primemu zadratovani vevnitr
    $abeceda = array ('0','1','2','3','4','5','6','7','8','9',
    'a','á','b','c','č','d','ď','e','é','f','g','h','ch',
    'i','í','j','k','l','m','n', 'ň','o','ó','p','q','r','ř','s','š','t',
    'ť','u','ú','ů','v','w','x','y','z','ž');
    $abeceda = array_flip($abeceda);

    // trideni je case insensitive
    $a = mb_strtolower($a, 'UTF-8');
    $b = mb_strtolower($b, 'UTF-8');
    if ($a == $b) return 0;

    // v cyklu prochazime pismena (CH se bere jako jedno pismeno), pokud je
    // jedno vetsi tak skoncime, jinak se jede dal
    $iA = 0;
    $iB = 0;
    do {
    if (moodlecscoll_charat($a, $iA) == 'c' and moodlecscoll_charat($a, $iA+1) == 'h') {
    $charA = moodlecscoll_charat($a, $iA) . moodlecscoll_charat($a,$iA + 1);
    $iA++;
    } else {
    $charA = moodlecscoll_charat($a, $iA);
    }

    if (moodlecscoll_charat($b, $iB) == 'c' and moodlecscoll_charat($b, $iB+1) == 'h') {
    $charB = moodlecscoll_charat($b, $iB) . moodlecscoll_charat($b, $iB+1);
    $iB++;
    } else {
    $charB = moodlecscoll_charat($b, $iB);
    }

    if ($abeceda[$charA] > $abeceda[$charB]) {
    return 1;
    } elseif ($abeceda[$charA] < $abeceda[$charB]) {
    return -1;
    }

    $iA++;
    $iB++;
    } while ($charA != and $charB != );

    return 0;
    }

    ?>

    btw. in my case I had to alter one of the last lines to while ($charA !=); (which makes this part of code disabled kind of) because it gave me some error I could'nt solve but make this work at all.

    As for the comments if you need, put it into google translate and you should be fine.
  • So, how do you feel about this? Is it any help for development or just "patch" for czech language to work? (any reply to let me know pls)
  • Well, since this is language specific, it is not something that we will incorporate. we would really like a general solution, but so far, none has surfaced.
Sign In or Register to comment.