Hello,
I'm
working on a module to auto translate nodes on my websites. I'm using google
translate to do this.
I've
encountered a problem that I was hoping someone would have an idea how to solve….when
I translate a text that has "special characters", mainly those that aren’t
English, and I try to display them, I get characters that are black diamonds. When
trying to display those using drupal with drupal set message, something strange
happens, it seems like drupal just ignores the entire function. I'm trying to
print it out of a nodeapi hook, and the when I do all the other
drupal_set_messages aren’t displayed, even those that come before.
Anyway,
I think I've isolated the problem to the encoding of the characters, but I
don't know how to solve it. I see the characters with the black diamonds when I
print_r($translation), in this case I only see them. And when ever I try to drupal_set_message
them I don't see anything.
If
I translate a text that doesn't have one of those characters, all is well.
This
is what I'm using to translate the texts:
function
google_translate($text, $from = 'en', $to = 'es') {
$data = "h1=en&ie=UTF8&text=$text";
$result = drupal_http_request(I18N_AUTO_GOOGLE_TRANSLATE_TRANSLATOR_URL
. '?langpair='. $from .'|'. $to, array(), 'POST', $data);
$texttosearch = "id=result_box";
$start = strpos($result->data,
$texttosearch);
$end = strpos($result->data,
"</div>", $start+24);
$start = $start + 24;
$translated = substr($result->data,
$start, $end-$start);
return $translated;
}
Thanks
Idan