Subject: [LON-CAPA-dev] I18N and dates

From: Jeremy Bowers <[email-masked]>
Date: Mon, 22 Sep 2003 12:01:49 -0500

I don't see anything in Locale::Maketext about dates. What's the state 
of the art on dates?

For instance, the Navmap returns due dates and such. For the "humanTime" 
function that converts dates into "1 hour and 49 minutes from now", I'd 
like my first internationalization cut to be "If English, use current 
function, if not English, just display the date in the correct Locale 
format." but I don't know how to do that last bit.

(If I'm not mistaken, Locale::Maketext can handle the full power of the 
humanTime function but will require a bit more knowlege from the 
translator; I like a bit more experience in I18N before tackling that.)

---

From: Gerd Kortemeyer <[email-masked]>
Date: Mon, 22 Sep 2003 17:41:37 -0400

Hi Jeremy,

> I don't see anything in Locale::Maketext about dates. What's the state 

I do not exactly know, but I believe somehow magically "localtime" is 
supposed to take care of that, I just don't know how to tell 
"localtime" (or all of Perl) which locale to use.

>
> For instance, the Navmap returns due dates and such. For the 
> "humanTime" function that converts dates into "1 hour and 49 minutes 
> from now", I'd like my first internationalization cut to be "If 
> English, use current function, if not English, just display the date 
> in the correct Locale format." but I don't know how to do that last 
> bit.

As a very very first cut, check out the code I already put into 
"humanTime" to either use your code (in case that the language starts 
with "en") or "localtime" else.

- Gerd.

---

From: Jeremy Bowers <[email-masked]>
Date: Mon, 22 Sep 2003 17:07:36 -0500

> with "en") or "localtime" else.

*grin* That'll teach me to open my mouth without checking out the latest 
CVS code ;-)

Looks like "man perllocale" has the goods...

-------------

You can switch locales as often as you wish at run time with the 
POSIX::setlocale() function:

         # This functionality not usable prior to Perl 5.004
         require 5.004;

         # Import locale-handling tool set from POSIX module.
         # This example uses: setlocale -- the function call
         #                    LC_CTYPE -- explained below
         use POSIX qw(locale_h);

         # query and save the old locale
         $old_locale = setlocale(LC_CTYPE);

         setlocale(LC_CTYPE, "fr_CA.ISO8859-1");
         # LC_CTYPE now in locale "French, Canada, codeset ISO 8859-1"

         setlocale(LC_CTYPE, "");
         # LC_CTYPE now reset to default defined by LC_ALL/LC_CTYPE/LANG
         # environment variables.  See below for documentation.

         # restore the old locale
         setlocale(LC_CTYPE, $old_locale);

--------------

Me again. That "setlocale" stuff looks a little dangerous, since it'll 
almost certainly propogate to the next request for a handler. Maybe a 
"cleanup" handler that resets the locale to a known state is called for, 
and then each handler can fiddle with it without fear it will leak into 
the next request.

Also note this puts us at the mercy of the locales on the system. AFAIK 
this is OK, *every* Linux system I've ever seen has a full locale 
database (in fact, it composes ~10% of the smallest Gentoo install CD 
image IIRC; on my system /usr/share/locale is 101MB now, it's not as 
large on a smaller install).

Also see the security notes on that manpage; I don't see anything 
terrifying but the more eyes the better.

http://www.perldoc.com/perl5.6/pod/perllocale.html#SECURITY