← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~danilo/pygettextpo/msgctxt-support into lp:pygettextpo

 

Данило Шеган has proposed merging lp:~danilo/pygettextpo/msgctxt-support into lp:pygettextpo with lp:~danilo/pygettextpo/simplify as a prerequisite.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~danilo/pygettextpo/msgctxt-support/+merge/92618

Provide support for msgctxt field in GNU gettext PO files.

This depends on the 'simplify' branch which simplifies the C code to reduce repeating of the same pattern. A new test is added to ensure this works like the other fields.

http://www.gnu.org/software/gettext/manual/gettext.html#PO-Files
-- 
https://code.launchpad.net/~danilo/pygettextpo/msgctxt-support/+merge/92618
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~danilo/pygettextpo/msgctxt-support into lp:pygettextpo.
=== modified file 'gettextpo.c'
--- gettextpo.c	2012-02-11 12:01:17 +0000
+++ gettextpo.c	2012-02-11 12:01:17 +0000
@@ -11,6 +11,7 @@
 #include <gettext-po.h>
 
 #define MIN_REQUIRED_GETTEXTPO_VERSION 0x000E02
+#define MIN_MSGCTXT_GETTEXTPO_VERSION 0x000F00
 
 #if LIBGETTEXTPO_VERSION < MIN_REQUIRED_GETTEXTPO_VERSION
 #  error "this module requires gettext >= 0.14.2"
@@ -564,6 +565,20 @@
     Py_RETURN_NONE;
 }
 
+/* msgctxt support was added in 0.15. */
+#if LIBGETTEXTPO_VERSION >= MIN_MSGCTXT_GETTEXTPO_VERSION
+
+PyDoc_STRVAR(doc_pypo_message_set_msgctxt,
+"M.set_msgctxt(msgctxt) -> None.  Set the msgctxt for this PoMessage");
+
+static PyObject *
+pypo_message_set_msgctxt(PyPoMessage *self, PyObject *args)
+{
+    return _message_set_field(self, args, "O:set_msgctxt",
+                                    &po_message_set_msgctxt);
+}
+#endif
+
 
 PyDoc_STRVAR(doc_pypo_message_set_msgid,
 "M.set_msgid(msgid) -> None.  Set the msgid for this PoMessage");
@@ -727,6 +742,11 @@
 }
 
 static PyMethodDef pypo_message_methods[] = {
+/* msgctxt support was added in 0.15. */
+#if LIBGETTEXTPO_VERSION >= MIN_MSGCTXT_GETTEXTPO_VERSION
+    { "set_msgctxt", (PyCFunction)pypo_message_set_msgctxt, METH_VARARGS,
+      doc_pypo_message_set_msgctxt },
+#endif
     { "set_msgid", (PyCFunction)pypo_message_set_msgid, METH_VARARGS,
       doc_pypo_message_set_msgid },
     { "set_msgid_plural", (PyCFunction)pypo_message_set_msgid_plural, METH_VARARGS,
@@ -744,6 +764,23 @@
     { NULL, 0, 0 }
 };
 
+/* msgctxt support was added in 0.15. */
+#if LIBGETTEXTPO_VERSION >= MIN_MSGCTXT_GETTEXTPO_VERSION
+PyDoc_STRVAR(doc_pypo_message_msgctxt,
+"M.msgctxt -> the msgctxt for this PoMessage.");
+
+static PyObject *
+pypo_message_get_msgctxt(PyPoMessage *self, void *closure)
+{
+    const char *msgctxt;
+
+    msgctxt = po_message_msgctxt(self->msg);
+    if (msgctxt)
+	return PyString_FromString(msgctxt);
+    Py_RETURN_NONE;
+}
+#endif
+
 PyDoc_STRVAR(doc_pypo_message_msgid,
 "M.msgid -> the msgid for this PoMessage.");
 
@@ -826,6 +863,11 @@
 
 
 static PyGetSetDef pypo_message_getsets[] = {
+/* msgctxt support was added in 0.15. */
+#if LIBGETTEXTPO_VERSION >= MIN_MSGCTXT_GETTEXTPO_VERSION
+    { "msgctxt", (getter)pypo_message_get_msgctxt,             (setter)0,
+      doc_pypo_message_msgctxt },
+#endif
     { "msgid", (getter)pypo_message_get_msgid,                 (setter)0,
       doc_pypo_message_msgid },
     { "msgid_plural", (getter)pypo_message_get_msgid_plural,   (setter)0,

=== modified file 'test_gettextpo.py'
--- test_gettextpo.py	2009-06-02 15:31:25 +0000
+++ test_gettextpo.py	2012-02-11 12:01:17 +0000
@@ -4,11 +4,14 @@
 import unittest
 import gettextpo
 
+
 class PoFileTestCase(unittest.TestCase):
+
     def testCreateEmpty(self):
         # Test that we can create an empty pofile object
         pofile = gettextpo.PoFile()
         self.assertEquals(list(iter(pofile)), [])
+
     def testAddMessage(self):
         # Test that we can add messages to a new pofile object
         pofile = gettextpo.PoFile()
@@ -18,6 +21,7 @@
         poiter.insert(msg)
 
         self.assertEquals(list(iter(pofile)), [msg])
+
     def testAddMessageTwice(self):
         # A message object can only be added to one pofile object
         pofile1 = gettextpo.PoFile()
@@ -31,7 +35,9 @@
         poiter = iter(pofile2)
         self.assertRaises(ValueError, poiter.insert, msg)
 
+
 class PoMessageTestCase(unittest.TestCase):
+
     def testCreateMessage(self):
         # Test that messages can be created.
         msg = gettextpo.PoMessage()
@@ -43,11 +49,16 @@
         msg.set_msgid_plural('Hellos')
         self.assertEquals(msg.msgid_plural, 'Hellos')
 
+    def testSetMsgCtxt(self):
+        msg = gettextpo.PoMessage()
+        msg.set_msgctxt('Hello')
+        self.assertEquals(msg.msgctxt, 'Hello')
+
     def testSetMsgStr(self):
         msg = gettextpo.PoMessage()
         msg.set_msgstr('Hello World')
         self.assertEquals(msg.msgstr, 'Hello World')
-    
+
     def testSetMsgStrPlural(self):
         # Test handling of plural msgstrs.  The PoMessage object can
         # not hold plural msgstrs if the msgid does not have a plural.
@@ -63,7 +74,9 @@
         msg.set_msgstr_plural(2, 'Two')
         self.assertEquals(msg.msgstr_plural, ['Zero', 'One', 'Two'])
 
+
 class CheckFormatTestCase(unittest.TestCase):
+
     def testGoodFormat(self):
         # Check that no exception is raised on a good translation.