problems with iso-8859-2 - temporary solution
"Jerzy Kurowski" <jerzy-rchyquexcp9aM7/vMKfp/[email protected]> Sat, 10 May 2003 04:22:18 +0200
| Newsgroups | gmane.comp.cms.xaraya.knowledge-base |
|---|---|
| Organization | Xaraya News Server |
| Message-ID | <[email protected]> |
I had problems using iso-8859-2 with unboxed mode on Xaraya beta 0,902. I
tried different solutions, finaly it seems i found kind of.
I hope that with time it will become unnecessary.
I desided to publish it here for people who may have problems using non
english iso encodings with unboxed multi-language setting.
First word of warning:
- use it only when you tried all other solutions, I'm sure it's not the
best one. You can try with mlstring, or iconv functions in PHP (probably if
you have mlstring working you have no problem anyway :)
- it's unsupported and you use it at your own risk: it's a hack of core
xaraya system, I'm NOT a xaraya developer, don't go to them if it does't
work, or destroys your xaraya box.
- it increases execution time: it will take more time to load for your
pages.
- it works for me with iso-8859-2 for all Polish characters, no qurantee
it'll work in every case
Now you have been warned, so let's say what it does:
it just converts double byte unicode strings to html entities within
strings translated by ml system
Usage:
copy function code to xarMLS.php file in includes directory ( I put it on
line 200), and add line
$trans=utf2html($trans);
just below line:
$trans = $GLOBALS['xarMLS_backend']->translate($string);
What else is necessary to have it working:
You should generate skels with translations module and translate them by
hand with utf editor (just put jour translation inside
<translation></translation> tag like this <translation>your
translation</translation>) .
Credits:
I found the function here:
http://www.php.net/manual/tw/function.utf8-decode.php in User Contributed
Notes
comments are welcomed
Jerzy Kurowski
The function [don't copy this line]:
// utf2html function from
http://www.php.net/manual/tw/function.utf8-decode.php
// inserted to decode utf 2 html entities
function utf2html ($utf2html_string)
{
$utf2html_retstr = "";
for ($utf2html_p=0; $utf2html_p<strlen($utf2html_string); $utf2html_p++) {
$utf2html_c = substr ($utf2html_string, $utf2html_p, 1);
$utf2html_c1 = ord ($utf2html_c);
if ($utf2html_c1>>5 == 6) {// 110x xxxx, 110 prefix for 2 bytes unicode
$utf2html_p++;
$utf2html_t = substr ($utf2html_string, $utf2html_p, 1);
$utf2html_c2 = ord ($utf2html_t);
$utf2html_c1 &= 31; // remove the 3 bit two bytes prefix
$utf2html_c2 &= 63; // remove the 2 bit trailing byte prefix
$utf2html_c2 |= (($utf2html_c1 & 3) << 6); // last 2 bits of c1 become
first 2 of c2
$utf2html_c1 >>= 2; // c1 shifts 2 to the right
$a = dechex($utf2html_c1);
$a = str_pad($a, 2, "0", STR_PAD_LEFT);
$b = dechex($utf2html_c2);
$b = str_pad($b, 2, "0", STR_PAD_LEFT);
$utf2html_n_neu = $a.$b;
$utf2html_n_neu_speicher = $utf2html_n_neu;
$utf2html_n_neu = "&#x".$utf2html_n_neu.";";
$utf2html_retstr .= $utf2html_n_neu;
}
else {
$utf2html_retstr .= $utf2html_c;
}
}
return $utf2html_retstr;
}
// END of modifications