On Thu, Jan 6, 2011 at 5:07 AM, Jonathan S <[email protected]> wrote:
>
>> You aren't supposed to use _('Foo') as a standalone variable.
>> (see last paragraph
>> herehttp://docs.djangoproject.com/en/1.2/topics/i18n/internationalization...)
>
>
> Why shouldn't I use it as a standalone variable? (A language should
> have a *context free* grammar, which means, that the underscore
> function can be used in any variable. But that's no problem in
> Django.)
>
>
> That's not the point, the bug applies to any variable, template tag or
> template filter parameter. It seems like a bug to me:
> Any underscore function is translated during the initialisation of the
> template, and that is wrong to me.
>
> I guess, also for this one, like mentioned in the documentation.
> {% some_special_tag _("Page not found") value|yesno:_("yes,no") %}
>
> And I did a quick test:
>
>
> with language('nl'):
> t = Template("{% load i18n %}{{ 1|yesno:_('yes,no') }}")
>
> t.render(Context()) # Will output 'ja'
> with language('en'):
> t.render(Context()) # Will still output 'ja', even if the language
> is English now...
Weird, it's working here:
In [1]: from django.utils import translation
In [2]: from django.template import Template, Context
In [3]:
In [4]:
In [5]: def language(language_code):
...: class with_block(object):
...: def __enter__(self):
...: self._old_language = translation.get_language()
...: translation.activate(language_code)
...: def __exit__(self, *args):
...: translation.activate(self._old_language)
...: return with_block()
...:
In [6]: with language('nl'):
...: Template("{% load i18n %}{{ 1|yesno:_('yes,no,maybe')
}}").render(Context())
...:
...:
Out[6]: u'ja'
In [7]: with language('en'):
Template("{% load i18n %}{{ 1|yesno:_('yes,no,maybe') }}").render(Context())
...:
...:
Out[7]: u'yes'
In [8]: with language('nl'):
Template("{% load i18n %}{{ 0|yesno:_('yes,no,maybe') }}").render(Context())
....:
....:
Out[8]: u'nee'
In [9]: with language('en'):
Template("{% load i18n %}{{ 0|yesno:_('yes,no,maybe') }}").render(Context())
....:
....:
Out[9]: u'no'
--
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en.