The Auto Translate module - http://drupal.org/project/i18n_auto - translates content in a text form, so that editors may translate content before a node is submitted. It currently has the same bug you're describing, although that should be fixed soon (already fixed in PHP5, but not yet for PHP4). Also, the module has several GHOP tasks, visible from http://drupal.org/project/issues/i18n_auto - to bring the module out of development. It will ultimately support other translation services besides Google as well.

Aaron Winborn

Idan Arbel wrote:
thanks, but I want the translated content to be saved as nodes, and not to be translated on the fly.

Idan

On Jan 12, 2008 7:43 PM, Amr Mostafa < amr.mostafa@gmail.com> wrote:
Hello Idan,

I would like to point out that there is an existing module which does exactly what you described, it's called gtrans.

http://drupal.org/project/gtrans

- Amr


On Jan 12, 2008 7:30 PM, Idan Arbel <idan@arbel-designs.com > wrote:

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