1 # This program is copyright Jonathan Feinberg 1999.
2 # This program is distributed under the same terms as infobot.
6 # http://pobox.com/~jdf/
9 # First public release.
15 # Translate some feasible abbreviations into the ones babelfish
17 use vars qw!%lang_code $lang_regex!;
30 # Here's how we recognize the language you're asking for. It looks
31 # like RTSL saves you a few keystrokes in #perl, huh?
32 $lang_regex = join '|', keys %lang_code;
36 my ($direction, $lang, $phrase) = @_;
38 return unless &loadPerlModule("URI::Escape");
40 $lang = $lang_code{$lang};
42 my $ua = new LWP::UserAgent;
45 my $url = 'http://babelfish.altavista.digital.com/cgi-bin/translate';
46 my $req = HTTP::Request->new('POST',$url);
47 $req->content_type('application/x-www-form-urlencoded');
49 my $tolang = "en_$lang";
50 my $toenglish = "${lang}_en";
52 if ($direction eq 'to') {
53 &main::performStrictReply( translate($phrase, $tolang, $req, $ua) );
55 } elsif ($direction eq 'from') {
56 &main::performStrictReply( translate($phrase, $toenglish, $req, $ua) );
60 my $last_english = $phrase;
65 last if $results{$phrase}++;
66 $last_lang = $phrase = translate($phrase, $tolang, $req, $ua);
67 last if $results{$phrase}++;
68 $last_english = $phrase = translate($phrase, $toenglish, $req, $ua);
71 &main::performStrictReply($last_english);
75 return '' if $no_babel;
76 my ($phrase, $languagepair, $req, $ua) = @_;
78 my $urltext = uri_escape($phrase);
79 $req->content("urltext=$urltext&lp=$languagepair&doit=done");
81 my $res = $ua->request($req);
84 if ($res->is_success) { # success.
85 my $html = $res->content;
86 # This method subject to change with the whims of Altavista's design
92 <font\ face="arial,\ helvetica">
94 (?:\*\*\s+time\ out\s+\*\*)?
99 $translated =~ s/\n/ /g;
100 $translated =~ s/\s*$//;