changeset 597:19345798ba5e stable-0.4.x 0.4.4

Ported [710] to 0.4.x branch.
author cmlenz
date Tue, 14 Aug 2007 08:58:56 +0000
parents 66fd7f370acb
children f35e1080420c
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
@@ -1,6 +1,6 @@
 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
@@ -11,7 +11,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
@@ -313,7 +313,6 @@
                     yield lineno, funcname, text
 
 
-
 def extract(fileobj, keywords, comment_tags, options):
     """Babel extraction method for Genshi templates.
     
@@ -332,10 +331,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()
@@ -343,7 +347,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
@@ -123,6 +123,18 @@
             (8, 'ngettext', (u'You have %d item', u'You have %d items'), []),
         ], 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'), []),
+        ], 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