Mercurial > genshi > mirror
changeset 600:23a4784203ae trunk
Handle starargs and dstarargs in the I18n extraction code.
author | cmlenz |
---|---|
date | Wed, 15 Aug 2007 23:07:55 +0000 |
parents | eaf2a3171e12 |
children | 59fbd7586454 |
files | genshi/filters/i18n.py genshi/filters/tests/i18n.py |
diffstat | 2 files changed, 24 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/genshi/filters/i18n.py +++ b/genshi/filters/i18n.py @@ -405,12 +405,15 @@ if isinstance(node, ast.CallFunc) and isinstance(node.node, ast.Name) \ and node.node.name in gettext_functions: strings = [] - for arg in node.args: + def _add(arg): if isinstance(arg, ast.Const) \ and isinstance(arg.value, basestring): - strings.append(unicode(arg.value)) - elif not isinstance(arg, ast.Keyword): + strings.append(unicode(arg.value, 'utf-8')) + elif arg and not isinstance(arg, ast.Keyword): strings.append(None) + [_add(arg) for arg in node.args] + _add(node.star_args) + _add(node.dstar_args) if len(strings) == 1: strings = strings[0] else:
--- a/genshi/filters/tests/i18n.py +++ b/genshi/filters/tests/i18n.py @@ -42,6 +42,24 @@ self.assertEqual((2, 'ngettext', (u'Singular', u'Plural', None)), messages[0]) + def test_extract_funky_plural_form(self): + tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"> + ${ngettext(len(items), *widget.display_names)} + </html>""") + translator = Translator() + messages = list(translator.extract(tmpl.stream)) + self.assertEqual(1, len(messages)) + self.assertEqual((2, 'ngettext', (None, None)), messages[0]) + + def test_extract_gettext_with_unicode_string(self): + tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"> + ${gettext("Grüße")} + </html>""") + translator = Translator() + messages = list(translator.extract(tmpl.stream)) + self.assertEqual(1, len(messages)) + self.assertEqual((2, 'gettext', u'Gr\xfc\xdfe'), messages[0]) + def test_extract_included_attribute_text(self): tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"> <span title="Foo"></span>