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