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; }

In reply to eijiro by miyagawa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.