Home
The Toolkit for Online Communities
17469 Community Members, 1 member online, 2493 visitors today
Log In Register
OpenACS Home : Forums : .LRN Q&A : How to internationalize dates? : One Message

Forum .LRN Q&A: Re: How to internationalize dates?

Collapse
Posted by Lars Pind on
Rocael,

Sorry, this isn't documented properly yet, but it's really quite simple.

What you do is get the date from the database in ansi format, like this:

to_char(forums_messages.posting_date, 'YYYY-MM-DD HH24:MI:SS') as posting_date_ansi

You don't need the time part if it's not relevant. Then just say 'YYYY-MM-DD'.

Then you run that through the procedure called "lc_time_fmt" with a format specifier, and an optional locale (defaults to connection locale, which will user locale if the user has one set, otherwise server locale). Example:

# Convert to user's date/time format
set row(posting_date_pretty) [lc_time_fmt $row(posting_date_ansi) "%x %X"]

Look at the documentation for lc_time_fmt to see what the available formats are. Most of them aren't directly useful for localization, in that they translate to month, day, year, etc. directly. Here are the ones that are relevant to internationalizing dates:

      %c          FDCC-set's appropriate date and time
                  representation.
      %q          Long date without weekday (OpenACS addition to the standard)
      %Q          Long date with weekday (OpenACS addition to the standard)
      %x          FDCC-set's appropriate date representation.
      %X          FDCC-set's appropriate time representation.

The details of these formats for various locales are all defined in the packages/acs-lang/tcl/localization-data-init.tcl file. Unfortunatley, the only way to edit these is directly in the file, there's no web UI. We haven't had the budget to do that yet, though we'd really like to.

The example above is taken from packages/forums/tcl/messages-procs.tcl.

For more details, take a look at packages/acs-lang/tcl/localization-procs.tcl and packages/acs-lang/tcl/localization-data-init.tcl.

It's really simple, and it works really well. In fact, this code was mostly written by Jeff Davis, I just added a couple more formats, locales, and then rewrote a bunch of packages to make use of it.

All of this is on HEAD in the CVS repository, of course.

Let me know if you have any more questions.

/Lars