Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Google Translation using WWW::Babelfish

by sk (Curate)
on Jan 25, 2006 at 04:07 UTC ( [id://525367]=note: print w/replies, xml ) Need Help??


in reply to Google Translation using WWW::Babelfish

I ran your code and I get this output

 soy mejicano con el pelo negro y los ojos marrones

If you want to store the output in a file then you can do something like this -

open (FH, '>', "junk") or die $!; $en_text = $obj->translate( 'source' => 'English', 'destination' => 'Spanish', 'text' => "i am mexican with black hair an +d brown eyes", 'delimiter' => "\n\n", 'ofh' => \*FH);
This will write the translation into a file.

If you do not want that then just remove the 'ofh' from the call. When i do that it returns the text and it is stored in $en_text. You can just print it or you can then push this text into an @array of your choice.

Something like this ? -

#!/usr/bin/perl use strict; use warnings; use WWW::Babelfish; use Data::Dumper; # open (FH, '>', "junk") or die $!; my $obj = new WWW::Babelfish( service => 'Google', agent => 'Mozilla/ +8.0'); die( "Babelfish server unavailable\n" ) unless defined($obj); my @sentences = ("I would like to translate this sentence into Spanis +h", "Because i am mexican with black hair and brown eyes"); my @translations = (); for (@sentences) { my $en_text = $obj->translate( 'source' => 'English', 'destination' => 'Spanish', 'text' => $_, 'delimiter' => "\n\n"); die("Could not translate: " . $obj->error) unless defined($en_text +); push(@translations,$en_text); } print Dumper (@translations);

Output

$VAR1 = "Quisiera traducir esta oraci\x{f3}n a espa\x{f1}ol"; $VAR2 = 'Porque soy mejicano con el pelo negro y los ojos marrones';

-SK

Replies are listed 'Best First'.
Re^2: Google Translation using WWW::Babelfish
by senik148 (Beadle) on Jan 26, 2006 at 16:45 UTC
    yeah your code works, i did not know it will be stored in $en_text if you romve the ofh parameter.
    but again both code examples are good, i stick more with the last example because i want to output the translation maybe on a web server running it as a cgi. and i dont wanna store it on a file. etc.

    hey but thanx!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://525367]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-24 02:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found