Subject: [LON-CAPA-dev] Internationalization

From: Gerd Kortemeyer <[email-masked]>
Date: Thu, 18 Sep 2003 08:28:34 -0400

Hi,

As you might have seen from a number of CVS commits in the last two 
days, we have started to internationalize LON-CAPA, so that it can run 
in different languages. We have also started localizing for German and 
Portuguese. Internalizing is the bulk of the work right now, localizing 
can be done anytime, and involves no programming.

The internationalization process involves putting a wrapper around 
on-screen user messages and menus and turning them into keys, which the 
Maketext library translates into the desired language output using a 
look-up table ("lexicon").

As keys we are currently using the plain English messages, and Maketext 
is configured to replace the message by its own key if no translation 
is found. This makes it easy to phase in the internationalization 
without disturbing the screen output.

Internationalization is tedious, and the more we can distribute the 
work, the better.

*** New software should be written in internationalized format from now 
on.

*** If you feel like doing something brainless but productive, grab a 
module and internationalize it.

*** As you come across some code during normal programming, just insert 
the wrappers.

*** HERE'S WHAT TO DO:

Into the "use" section of a module, we need to insert

  use Apache::lonlocal;

- note that there are NO BRACKETS, we *want* to pollute our namespace.

Inside might be something like this

sub message {
    my $status=shift;
    my $message='Status unknown';
    if ($status eq 'WON') {
       $message='You have won.';
    } elsif ($status eq 'LOST') {
       $message='You are a total looser.';
    }
    return $message;
}
...
$r->print('<h3>Gamble your Homework Points</h3>');
...
$r->print(<<ENDMSG);
<font size="1">Rules:</font>
<font size="0">No purchase necessary. Illegal where not allowed.</font>
ENDMSG

We have to now wrap the subroutine &mt() ("maketext") around our 
messages, but not around markup, etc. We also want minimal disturbance. 
The first two examples are easy:

sub message {
    my $status=shift;
    my $message='Status unknown';
    if ($status eq 'WON') {
       $message='You have won.';
    } elsif ($status eq 'LOST') {
       $message='You are a total looser.';
    }
    return &mt($message);
}
...
$r->print('<h3>'.&mt('Gamble your Homework Points').'</h3>');

The last one is a bummer, since you cannot call subroutines inside of 
(<<MARKER). I have written a little subroutine to generate a translated 
hash for that purpose:

my %lt=&Apache::lonlocal::texthash('header' => 'Rules', 'disclaimer' => 
'No purchase necessary. Illegal where not allowed.');
$r->print(<<ENDMSG);
<font size="1">$lt{'header'}:</font>
<font size="0">$lt{'disclaimer'}</font>
ENDMSG

As a programmer, your job is done here. If everything worked, you 
should see no changes on the screen.

As a translator, you need to provide the lexicon for the keys, which in 
this case is the plain text message. The lexicons sit in 
loncom/localize/localize, with the language code as filename, for 
example de.pm for the German translation. The file then simply looks 
like this:

    'You have won.'
=> 'Sie haben gewonnen.',

    'You are a total looser.'
=> 'Sie sind der totale Verlierer.',

    'Rules'
=> 'Regeln',

    'No purchase necessary. Illegal where not allowed.'
=> 'Es ist erlaubt, einfach zu verlieren, und das ist Ihre Schuld.'

The German translation lexicon is in pretty okay shape, but not 
complete yet. Portuguese currently only covers the login screen. 
Russian is purely experimental. Looks like UTF-8 is the way to encode 
this, at least for latin/greek-based languages, but we still have to 
learn a lot.

This is a relatively easy programming task, and any help is appreciated.

Maketext can do a whole lot more, see

  http://search.cpan.org/dist/Locale-Maketext/lib/Locale/Maketext.pod

but for most purposes, we do not have to mess with that.

- Gerd.

---

From: Shoji Kajita <[email-masked]>
Date: Thu, 18 Sep 2003 22:46:01 +0900

Gerd,

