# HG changeset patch
# User cmlenz
# Date 1183367145 0
# Node ID da5cbf6d134d9b8c78755a0edcb0e1fd0e85bc92
# Parent c2e039c7e4395ae811e3d8962f00b513fa900574
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
diff --git a/genshi/filters/i18n.py b/genshi/filters/i18n.py
--- a/genshi/filters/i18n.py
+++ b/genshi/filters/i18n.py
@@ -236,14 +236,14 @@
xml_lang = XML_NAMESPACE['lang']
for kind, data, pos in stream:
+
if skip:
if kind is START:
skip += 1
if kind is END:
skip -= 1
- continue
- if kind is START:
+ if kind is START and not skip:
tag, attrs = data
if tag in self.ignore_tags or \
isinstance(attrs.get(xml_lang), basestring):
@@ -262,7 +262,7 @@
search_text=False):
yield lineno, funcname, text
- elif search_text and kind is TEXT:
+ elif not skip and search_text and kind is TEXT:
text = data.strip()
if text and filter(None, [ch.isalpha() for ch in text]):
yield pos[1], None, text
@@ -299,8 +299,9 @@
elif kind is SUB:
subkind, substream = data
- for lineno, funcname, text in self.extract(substream,
- gettext_functions):
+ messages = self.extract(substream, gettext_functions,
+ search_text=search_text and not skip)
+ for lineno, funcname, text in messages:
yield lineno, funcname, text
diff --git a/genshi/filters/tests/i18n.py b/genshi/filters/tests/i18n.py
--- a/genshi/filters/tests/i18n.py
+++ b/genshi/filters/tests/i18n.py
@@ -132,6 +132,30 @@
(7, None, u'All the best,\n Foobar', [])
], results)
+ def test_extraction_inside_ignored_tags(self):
+ buf = StringIO("""
+
+ """)
+ results = list(extract(buf, ['_'], [], {}))
+ self.assertEqual([
+ (5, '_', u'Please wait...', []),
+ ], results)
+
+ def test_extraction_inside_ignored_tags_with_directives(self):
+ buf = StringIO("""
+
+ """)
+ self.assertEqual([], list(extract(buf, ['_'], [], {})))
+
def suite():
suite = unittest.TestSuite()