- my ($phrase, $languagepair, $req, $ua) = @_;
-
- my $urltext = uri_escape($phrase);
- $req->content("urltext=$urltext&lp=$languagepair&doit=done");
-
- my $res = $ua->request($req);
-
- my $translated;
- if ($res->is_success) { # success.
- my $html = $res->content;
- # This method subject to change with the whims of Altavista's design
- # staff.
-
- $translated =
- ($html =~ m{<br>
- \s+
- <font\ face="arial,\ helvetica">
- \s*
- (?:\*\*\s+time\ out\s+\*\*)?
- \s*
- ([^<]*)
- }sx);
-
- $translated =~ s/\n/ /g;
- $translated =~ s/\s*$//;
- } else { # failure
- $translated = ":(";
- }
+ my ($phrase, $languagepair, $req, $ua) = @_;
+ &main::DEBUG("translate($phrase, $languagepair, $req, $ua)");
+
+ my $urltext = uri_escape($phrase);
+ $req->content("urltext=$urltext&lp=$languagepair");
+ &main::DEBUG("http://babelfish.altavista.com/babelfish/tr??urltext=$urltext&lp=$languagepair");
+
+ my $res = $ua->request($req);
+ my $translated;
+
+ if ($res->is_success) {
+ my $html = $res->content;
+ # This method subject to change with the whims of Altavista's design
+ # staff.
+ ($translated) = $html;
+
+ $translated =~ s/<[^>]*>//sg;
+ $translated =~ s/ / /sg;
+ $translated =~ s/\s+/ /sg;
+ #&main::DEBUG("$translated\n===remove <attributes>\n");
+
+ $translated =~ s/\s*Translate again.*//i;
+ &main::DEBUG("$translated\n===remove after 'Translate again'\n");
+
+ $translated =~ s/[^:]*?:\s*(Help\s*)?//s;
+ &main::DEBUG("$translated\n===remove to first ':', optional Help\n");
+
+ $translated =~ s/\n/ /g;
+ # FIXME should we do unicode->iso
+ } else {
+ $translated = ":("; # failure
+ }
+ &main::pSReply($translated);
+}