1 # This program is copyright Jonathan Feinberg 1999.
3 # This program is distributed under the same terms as infobot.
7 # http://pobox.com/~jdf/
10 # First public release.
16 # Translate some feasible abbreviations into the ones babelfish
18 use vars qw!%lang_code $lang_regex!;
31 # Here's how we recognize the language you're asking for. It looks
32 # like RTSL saves you a few keystrokes in #perl, huh?
33 $lang_regex = join '|', keys %lang_code;
37 my ($direction, $lang, $phrase) = @_;
39 return unless &loadPerlModule("URI::Escape");
41 $lang = $lang_code{$lang};
43 my $ua = new LWP::UserAgent;
46 my $url = 'http://babelfish.altavista.digital.com/cgi-bin/translate';
47 my $req = HTTP::Request->new('POST',$url);
48 $req->content_type('application/x-www-form-urlencoded');
50 my $tolang = "en_$lang";
51 my $toenglish = "${lang}_en";
53 if ($direction eq 'to') {
54 &main::performStrictReply( translate($phrase, $tolang, $req, $ua) );
56 } elsif ($direction eq 'from') {
57 &main::performStrictReply( translate($phrase, $toenglish, $req, $ua) );
61 my $last_english = $phrase;
66 last if $results{$phrase}++;
67 $last_lang = $phrase = translate($phrase, $tolang, $req, $ua);
68 last if $results{$phrase}++;
69 $last_english = $phrase = translate($phrase, $toenglish, $req, $ua);
72 &main::performStrictReply($last_english);
76 return '' if $no_babel;
77 my ($phrase, $languagepair, $req, $ua) = @_;
79 my $urltext = uri_escape($phrase);
80 $req->content("urltext=$urltext&lp=$languagepair&doit=done");
82 my $res = $ua->request($req);
85 if ($res->is_success) { # success.
86 my $html = $res->content;
87 # This method subject to change with the whims of Altavista's design
93 <font\ face="arial,\ helvetica">
95 (?:\*\*\s+time\ out\s+\*\*)?
100 $translated =~ s/\n/ /g;
101 $translated =~ s/\s*$//;