Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #7027: template tags now corectly break tokens around strings m…

…arked for translation.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8769 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 86316f0be6837e3359b63e48e518b4f7d5b4d78d 1 parent 79968f9
Jacob Kaplan-Moss authored August 31, 2008
14  django/template/__init__.py
@@ -197,7 +197,19 @@ def __str__(self):
197 197
             self.contents[:20].replace('\n', ''))
198 198
 
199 199
     def split_contents(self):
200  
-        return list(smart_split(self.contents))
  200
+        split = []
  201
+        bits = iter(smart_split(self.contents))
  202
+        for bit in bits:
  203
+            # Handle translation-marked template pieces
  204
+            if bit.startswith('_("') or bit.startswith("_('"):
  205
+                sentinal = bit[2] + ')'
  206
+                trans_bit = [bit]
  207
+                while not bit.endswith(sentinal):
  208
+                    bit = bits.next()
  209
+                    trans_bit.append(bit)
  210
+                bit = ' '.join(trans_bit)
  211
+            split.append(bit)
  212
+        return split
201 213
 
202 214
 class Lexer(object):
203 215
     def __init__(self, template_string, origin):
6  tests/regressiontests/templates/tests.py
@@ -130,6 +130,12 @@ def test_template_sources(path, template_dirs, expected_sources):
130 130
             test_template_sources('/DIR1/index.HTML', template_dirs,
131 131
                                   ['/dir1/index.html'])
132 132
 
  133
+    def test_token_smart_split(self):
  134
+        # Regression test for #7027
  135
+        token = template.Token(template.TOKEN_BLOCK, 'sometag _("Page not found") value|yesno:_("yes,no")')
  136
+        split = token.split_contents()
  137
+        self.assertEqual(split, ["sometag", '_("Page not found")', 'value|yesno:_("yes,no")'])
  138
+
133 139
     def test_templates(self):
134 140
         template_tests = self.get_template_tests()
135 141
         filter_tests = filters.get_filter_tests()

0 notes on commit 86316f0

Please sign in to comment.
Something went wrong with that request. Please try again.