On Thu, Jan 6, 2011 at 8:15 AM, Ramiro Morales <[email protected]> wrote:
> Weird, it's working here:
Ignore me, I was creating a new Template instance. I can reproduce it:
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('de'): z = Template("{% load i18n %}{{
0|yesno:_('yes,no,maybe') }}")
...:
In [7]: with language('nl'):
...: z.render(Context())
...:
...:
Out[7]: u'Nein'
In [8]: with language('en'):
...: z.render(Context())
...:
...:
Out[8]: u'Nein'
If I apply this small fix to our code:
http://paste.pocoo.org/show/315758/
Things work correctly:
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('de'): z = Template("{% load i18n %}{{
0|yesno:_('yes,no,maybe') }}")
...:
In [7]: with language('nl'):
...: z.render(Context())
...:
...:
Out[7]: u'nee'
In [8]: with language('en'):
...: z.render(Context())
...:
...:
Out[8]: u'no'
and out test suite still runs, but I need to add regression tests.
Will ask about this to I18N maintainers/contributors. Thanks!
--
Ramiro Morales
--
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.