Excelent! I will see the code and lexicon to Japanize LON-CAPA as soon
as possible.

Shoji Kajita, Ph.D, Associate Professor
Information Technology Center
Nagoya University, Japan

---

From: "Minoru Akiyama" <[email-masked]>
Date: Sun, 21 Sep 2003 14:18:21 +0900

Hi, Gerd,

Sample file is not  encoded in UTF-8.
I'd like to develop Japanese lexicon, but I'm afraid it won't
work in the case of Japanese(double byte code).

i-Learning / EMIT Japan
Minoru Akiyama

----- Original Message ----- 
From: "Gerd Kortemeyer" <[email-masked]>
To: <[email-masked]>; "Leonardo Mendes"
<[email-masked]>; "Ricardo Luis Kulzer"
<[email-masked]>; "Horst Bögel"
<[email-masked]>; "Shoji Kajita"
<[email-masked]>; "Timothy Takemoto"
<[email-masked]>; "Michael Thoennessen"
<[email-masked]>
Cc: "Gerd Kortemeyer" <[email-masked]>; "Ed Kashy"
<[email-masked]>; <[email-masked]>; "Deborah Kashy"
<[email-masked]>; "Wolfgang Bauer" <[email-masked]>;
"Helen Keefe" <[email-masked]>
Sent: Thursday, September 18, 2003 9:28 PM
Subject: [LON-CAPA-dev] Internationalization

> _______________________________________________
> LON-CAPA-dev mailing list
> [email-masked]
> http://mail.lon-capa.org/mailman/listinfo/lon-capa-dev
>

---

From: Gerd Kortemeyer <[email-masked]>
Date: Sun, 21 Sep 2003 15:34:50 -0400

Minoru,

Yes, the sample file is in ISO, but we have also successfully worked 
with UTF-8. If you could send me a small Japanese sample file in UTF-9, 
I can install it here, and we can test the setup.

Thanks!

- Gerd.

---

From: "Minoru Akiyama" <[email-masked]>
Date: Mon, 22 Sep 2003 07:04:09 +0900

Thanks, Gerd!

Thank you for your cooperation.
I'll send it to you ASAP.

Minoru

----- Original Message ----- 
From: "Gerd Kortemeyer" <[email-masked]>
To: <[email-masked]>
Cc: "Gerd Kortemeyer" <[email-masked]>
Sent: Monday, September 22, 2003 4:34 AM
Subject: Re: [LON-CAPA-dev] Internationalization

> >> As you might have seen from a number of CVS commits in the
last
> > two
> >> days, we have started to internationalize LON-CAPA, so that
it
> > can run
> >> on-screen user messages and menus and turning them into
keys,
> > which the
> >> As keys we are currently using the plain English messages,
and
> > Maketext
> >> Internationalization is tedious, and the more we can
distribute
> > the
> >> work, the better.
> >>
> >> *** New software should be written in internationalized
format
> > from now
> >> on.
> >>
> >> *** If you feel like doing something brainless but
productive,
> > grab a
> >> As a programmer, your job is done here. If everything
worked,
> > you
> >> As a translator, you need to provide the lexicon for the
keys,
> > which in
> >> loncom/localize/localize, with the language code as
filename,
> > for
> >> example de.pm for the German translation. The file then
simply
> > looks
> >> Russian is purely experimental. Looks like UTF-8 is the way
to
> > encode

---

From: "Minoru Akiyama" <[email-masked]>
Date: Tue, 23 Sep 2003 14:34:52 +0900

Hi Gerd,

here's sample jp.pm encoded in UTF-8.
Please test it if it will work or not.

Minoru
----- Original Message ----- 
From: "Gerd Kortemeyer" <[email-masked]>
To: <[email-masked]>
Cc: "Gerd Kortemeyer" <[email-masked]>
Sent: Monday, September 22, 2003 4:34 AM
Subject: Re: [LON-CAPA-dev] Internationalization

last
it
keys,
and
distribute
format
productive,
worked,
keys,
filename,
simply
to