#!/usr/bin/perl -w use CGI qw(:all); use URI::Escape; my %links; $links{'es'} = 'Conjugaciones por Verbix.'; $links{'fr'} = 'Conjugations by Verbix.'; $links{'it'} = 'Conjugations by Verbix.'; my %lang = ( 'de' => 'German', 'en' => 'English', 'es' => 'Spanish', 'fr' => 'French', 'it' => 'Italian', 'nl' => 'Dutch', 'pt' => 'Portugese', 'ja' => 'Japanese', 'el' => 'Greek', 'ko' => 'Korean', 'ru' => 'Russian', 'zh' => 'Simplified Chinese', 'zt' => 'Traditional Chinese', ); print header('text/html; charset=UTF-8'); my($L1, $L2) = (param('L1'), param('L2')); my($L1_) = $lang{$L1} || $L1; my($L2_) = $lang{$L2} || $L2; if (!defined($L1)) { foreach my $l (sort keys %lang) { if ($l eq 'en') { $opt1 .= "\n"; $opt2 .= "\n"; } elsif ($l eq 'es') { $opt1 .= "\n"; $opt2 .= "\n"; } else { $opt1 .= "\n"; $opt2 .= "\n"; } } print "

Choose your languages

\n"; print "
"; print ""; print ""; print ""; print "
From:
To:
"; } my($from, $to); if ($from = param('from')) { $to = param('to'); my ($in, $out); if ($in = param('in')) { $out = trans($in, $from, $to); } else { $in = ''; $out = " "; } my($title, $links); if ($from eq $L1) { $title = "$L1_ to $L2_"; $links = $links{$L1} || ''; $wr = "Look up words at WordReference"; } else { $title = "$L2_ to $L1_"; $links = $links{$L2} || ''; $wr = "Look up words at WordReference"; } print ""; print "
"; print "$title
"; print "

"; print ""; print ""; print ""; print ""; print ""; print "

Powered by AltaVista. $links $wr"; print "

"; print "
"; print "$out"; print "
"; } else { print "$L1_/$L2_ Translation "; } sub trans { my($in, $from, $to) = @_; my $out = ''; my $lp = "${from}_${to}"; $in = uri_escape($in); $in =~ s/'/\'/; open(F, "wget -O- -q --header='Accept-Charset: utf-8' \"http://babelfish.altavista.com/tr?doit=1&intl=1&trtext=$in&tt=urltext&lp=$lp\" |"); my $found = 0; while () { if (! $found) { next unless s/
//; $found = 1; } if (/<\/div>/) { s/<\/div>.*$//; $out .= $_; last; } else { $out .= $_; } } close F; return $out; }