Mercurial > genshi > genshi-test
changeset 549:da5cbf6d134d
The I18n filter now extracts text from translation functions in ignored tags. Fixes #132.
author | cmlenz |
---|---|
date | Mon, 02 Jul 2007 09:05:45 +0000 |
parents | c2e039c7e439 |
children | ed5a6d9e2767 |
files | genshi/filters/i18n.py genshi/filters/tests/i18n.py |
diffstat | 2 files changed, 30 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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("""<html xmlns:py="http://genshi.edgewall.org/"> + <script type="text/javascript"> + $('#llist').tabs({ + remote: true, + spinner: "${_('Please wait...')}" + }); + </script> + </html>""") + results = list(extract(buf, ['_'], [], {})) + self.assertEqual([ + (5, '_', u'Please wait...', []), + ], results) + + def test_extraction_inside_ignored_tags_with_directives(self): + buf = StringIO("""<html xmlns:py="http://genshi.edgewall.org/"> + <script type="text/javascript"> + <py:if test="foobar"> + alert("This shouldn't be extracted"); + </py:if> + </script> + </html>""") + self.assertEqual([], list(extract(buf, ['_'], [], {}))) + def suite(): suite = unittest.TestSuite()