#!/usr/bin/perl -w use CGI qw(:all); use URI::Escape; print header(); my $from; if ($from = param('from')) { my ($in, $out); if ($in = param('in')) { $out = trans($in, $from); } else { $in = ''; $out = " "; } my $title, $po, $links; if ($from eq 'en') { $title = "English to Spanish"; $po = "Powered by "; $links = ''; } else { $title = "Espaņol a Ingles"; $po = "Accionado por "; $links = 'Conjugaciones en Espaņol por Verbix.'; } print ""; print "
"; print "

$title

"; print "

"; print ""; print ""; print " $po AltaVista. $links"; print "
"; print "
"; print "$out"; print "
"; } elsif (param('es')) { print "Es"; } else { print 'English/Spanish Translation '; } sub trans { my($in, $from) = @_; my $out = ''; if ($from eq 'en') { $from = 'en_es'; } else { $from = 'es_en'; } $in = uri_escape($in); my $file = "/tmp/out.$$"; system("wget -O $file 'http://babelfish.altavista.com/tr?doit=1&intl=1&trtext=$in&tt=urltext&lp=$from'"); open(F, $file) || return "Could not open $file: $!"; my $found = 0; while () { if (! $found) { next unless /
/; $found = 1; } if (/<\/div>/) { s/<\/div>.*$//; $out .= $_; last; } else { $out .= $_; } } close F; unlink $file; return $out; }