Author: jezdez
Date: 2010-09-30 21:02:01 -0500 (Thu, 30 Sep 2010)
New Revision: 13967
Modified:
django/trunk/django/templatetags/i18n.py
django/trunk/tests/regressiontests/templates/tests.py
Log:
Fixed #13568 -- Fixed the blocktrans tag to not raise a KeyError if the number
of variables in the singular and the plural block differ. Thanks, deloide.
Modified: django/trunk/django/templatetags/i18n.py
===================================================================
--- django/trunk/django/templatetags/i18n.py 2010-10-01 02:01:38 UTC (rev
13966)
+++ django/trunk/django/templatetags/i18n.py 2010-10-01 02:02:01 UTC (rev
13967)
@@ -76,8 +76,10 @@
if self.plural and self.countervar and self.counter:
count = self.counter.resolve(context)
context[self.countervar] = count
- plural, vars = self.render_token_list(self.plural)
+ plural, plural_vars = self.render_token_list(self.plural)
result = translation.ungettext(singular, plural, count)
+ if count != 1:
+ vars = plural_vars
else:
result = translation.ugettext(singular)
# Escape all isolated '%' before substituting in the context.
Modified: django/trunk/tests/regressiontests/templates/tests.py
===================================================================
--- django/trunk/tests/regressiontests/templates/tests.py 2010-10-01
02:01:38 UTC (rev 13966)
+++ django/trunk/tests/regressiontests/templates/tests.py 2010-10-01
02:02:01 UTC (rev 13967)
@@ -1116,6 +1116,9 @@
'i18n24': ("{% load i18n %}{% trans 'Page not found'|upper %}",
{'LANGUAGE_CODE': 'de'}, u'SEITE NICHT GEFUNDEN'),
'i18n25': ('{% load i18n %}{% trans somevar|upper %}', {'somevar':
'Page not found', 'LANGUAGE_CODE': 'de'}, u'SEITE NICHT GEFUNDEN'),
+ # translation of plural form with extra field in singular form
(#13568)
+ 'i18n26': ('{% load i18n %}{% blocktrans with myextra_field as
extra_field count number as counter %}singular {{ extra_field }}{% plural
%}plural{% endblocktrans %}', {'number': 1, 'myextra_field': 'test'}, "singular
test"),
+
### HANDLING OF TEMPLATE_STRING_IF_INVALID
###################################
'invalidstr01': ('{{ var|default:"Foo" }}', {}, ('Foo','INVALID')),
--
You received this message because you are subscribed to the Google Groups
"Django updates" 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-updates?hl=en.