But you aren't using the i18n support correctly.
You aren't supposed to use _('Foo') as a standalone variable.
(see last paragraph here
http://docs.djangoproject.com/en/1.2/topics/i18n/internationalization/#other-tags)
Also,
* You need to load the i18n template tag library
* Use the trans tag.
Try using Template("{% load i18n %}{% trans 'Yes' %}").render(...)
to achieve what you want.
All this is covered in the docs:
--
Ramiro Morales
I thought that if you wanted to apply a filter to a string in a
template that you had to use _ instead of {% trans %}.
-- Gert
Mobile: +32 498725202
Twitter: @gvangool
Web: http://gert.selentic.net
> --
> You received this message because you are subscribed to the Google Groups "Django developers" group.
> To post to this group, send email to django-d...@googlegroups.com.
> To unsubscribe from this group, send email to django-develop...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
>
>
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'
> 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
I've opened ticket [1]15157 in the Django issue tracker for this report.
Any feedback or correction is welcome.
Thanks!
1. http://code.djangoproject.com/ticket/15157
--
Ramiro Morales