in reply to Google Translation using WWW::Babelfish
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 -
This will write the translation into a file.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);
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 |