Trag has asked for the wisdom of the Perl Monks concerning the following question:

I've recently decided it would be fun to learn to read Kana, and got it into my head to write my own training program with Perl. It would show a character and have you type in the pronunciation (learning to read words is next on my list) for it.

My problem is that I don't have a suitable input/output medium for displaying the characters. I'm on windows and the console doesn't display the character properly (or rather, writes a few characters). I tried Tk but got the same output as with the command prompt along with an error about it being too wide (would Unicode::EastAsianWidth help?).

Does anyone know what output medium I could use?
Corion suggested I output to HTML, but my goal is not a CGI app, which is what I assume this would involve.

Thanks

Trag

------------------------------------------------
Just another Perl Hack

Replies are listed 'Best First'.
Re: Displaying Kana
by sweetblood (Prior) on Jul 05, 2004 at 16:18 UTC
    Using HTML as Corion suggested does not mean you need to build a 'CGI' app, it is only a means to display your characters. The app need not live anywhere but on your computer, You'd just display the HTML files your app produces locally. It's a good idea!

    HTH

    Sweetblood

      It works for displaying, yes, but I would prefer a more convenient interface where I could type my response into the same window as the character is displayed in (of course, for all I know, this is possible with HTML).
      Please correct me if I'm wrong.

      Thanks

      Just another Perl Hack
Re: Displaying Kana
by traveler (Parson) on Jul 05, 2004 at 16:25 UTC
    If the Windows you are using is XP, you can install the East Asian language support. Go to Control Panel->Languages. On the supplemental language support tab click on the Install files for East Asian Languages checkbox. Click OK and follow instructions. Presumably other versions of Windows have similar tools. I installed Chinese characters on 2000 using some instructions from MS. --traveler
Re: Displaying Kana
by graff (Chancellor) on Jul 06, 2004 at 03:29 UTC
    I don't know whether the MS-Windows (binary?) distributions of Tk are different from those for unix (source code), but whenever I've installed Tk for5.8.x from source code (via CPAN), the test phase of the installation has generally included a succesful text display of Japanese (and Chinese) characters. Here is the snippet that runs the display of Japanese in a text widget -- slightly modified so I could run it from the command line via "perl -e ..." (and use a larger font size):
    use Tk; use Tk::widgets qw(Text); my $mw = MainWindow->new; $mw->geometry("+10+10"); #my $font = 'Times'; my $font = 'fixed'; my $t = $mw->Scrolled(Text => -font => [$font => 24, 'normal'])->pa +ck( -fill => 'both', -expand => 1); $file = "t/JP.dat"; open(my $fh,"<:utf8",$file) || die "Cannot open $file:$!"; while (<$fh>) { # s/[^ -~\s]/?/g; $t->insert('end',$_); $t->see('end'); $mw->update; } close($fh); MainLoop;
    I won't repeat the whole content of "JP.dat", which is used by this script -- you can get that yourself from the source code tarball if you don't have it already. It's just a long list of utf8 code points, arranged 16 characters per line. Here are the first few lines:
    0x0020: ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > 0x0040: @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ 0x0060: ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ 0x8ea0: 。 「 」 、 ・ ヲ ァ ィ ゥ ェ ォ ャ ュ ョ ッ + ー ア イ ウ エ オ カ キ ク ケ コ サ シ ス セ 0x8ec0: タ チ ツ テ ト ナ ニ ヌ ネ ノ ハ �‹ フ ヘ + マ ミ ム メ モ ヤ ユ ヨ ラ リ ル レ �› ワ ン ゙
    (There's genuine utf8 character data in that "code" block -- if it looks garbled, be sure to set your browser for utf8 encoding. Also, if your PM user settings impose wrapping on code lines, this could disrupt a character or two -- that'll go away when you use the "download code" link; it appears that the PM code-wrapping process is not utf8-aware...)

    You may need to play with the font specs a bit to make it legible, or you may need to install a suitable font (sorry, I can't help with that).

    Oh, and this is supposed to be perl 5.8.0 or greater, to get the ":<utf8" in the open statement to be properly understood. (I was doing it with 5.8.1 on macosx.)

      No luck, I'm afraid. I ran the code you gave me, and tracked down jp.dat, but It just displayed gibberish.

      Thanks though

      Trag

      Just another Perl Hack
Re: Displaying Kana
by Mercio (Scribe) on Jul 06, 2004 at 02:17 UTC
    I think HTML would be your best bet. You could set up a form field that will allow you to enter the pronounciation on the screen with the character and have it submit to the same perl script so it can check your answer
      Thanks, except I have no idea how to do that. Do you think you could link me to a tutorial of some type?

      Thanks

      Trag

      Just another Perl Hack