# HG changeset patch # User cmlenz # Date 1187081743 0 # Node ID f436c7db99f529dbdd4a38e06bfa5dddc004111d # Parent 0fb43dc2e1652b5c67ba14066695e6fe1ab722f7 Follow-up to [708]. The added `extract_text` option wasn't actually being handled by the Babel extraction plugin. diff --git a/ChangeLog b/ChangeLog --- 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 diff --git a/genshi/filters/i18n.py b/genshi/filters/i18n.py --- 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, [] 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 @@ -279,6 +279,18 @@ []), ], 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', None), []), + ], 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