views:

631

answers:

1

Hello everyone,

I've been playing with Django's i18n system and it seems to be mostly working. However, dates in model code seem to be causing a problem.

I use datetime.strftime to populate a few CHOICES tuples which are then used in forms.

From what I understood, django will set the locale to the user's choice so that datetime.strftime() will output in the appropriate language, but this doesn't seem to happen.

What am I missing here?

If I set the locale manually (eg. locale.setlocale(locale.LC_TIME,'de_DE.UTF-8') ) datetime does translate correctly.

Thanks,

Tom

+2  A: 

Django does not set locale for translation, just loads translation catalog. To get desired effect you have either set locale (which is not a good option since it works process-wide) or use specialized library. I recommend Babel which has nice Django integration.

zgoda
Ah, thank you zgoda. I rather think the django docs should be a little more explicit, they rather suggest that the i18n does more that it actually does.
Tom Playford
I'd say it does "i18n" as advertized. Formatting dates and monetary values is "l10n" (localization) which is absent in Django anyways. That's the domain of Babel library. :)
zgoda