Django

Code

Changeset 8769

Show
Ignore:
Timestamp:
08/31/08 13:28:06 (3 months ago)
Author:
jacob
Message:

Fixed #7027: template tags now corectly break tokens around strings marked for translation.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/template/__init__.py

    r8393 r8769  
    198198 
    199199    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 
    201213 
    202214class Lexer(object): 
  • django/trunk/tests/regressiontests/templates/tests.py

    r8766 r8769  
    130130            test_template_sources('/DIR1/index.HTML', template_dirs, 
    131131                                  ['/dir1/index.html']) 
     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")']) 
    132138 
    133139    def test_templates(self):