Skip to content

Commit

Permalink
Merge pull request #32 from voipro/fix-structure-text
Browse files Browse the repository at this point in the history
structure/text prefix for tal:content/replace
  • Loading branch information
wichert committed Jun 10, 2014
2 parents 7951e37 + 45e7fd8 commit 48ee37f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/lingua/extractors/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def _open(filename):


ENGINE_PREFIX = re.compile(r'^\s*([a-z\-_]+):\s*')
STRUCTURE_PREFIX = re.compile(r'\s*(structure|text)\s+(.*)')
WHITESPACE = re.compile(u"\s+")
EXPRESSION = re.compile(u"\s*\${(.*?)}\s*")
UNDERSCORE_CALL = re.compile("_\(.*\)")
Expand Down Expand Up @@ -165,6 +166,9 @@ def get_code_for_attribute(self, attribute, value):
if attribute[1] in ['content', 'replace']:
(engine, value) = get_tales_engine(value)
if engine == 'python':
m = STRUCTURE_PREFIX.match(value)
if m is not None:
value = m.group(2)
self._assert_valid_python(value)
yield value
if attribute[1] == 'define':
Expand Down
13 changes: 13 additions & 0 deletions tests/extractors/test_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,3 +448,16 @@ def test_nested_braces(self):
assert list(get_python_expressions(
'''${resource_url(_query={'one': 'one'})}''')) == \
['''resource_url(_query={'one': 'one'})''']


@pytest.mark.usefixtures('fake_source')
def test_ignore_structure_in_replace():
global source
source = b'''\
<html xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:domain="lingua">
<dummy tal:replace="structure _('foo')">Dummy</dummy>
</html>
'''
messages = list(extract_xml('filename', _options()))
assert messages[0].msgid == u'foo'

0 comments on commit 48ee37f

Please sign in to comment.