Archive for April, 2008

Using translation tools: babelfish / google / yahoo

Languages: Chinese-simp, Chinese-trad, Dutch, English, French, German, Greek, Italian, Japanese, Korean, Portuguese, Russian, Spanish

Requirements:

IO::String
WWW::Babelfish
#!/usr/bin/perl
 use strict;
 use warnings;
 use WWW::Babelfish;
 
 # text to translate
 my $text_source = 'I like to test this service.';
 
 # create the Babelfish service
 my $service = WWW::Babelfish->new(
     service => 'Babelfish',
 );
 
 # check for errors
 if (not defined $service) {
     die "Babelfish server unavailable";
 }
 
 # show text to be translated
 print "[EN] $text_source\n";
 
 # translate to Italian
 my $text_target = $service->translate(
     source          => 'English',   # source language
     destination     => 'Italian',   # destination language
     text            => $text_source,    # text to translate
 );
 if (not defined $text_target) {
     print "Error while translating to Italian";
 }
 else {
     print "[FR] $text_target\n";
 }