Thanks, Malcolm! I filed the ugettext_lazy problem under #11701 and attached a patch that fixes it by using force_unicode() on the format in DateWidget.
FWIW, users could also workaround this thing by using their forms __init__, like so: def __init__(self, *args, **kwargs): super(SomeForm, self).__init__(*args, **kwargs) self.fields['some_date'].widget.format = ugettext_lazy('%d.%m. %Y') Seems, the __proxy__ then already is a string/unicode when reaching the widgets formatting method. On Aug 7, 5:39 am, Malcolm Tredinnick <malc...@pointy-stick.com> wrote: > On Fri, 2009-08-07 at 11:56 +1000, Malcolm Tredinnick wrote: > > 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. > > This came about ambiguously: without hunting down the offending place > right at the moment, I'm still fairly certain it's easy to fix this in > Django's core. I can't think of an easy way to work around it in Django > apps, however (that might be because I'm not imaginative enough). > > 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 -~----------~----~----~----~------~----~------~--~---