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
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).
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.
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.