changeset 551:0c4e30a3cac1 stable-0.4.x

Ported [658:659] to 0.4.x branch.
author cmlenz
date Mon, 02 Jul 2007 09:10:40 +0000
parents 85a1044d9b12
children b590da4a45e8
files ChangeLog genshi/filters/i18n.py genshi/filters/tests/i18n.py
diffstat 3 files changed, 32 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,8 @@
    template is loaded (ticket #130). Note that the value for this option can
    not be specified as a string, only as an actual function object, which means
    it is not available for use through configuration files.
+ * The I18n filter now extracts messages from gettext functions even inside
+   ignored tags (ticket #132).
 
 
 Version 0.4.2
--- 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()
Copyright (C) 2012-2017 Edgewall Software