1 # This program is distributed under the same terms as infobot.
2 # hacked by Tim@Rikers.org
9 my $url = 'http://translate.google.com/translate_a/t';
12 eval "use URI::Escape"; # utility functions for encoding the
13 if ($@) { $no_translate++ }
14 eval "use LWP::UserAgent";
15 if ($@) { $no_translate++ }
17 if ($@) { $no_translate++ }
21 return '' if $no_translate;
22 my ( $from, $to, $phrase ) = @_;
23 &::DEBUG("translate($from, $to, $phrase)");
25 my $ua = new LWP::UserAgent;
26 $ua->proxy( 'http', $::param{'httpProxy'} ) if ( &::IsParam('httpProxy') );
29 $ua->agent( "Mozilla/5.0 " . $ua->agent );
32 my $req = HTTP::Request->new('GET', 'http://translate.google.com/translate_a/t?client=t&&sl='.$from.'&tl='.$to.'&text='.$phrase);
34 $req->header('Accept-Language' => 'en-us');
35 $req->header('Accept-Charset' => 'UTF-8,*');
36 my $json = JSON->new->utf8;
37 my $json_text=$ua->request($req)->content;
38 $json_text =~ s/,,/,"",/g;
39 $json_text =~ s/,,/,"",/g;
40 #&::DEBUG($json_text);
41 my @decoded_json = from_json($json_text);
43 return $decoded_json[0][0][0][0];
48 if ($message =~ m{(\S*)\s+(\S*)\s+(.+)}xoi) {
49 &::performStrictReply( &translateParam( lc $1, lc $2, lc $3 ) );
56 # vim:ts=4:sw=4:expandtab:tw=80