Yesterday I had to solve the "greek characters do not get displayed in user activity graphs" problem within an extremely small time limit, and it was rather... distressing. But in the process, I found out something which may be of interest to the Moodle core.
After poking around, the solution was found in creating a lang/el/fonts/lang_decode.php file with a function like this:
function lang_decode($s) {
$len = strlen($s);
$out = '';
for($i=0; $i < $len; $i++) {
$ch = ord($s[$i]);
$out .= $ch > 128 && $ch < 256 ? '&#'.(720 + $ch).';' : chr($ch);
}
return $out;
}
This solved the problem, although the things I did to find out that 720 magic number would be amusing, if it were someone else doing them. However, it was later pointed out to me that there is a very nice iconv() function which would simplify matters:
function lang_decode($s) {
return iconv('ISO-8859-7', 'UTF-8', $s);
}
So I have two questions:
- iconv needs PHP compiled with --with-iconv. Does anyone know if this is standard? Can we count on iconv() to be present in a plain vanilla PHP installation? Personally, I don't remember.
- If the answer to the above is yes, Martin, since Moodle knows the source codepage from the language configuration, wouldn't it make sense to drop support for lang_decode.php and move this within the Moodle core?
Cheers,
Jon