On Thu, 2009-08-06 at 08:06 -0700, cArkraus wrote:
> Hey all,
> 
> I cant seem to get my (non-model-)forms datefield localized.
> 
> Here's my first attempt:
> some_date = fields.DateField(widget=widgets.DateInput(format=ugettext
> ('%d.%m.%Y')))

This would do the translation when the file is imported, which won't
reflect the user's current locale. The working rule is that you don't
use ugettext() outside of a view function (or something called directly
by a view).

> That's working fine, until the user switches his sessions language.
> Then, the date is still shown in the format(ie. '%d.%m.%Y') and not
> the correctly localized one(ie. '%Y-%m-%d').
> 
> Now, if I change to ugettext_lazy() like this:
> 
> some_date = fields.DateField(widget=widgets.DateInput
> (format=ugettext_lazy('%d.%m.%Y')))
> 
> I get a TemplateSyntaxError 'strftime() argument 1 must be string or
> read-only buffer, not __proxy__'

That's a bug in Django and Python (both sides share some blame: Python's
string handling is retarded in cases like this and Django doesn't work
around it correctly here). It's not particularly easy to work around it,
either.

Please open a ticket with this short example (only the ugettext_lazy()
case). Although you might also check that the i18n component in Trac
doesn't have a ticket open like this. I'm a little surprised it hasn't
been noticed before.

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to