diff -r 6641e941ef1e -r ff1a9aa48cfd app/django/template/__init__.py --- a/app/django/template/__init__.py Tue Oct 14 12:36:55 2008 +0000 +++ b/app/django/template/__init__.py Tue Oct 14 16:00:59 2008 +0000 @@ -197,7 +197,19 @@ self.contents[:20].replace('\n', '')) def split_contents(self): - return list(smart_split(self.contents)) + split = [] + bits = iter(smart_split(self.contents)) + for bit in bits: + # Handle translation-marked template pieces + if bit.startswith('_("') or bit.startswith("_('"): + sentinal = bit[2] + ')' + trans_bit = [bit] + while not bit.endswith(sentinal): + bit = bits.next() + trans_bit.append(bit) + bit = ' '.join(trans_bit) + split.append(bit) + return split class Lexer(object): def __init__(self, template_string, origin): @@ -467,7 +479,7 @@ >>> len(fe.filters) 2 >>> fe.var - 'variable' + This class should never be instantiated outside of the get_filters_from_token helper function. @@ -485,9 +497,14 @@ (token[:upto], token[upto:start], token[start:])) if var == None: var, constant, i18n_constant = match.group("var", "constant", "i18n_constant") - if i18n_constant: - var = '"%s"' % _(i18n_constant.replace(r'\"', '"')) - elif constant: + if i18n_constant is not None: + # Don't pass the empty string to gettext, because the empty + # string translates to meta information. + if i18n_constant == "": + var = '""' + else: + var = '"%s"' % _(i18n_constant.replace(r'\"', '"')) + elif constant is not None: var = '"%s"' % constant.replace(r'\"', '"') upto = match.end() if var == None: @@ -598,15 +615,15 @@ a hard-coded string (if it begins and ends with single or double quote marks):: - >>> c = {'article': {'section':'News'}} + >>> c = {'article': {'section':u'News'}} >>> Variable('article.section').resolve(c) u'News' >>> Variable('article').resolve(c) - {'section': 'News'} + {'section': u'News'} >>> class AClass: pass >>> c = AClass() >>> c.article = AClass() - >>> c.article.section = 'News' + >>> c.article.section = u'News' >>> Variable('article.section').resolve(c) u'News'