Special characters mess up sort order
| Project: | Views Tagadelic |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
| Issue tags: | tagadelic fix |
Jump to:
Using Views Tagadelic I have a problem with the sort order of tags when it comes to special characters. I set "Taxonomy: Term Name" as sort criteria in views which shows my tags in an alphabetical order. But: When there are tags starting with a special character (like ä, ö, ü, ß; talking about a website in german), those are listed before all the others. Example:
Categories: birnen, ananas, äpfel, obst, überfluss, absinth
Sort order (should be): absinth, äpfel, ananas, birnen, obst, überfluss
Sort order (is): äpfel, überfluss, absinth, ananas, birnen, obst
(I am not sure if german umlaute should be treated as the respective vowel+e (ä->ae, ö->oe, ü->ue) or just as a vowel (ä->a, ö->o, ü->u) when it comes to sorting. Both work.)
This doesn't happen when I create a view with a list of nodes ordered by title. For that reason I think it's a Views Tagadelic problem, not a Views problem.

#1
It happens to me too, in Polish characters. Any fix for this?
Szy.
#2
+1
#3
Try replacing the _tagadelic_sort_by_title in tagadelic.module to the following:
function _tagadelic_sort_by_title($a, $b) {
static $arr;
if (empty($arr)) {
// set character order for your language, this one is for polish language
$arr = array_flip(array(
'!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/','0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?','@',
'A','Ą','B','C','Ć','D','E','Ę','F','G','H','I','J','K','L','Ł','M','N','Ń','O','Ó','P','Q','R','S','Ś','T','U','V','W','X','Y','Z','Ź','Ż','[','\\',']','^','_','`',
'a','ą','b','c','ć','d','e','ę','f','g','h','i','j','k','l','ł','m','n','ń','o','ó','p','q','r','s','ś','t','u','v','w','x','y','z','ź','ż','{','|','}'
));
}
$len1 = mb_strlen($a->name);
$len2 = mb_strlen($b->name);
for ($i=0;$i<min($len1,$len2);$i++) {
$c1 = $arr[mb_substr($a->name,$i,1)];
$c2 = $arr[mb_substr($b->name,$i,1)];
if ($c1<$c2) return -1;
if ($c1>$c2) return 1;
}
if ($len1<$len2) return -1;
if ($len1>$len2) return -1;
return 0;
}
#4
Works like a charm :]
Dzięki :)
Szy.
#5
The following seems to work with german language:
<?php
function _tagadelic_sort_by_title($a, $b) {
static $arr;
if (empty($arr)) {
// set character order for your language, this one is for german language
$arr = array_flip(array(
'!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/','0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?','@',
'A','Ä','B','C','D','E','F','G','H','I','J','K','L','M','N','O','Ö','P','Q','R','S','T','U','Ü','V','W','X','Y','Z','[','\\',']','^','_','`',
'a','ä','b','c','d','e','f','g','h','i','j','k','l','m','n','o','ö','p','q','r','s','ß','t','u','ü','v','w','x','y','z','{','|','}'
));
}
$len1 = mb_strlen($a->name);
$len2 = mb_strlen($b->name);
for ($i=0;$i<min($len1,$len2);$i++) {
$c1 = $arr[mb_substr($a->name,$i,1)];
$c2 = $arr[mb_substr($b->name,$i,1)];
if ($c1<$c2) return -1;
if ($c1>$c2) return 1;
}
if ($len1<$len2) return -1;
if ($len1>$len2) return -1;
return 0;
}
?>
But this looks like a very specific (language based) way to me. Does anybody have an idea how to solve this more generally?