#!/usr/bin/env perl # made by sputnick from a fork of Zoffix script. # [02:41:46] sputnick, BTW that script is against Google's TOS # [02:42:39] OMG I'm burnt :° ###use HTML::Entities qw(decode_entities); use warnings; use strict; use URI; use Clipboard; use Getopt::Long; use LWP::UserAgent; use HTML::TokeParser::Simple; use UI::Dialog::Backend::Zenity; my ($Input, $Context, $Lang, $fren, $enfr, $esen, $enes, $std1n, $expr, $help); my $D = new UI::Dialog::Backend::Zenity; Getopt::Long::Configure("pass_through"); GetOptions( 'fren' => \$fren, 'enfr' => \$enfr, 'esen' => \$esen, 'enes' => \$enes, 'std1n' => \$std1n, # 'expr' => $expr = $_, 'help|h' => \$help); Getopt::Long::Configure("no_pass_through"); unless (defined(@ARGV)) { $help = 1 }; if (defined($help)) { print "Usage : perl $0 < --fren --enfr --esen --enes > [ --exp --std1n --help ]", $/; exit(0) }; if (defined($fren)) { $Lang='fr|en'; $Context='Google traduction : Français => Anglais...' } elsif (defined($enfr)) { $Lang='en|fr'; $Context='Google traduction : Anglais => Français...' } elsif (defined($esen)) { $Lang='es|en'; $Context='Google traducción : Español => Inglés...' } elsif (defined($enes)) { $Lang='en|es'; $Context='Google traducción : Inglés => Español...' }; if (defined($std1n)) { print "Paste your text below...", $/; $Input = <> } else { $Input = Clipboard->paste }; my $translate_uri = URI->new('http://www.google.fr/translate_t'); $translate_uri->query_form( hl => 'fr', ie => 'UTF8', text => $Input, langpair => $Lang); my $ua = LWP::UserAgent->new( agent => 'Mozilla/5.0' ); my $response = $ua->get( $translate_uri ); unless ( $response->is_success ) { die "ZOMG!!! FAILED!!! : " . $response->status_line; } my $parser = HTML::TokeParser::Simple->new( \$response->content ); my $get_text = 0; my $translation; while (my $t = $parser->get_token) { $get_text = 1 if $t->is_start_tag('div') and $t->get_attr('id') and $t->get_attr('id') eq 'result_box'; last if $get_text == 1 and $t->is_end_tag('div'); $translation .= $t->as_is if $get_text and $t->is_text; } $D->msgbox( title => $Context, text => $translation ) || print decode_entities($translation), $/ ;