If you use a language that's a bit more complex than English (or most western languages, that is), you'll probably have some problems displaying dates that actually don't look like computer-generated.

Django-localdates deals with this problem, and tries to tackle the general problem of internationalizing dates.

The main issue is, if you want your application to be truly international, you have to find a translator that will translate your templates, messages, emails and everything else that a user might see. However, translating dates isn't that straightforward.

The easiest example is US vs British date format. US citizens write the month first, while the British write the month after the date. So, if you have a template that uses now "d F Y", it will look good for a British person, but not for an US person. A Russian would be appaled, because Март isn't the same as марта!

django-localdates tries to overcome all this by defining translatable date formats. Every language has a "formal" way to display dates, a short way, a numeric way and so on. So if we could just specify "This date should be formatted to be short" or "This day is the full deal", and have each translator specify what full or short means, we could solve this problem.

Here is the usage:

{{ datenow|ldate:"{FULL_DATE}" }} 

{{ datenow|ldate:"{NUM_DATE}" }}

and so on and so forth. Give it a try!. Instructions here.

March 25, 2008, 2:22 p.m. More (235 words) 7 comments Feed
Previous entry: On extreme programming
Next entry: Painless local commits: a VCS comparison

Comments

1

Comment by zgoda , 4 years, 1 month ago :

Why not use babel http://babel.edgewall.org/ ? It has much more than just dates formatting (and uses very standard CLDR to get formats).

2

Comment by Nick , 4 years, 1 month ago :

Sorry, my post is related to your quite old post titled "Porting to numpy". But commenting there was closed, so I decided to comment it here. Hope it will help you. To speed up python you can use psyco. http://psyco.sourceforge.net/
it is a dynamic compiler for python that will speed up your program in 2-100 times.

3

Comment by Orestis Markou , 4 years, 1 month ago :

@zgoda Babel does seem interesting. I wonder if I can reuse parts of it. It doesn't seem to play with Django out of the box, so perhaps an adapter is the only thing that's needed.

4

Comment by Orestis Markou , 4 years, 1 month ago :

@Nick: Thanks for that, I've already tried psyco but it didn't speed up enough to make a difference. It's a case by case thing...

5

Comment by Hraban , 4 years, 1 month ago :

Is there a reason you don't use Python's locale module?
http://docs.python.org/lib/module-loc...
(I never tried it with exotic languages, but it works well with European.)

6

Comment by Orestis Markou , 4 years, 1 month ago :

This is a problem specific to dates, present only in languages that can't present every desired date format using just a set of month names.

This approach extends the date format in Django in a generic way, but at the moment the only extensions are to add different forms of months, and a generic way to specify date formats.

Babel looks good, but the locale module is inadequate.

7

Comment by Orestis Markou , 4 years, 1 month ago :

It seems like either Babel or the CLDR contain wrong information for Greek. There's no difference between LLLL and MMMM (The first should print 'Απρίλιος', and the second 'Απριλίου').

I still can't find a way to print the third form, 'Απρίλιο'. For Greek it's easy, it's only taking the last letter off.

I may write a parser for the CLDR formats and adapt it to Django.


This post is older than 30 days and comments have been turned off.