# HG changeset patch # User cmlenz # Date 1187081936 0 # Node ID 2c52ec2c9d7ef5fec3b545549a55d78aca55890a # Parent 6d51c8df5d5a2067cfcfdb0a6bf4daa91723f75a Ported [710] to 0.4.x branch. diff --git a/ChangeLog b/ChangeLog --- 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 diff --git a/genshi/filters/i18n.py b/genshi/filters/i18n.py --- 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, [] 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 @@ -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(""" +

Foo

+ ${ngettext("Singular", "Plural", num)} + """) + 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}}, diff --git a/setup.py b/setup.py --- 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