]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Add unit tests for extracting translator comments from python sources.
authorChristopher Lenz <cmlenz@gmail.com>
Sun, 10 Jun 2007 17:37:50 +0000 (17:37 +0000)
committerChristopher Lenz <cmlenz@gmail.com>
Sun, 10 Jun 2007 17:37:50 +0000 (17:37 +0000)
babel/messages/tests/extract.py
doc/catalogs.txt

index a02f9154cb5aa854b677d0a4c56dfe9edb85006b..6a8672257ac47b654ec0ac3b7dba1a4338b6e03f 100644 (file)
@@ -22,9 +22,29 @@ class ExtractPythonTestCase(unittest.TestCase):
 
     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()
index a3e86eaa1f635de3d458bd9934950bacbf350c98..a6c4110e883b3771f3971e216761fbdc76b27908 100644 (file)
@@ -185,6 +185,12 @@ need to implement a function that complies with the following interface:
         :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