changeset 596:f436c7db99f5

Follow-up to [708]. The added `extract_text` option wasn't actually being handled by the Babel extraction plugin.
author cmlenz
date Tue, 14 Aug 2007 08:55:43 +0000
parents 0fb43dc2e165
children e4ec94fcb0c0
files ChangeLog genshi/filters/i18n.py genshi/filters/tests/i18n.py setup.py
diffstat 4 files changed, 22 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -26,7 +26,7 @@
 
 Version 0.4.4
 http://svn.edgewall.org/repos/genshi/tags/0.4.4/
-(?, from branches/stable/0.4.x)
+(Aug 14, 2007, from branches/stable/0.4.x)
 
  * Fixed augmented assignment to local variables in Python code blocks.
  * Fixed handling of nested function and class definitions in Python code
@@ -37,7 +37,8 @@
    cached template is removed or renamed, where it previously was passing up
    an `OSError`.
  * The Genshi I18n filter can be configured to only extract messages found in
-   `gettext` function calls, ignoring any text nodes and attribute values.
+   `gettext` function calls, ignoring any text nodes and attribute values
+   (ticket #138).
 
 
 Version 0.4.3
--- a/genshi/filters/i18n.py
+++ b/genshi/filters/i18n.py
@@ -463,7 +463,6 @@
 
     return parts
 
-
 def extract(fileobj, keywords, comment_tags, options):
     """Babel extraction method for Genshi templates.
     
@@ -482,10 +481,15 @@
         template_class = getattr(__import__(module, {}, {}, [clsname]), clsname)
     encoding = options.get('encoding', None)
 
+    extract_text = options.get('extract_text', True)
+    if isinstance(extract_text, basestring):
+        extract_text = extract_text.lower() in ('1', 'on', 'yes', 'true')
+
     ignore_tags = options.get('ignore_tags', Translator.IGNORE_TAGS)
     if isinstance(ignore_tags, basestring):
         ignore_tags = ignore_tags.split()
     ignore_tags = [QName(tag) for tag in ignore_tags]
+
     include_attrs = options.get('include_attrs', Translator.INCLUDE_ATTRS)
     if isinstance(include_attrs, basestring):
         include_attrs = include_attrs.split()
@@ -493,7 +497,7 @@
 
     tmpl = template_class(fileobj, filename=getattr(fileobj, 'name', None),
                           encoding=encoding)
-    translator = Translator(None, ignore_tags, include_attrs)
+    translator = Translator(None, ignore_tags, include_attrs, extract_text)
     for lineno, func, message in translator.extract(tmpl.stream,
                                                     gettext_functions=keywords):
         yield lineno, func, message, []
--- a/genshi/filters/tests/i18n.py
+++ b/genshi/filters/tests/i18n.py
@@ -279,6 +279,18 @@
                              []),
         ], results)
 
+    def test_extraction_without_text(self):
+        buf = StringIO("""<html xmlns:py="http://genshi.edgewall.org/">
+          <p title="Bar">Foo</p>
+          ${ngettext("Singular", "Plural", num)}
+        </html>""")
+        results = list(extract(buf, ['_', 'ngettext'], [], {
+            'extract_text': 'no'
+        }))
+        self.assertEqual([
+            (3, 'ngettext', (u'Singular', u'Plural', None), []),
+        ], results)
+
     def test_text_template_extraction(self):
         buf = StringIO("""${_("Dear %(name)s") % {'name': name}},
         
--- a/setup.py
+++ b/setup.py
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2006 Edgewall Software
+# Copyright (C) 2006-2007 Edgewall Software
 # All rights reserved.
 #
 # This software is licensed as described in the file COPYING, which
Copyright (C) 2012-2017 Edgewall Software