[development] Google translation module

Amr Mostafa amr.mostafa at gmail.com
Sat Jan 12 17:43:04 UTC 2008


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 at 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20080112/dd05a535/attachment.htm 


More information about the development mailing list