# HG changeset patch # User cmlenz # Date 1181497070 0 # Node ID e10f82c1d4c4cb0188fd9fcdd9d58b57153d4267 # Parent 3c6421bca777facd472148d8f1070a5346e1a993 Add unit tests for extracting translator comments from python sources. diff --git a/babel/messages/tests/extract.py b/babel/messages/tests/extract.py --- a/babel/messages/tests/extract.py +++ b/babel/messages/tests/extract.py @@ -22,9 +22,29 @@ def test_unicode_string_arg(self): buf = StringIO("msg = _(u'Foo Bar')") - messages = list(extract.extract_python(buf, ('_',), {}, [])) + messages = list(extract.extract_python(buf, ('_',), [], {})) self.assertEqual('Foo Bar', messages[0][2]) + def test_comment_tag(self): + buf = StringIO(""" +# NOTE: A translation comment +msg = _(u'Foo Bar') +""") + messages = list(extract.extract_python(buf, ('_',), ['NOTE'], {})) + self.assertEqual('Foo Bar', messages[0][2]) + self.assertEqual(['NOTE: A translation comment'], messages[0][3]) + + def test_comment_tag_multiline(self): + buf = StringIO(""" +# NOTE: A translation comment +# with a second line +msg = _(u'Foo Bar') +""") + messages = list(extract.extract_python(buf, ('_',), ['NOTE'], {})) + self.assertEqual('Foo Bar', messages[0][2]) + self.assertEqual(['NOTE: A translation comment', 'with a second line'], + messages[0][3]) + def suite(): suite = unittest.TestSuite() diff --git a/doc/catalogs.txt b/doc/catalogs.txt --- a/doc/catalogs.txt +++ b/doc/catalogs.txt @@ -185,6 +185,12 @@ :rtype: ``iterator`` """ +.. note:: Any strings in the tuples produced by this function must be either + ``unicode`` objects, or ``str`` objects using plain ASCII characters. + That means that if sources contain strings using other encodings, it + is the job of the extractor implementation to do the decoding to + ``unicode`` objects. + Next, you should register that function as an entry point. This requires your ``setup.py`` script to use `setuptools`_, and your package to be installed with the necessary metadata. If that's taken care of, add something like the