Fixed #4982 -- Fixed handling of '%' symbols in 'blocktrans' blocks. Thanks,

permonik@mesias.brnonet.cz.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@6565 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2007-10-20 12:29:56 +00:00
parent 3742e35df3
commit cc6139ab50
1 changed files with 6 additions and 2 deletions

View File

@ -1,3 +1,5 @@
import re
from django.template import Node, Variable from django.template import Node, Variable
from django.template import TemplateSyntaxError, TokenParser, Library from django.template import TemplateSyntaxError, TokenParser, Library
from django.template import TOKEN_TEXT, TOKEN_VAR from django.template import TOKEN_TEXT, TOKEN_VAR
@ -68,9 +70,11 @@ class BlockTranslateNode(Node):
count = self.counter.resolve(context) count = self.counter.resolve(context)
context[self.countervar] = count context[self.countervar] = count
plural = self.render_token_list(self.plural) plural = self.render_token_list(self.plural)
result = translation.ungettext(singular, plural, count) % context result = translation.ungettext(singular, plural, count)
else: else:
result = translation.ugettext(singular) % context result = translation.ugettext(singular)
# Escape all isolated '%' before substituting in the context.
result = re.sub('%(?!\()', '%%', result) % context
context.pop() context.pop()
return result return result