Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Google Translation using WWW::Babelfish

by sk (Curate)
on Jan 25, 2006 at 04:07 UTC ( #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
Node Status?
node history
Node Type: note [id://525367]
help
Chatterbox?
[stevieb]: I *finally* have my automated RPi::WiringPi and related distribution automated test build system done! It's easy to use (relatively), simple to set up, and works awesome! Cycles every X mins, checks github for new commits, and builds...
[stevieb]: ...optionally displaying the results to a connected LCD with the dist name, date, time and commit of the last run along with a FAIL/PASS. Obviously I can't get CI with Travis for a RPi, so I built my own :) It'll take a couple of blog posts I think...
[stevieb]: ...to cover it all. Awesome thing is that you can dispatch ANY distribution to it (and include all revdeps if desired), and it works all the same as if I'm just testing the RPI code itself
[stevieb]: I'm rather pleased with myself and everything I've leared along this arduous and sometimes frustrating path
[stevieb]: Just need to implement an email plugin or something so I can get alerted remotely if the status of a build has changed from the last run
[stevieb]: Because of the extreme complexity of the testing code itself, I implemented extensive logging so I can troubleshoot much easier by setting a high debug level.

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2017-04-28 21:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (529 votes). Check out past polls.