Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

transl8it.com interface w/ Win32::Clipboard support

by thealienz1 (Pilgrim)
on Aug 12, 2002 at 05:43 UTC ( [id://189385]=sourcecode: print w/replies, xml ) Need Help??
Category: Fun Stuff
Author/Contact Info

jtarchie <thealienz123@yahoo.com>
AIM: thealienz123
ICQ: 5673454

Description:

This script requires use of the Win32::Clipboard Module.

This is the same as my tranls8it.com code, but has a built in interface for the Win32::Clipboard module. That way if you want to copy something into the clipboard, instead of typing it out again, the script will automatically translate whatever is in the clipboard, and write it over with the translation. I have it setup so, I can just use some shortcuts to do english<->lingo.

use strict;
use LWP::UserAgent;
use HTTP::Request::Common;
use HTML::Form;
use Win32::Clipboard;

my $clip = Win32::Clipboard;
my $agent = new LWP::UserAgent;
my $url = 'http://www.transl8it.com/index.cgi?convert';
if($ARGV[0] eq '-to') {
    #Translates from english to text lingo
    print "English to lingo - \n";
    print "Type Message: ";
    my $input = '';
    if($clip->IsText()) {
        $input = $clip->GetText() . "\n";
        print $input;
    } else{
        $input = <STDIN>;
    }
    chomp($input);

    #Actual FORM post data
    my %data = (    'txtMessage' => $input,
            'direction' => '<--'
        );
    my $request = $agent->request(POST $url, [%data]);
    my $content = $request->content();
    my @forms = HTML::Form->parse($content, $url);
    foreach my $form (@forms) {
        eval{
            if(defined($form->value('txtTranslation'))) {
                print "\nTranslation: \n" . $form->value('txtTranslati
+on');
                $clip->Set($form->value('txtTranslation'));
                last;
            }
        };
        if(@_) {next;}
    }
} elsif($ARGV[0] eq '-from') {
    #Translates from text lingo to english
    print "lingo to English - \n";
    print "Type Message: ";
    my $input = '';
    if($clip->IsText()) {
        $input = $clip->GetText() . "\n";
        print $input;
    } else{
        $input = <STDIN>;
    }
    chomp($input);

    #Actual FORM post data
    my %data = (    'txtMessage' => $input,
            'direction' => '-->'
        );
    my $request = $agent->request(POST $url, [%data]);
    my $content = $request->content();
    my @forms = HTML::Form->parse($content, $url);
    foreach my $form (@forms) {
        eval{
            if(defined($form->value('txtTranslation'))) {
                print "\nTranslation: \n" . $form->value('txtTranslati
+on');
                $clip->Set($form->value('txtTranslation'));
                last;
            }
        };
        if(@_) {next;}
    }
} else{
    print 'perl trans.pl (-to|-from)';
}

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://189385]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-20 01:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found