List Info

Thread: Newform and i18n




Newform and i18n
country flaguser name
United States
2007-03-30 03:43:44
Hello,

Here is how I define a form in my views:

class MyForm(forms.Form):
    name        = forms.CharField(label=_('Name'))
    ...

The problem is _('Name') is translated when I restart the
server
(Django or Apache),
but not when I switch the browser locale.

I tried both
from django.utils.translation import gettext_lazy as _
and
from django.utils.translation import gettext as _

Any idea ?

Olive.


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


Re: Newform and i18n
country flaguser name
Australia
2007-03-30 03:53:48
On Fri, 2007-03-30 at 01:43 -0700, olive wrote:
> Hello,
> 
> Here is how I define a form in my views:
> 
> class MyForm(forms.Form):
>     name        = forms.CharField(label=_('Name'))
>     ...
> 
> The problem is _('Name') is translated when I restart
the server
> (Django or Apache),
> but not when I switch the browser locale.
> 
> I tried both
> from django.utils.translation import gettext_lazy as _
> and
> from django.utils.translation import gettext as _
> 
> Any idea ?

I would hazard a guess (and I may be wrong and thus doing
Adrian a
disservice) that i18n support for newforms has not been
completely
though through yet. There seem to be a couple of places in
the code that
need some i18n support put in.

As a general rule, any code that is executed when a file is
imported
should be using gettext_lazy as the translation function.
This would
include things like the class attributes you are defining in
your
example. A consequence of this is that the code which uses
those strings
needs to call gettext() on the string in order to force the
translation.
Right at this moment, newforms does not do the gettext call.
So you
problem is not completely solvable without a bugfix in
Django.

If you could file a ticket about this and put it in the
internationalisation component -- even assign it to me (I am
mtredinnick
in Trac) -- we won't forget about it and I'll make sure we
get the right
hooks in the code.

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-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )