Re: Problems with i18n of field labels (newforms)

2007-07-25 Thread Peter Melvyn

On 7/25/07, Nathan Ostgard <[EMAIL PROTECTED]> wrote:

> What import are you aliasing as _?

Nothing, because I believed it is globally available and no import is
neccessary.

It was probably true before swap to UNICODE. And on the top of it, I
got somehow deranged and assumed that _() function is always lazy ->
this was a reason I was absolutely blind to this problem.

Thanks for your help, Peter

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Problems with i18n of field labels (newforms)

2007-07-25 Thread Nathan Ostgard

What import are you aliasing as _?

You have three options for gettext calls:
- ugettext, which translates as soon as it's *called*.
- ugettext_lazy, which does not translate until the attribute is
*accessed*.
- ugettext_noop, which translates at the last possible moment, such as
when the value is *rendered*.

For your case, you probably want to be using ugettext_lazy:

from django.utils.translation import ugettext_lazy as _

If that doesn't fix the problem, try using ugettext_noop.

On Jul 25, 2:54 am, "Peter Melvyn" <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I'm trying to embed login form into each page. I implemented it using
> new forms as inclusion tag. Form model looks like:
>   ...
>   sf_name = forms.CharField(required=True, label=_('Username:'),
> max_length=30,  widget=forms.TextInput(attrs={'class':'wsu-login-edit'}))
>   ...
>
> If I change language by setting session['django-language'], page is
> re-rendered correctly using the new language, except labels defined in
>  form model (texts translated in underlying inclusion template are
> OK).
> When re-rendering page, form is instantiated again, but texts in
> labels does not correspond to current
> request.session['django-language'] value. I tried to trace Django-code
> down, but I was lost somewhere in copy.py
>
> #
>
> Having this written, I got an idea to test another new form instances
> and it seems that those instances do not work as well i.e. instance
> does not translate labels if language is session changed is changed.
>
> #
>
> Please, could anybody advise me, what I'm missing?
>
> Thank, Peter


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Problems with i18n of field labels (newforms)

2007-07-25 Thread Peter Melvyn

Hi all,

I'm trying to embed login form into each page. I implemented it using
new forms as inclusion tag. Form model looks like:
  ...
  sf_name = forms.CharField(required=True, label=_('Username:'),
max_length=30,  widget=forms.TextInput(attrs={'class':'wsu-login-edit'}))
  ...

If I change language by setting session['django-language'], page is
re-rendered correctly using the new language, except labels defined in
 form model (texts translated in underlying inclusion template are
OK).
When re-rendering page, form is instantiated again, but texts in
labels does not correspond to current
request.session['django-language'] value. I tried to trace Django-code
down, but I was lost somewhere in copy.py

#

Having this written, I got an idea to test another new form instances
and it seems that those instances do not work as well i.e. instance
does not translate labels if language is session changed is changed.

#

Please, could anybody advise me, what I'm missing?


Thank, Peter

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---