Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

eijiro

by miyagawa (Chaplain)
on Dec 06, 2001 at 00:20 UTC ( [id://129731]=CUFP: print w/replies, xml ) Need Help??

Eijiro is the name of a website providing English - Japanese translation. eijiro is a perl script with which you can do translation in command line interactively. Handy for guys who are willing to study Japanese out there.

eijiro web page is at http://bulknews.net/lib/utils/eijiro/

#!/usr/local/bin/perl # eijiro.pl - http://www.alc.co.jp/ # # Tatsuhiko Miyagawa <miyagawa@bulknews.net> # use strict; use Jcode; use LWP::Simple; use FileHandle; use URI::Escape; use HTML::FormatText; use HTML::TreeBuilder; use Term::ReadLine; my $historyfile = $ENV{HOME} . '/.eijirohistory'; my $pager = $ENV{PAGER} || 'less'; my $action = 'http://home.alc.co.jp/db/owa/eijiro_red'; # Terminal mode / Argv mode if (@ARGV) { my $line = join ' ', @ARGV; translate($line); } else { my $term = Term::ReadLine->new('Eijiro'); ### read history if (my $fh = FileHandle->new($historyfile)) { my @h = $fh->getlines; chomp @h; $fh->close; my %seen; $term->addhistory($_) foreach (grep { /\S/ && !$seen{$_}++ } @ +h); } ### readline & translate while ( defined ($_ = $term->readline('eijiro> ')) ) { exit if /^!exit/; translate($_); # Add history { my $fh = FileHandle->new(">>$historyfile") or die $!; $fh->print("$_\n"); $fh->close; } $term->addhistory($_) if /\S/; } } sub translate { my $line = shift or return; # ej or je my $type_in = $line =~ /^[\x00-\x7f]*$/ ? 'ej' : 'je'; # URI-Escape my $word_in = Jcode->new($line)->sjis; $word_in = uri_escape($word_in, '\W'); # get Simply my $url = sprintf '%s?word_in=%s&type_in=%s', $action, $word_in, $ +type_in; my $content = LWP::Simple::get($url) or die $!; my $parser = new HTML::TreeBuilder; my $html = $parser->parse(Jcode->new($content)->euc); my $format = new HTML::FormatText(leftmargin=>0); my $p = new FileHandle "| $pager"; $p->print($format->format($html)); $p->close; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2024-03-28 23:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found