Index: translate/storage/cpo.py
===================================================================
--- translate/storage/cpo.py (revision 8228)
+++ translate/storage/cpo.py (working copy)
@@ -134,6 +134,8 @@
gpo.po_message_msgid_plural.restype = STRING
gpo.po_message_msgstr.restype = STRING
gpo.po_message_msgstr_plural.restype = STRING
+gpo.po_message_set_format.argtypes = [c_int, STRING, c_int]
+gpo.po_format_list.restype = POINTER(STRING)
# Message (set methods)
gpo.po_message_set_comments.argtypes = [c_int, STRING]
@@ -422,6 +424,40 @@
def hastypecomment(self, typecomment):
return gpo.po_message_is_format(self._gpo_message, typecomment)
+ def _get_available_typecomments(self):
+ """Returns a list of all the type comments available"""
+ formats = gpo.po_format_list()
+ typecomments = []
+ for format in formats:
+ if format is None:
+ break
+ else:
+ typecomments.append(format)
+ return typecomments
+
+ def gettypecomments(self):
+ """Returns a list of the unit type comments
+
+ @returns: a list of the typecomments or an empty list if the unit not
+ have type comments.
+ """
+ comments = []
+ for typecomment in self._get_available_typecomments():
+ if self.hastypecomment(typecomment):
+ comments.append(typecomment)
+ return comments
+
+ def addtypecomment(self, typecomment):
+ """Adds a type comment to the unit
+
+ @param typecomment: the type comment to be added, for example
+ "c-format"
+ """
+ if typecomment not in self._get_available_typecomments():
+ raise ValueError("Invalid typecomment: %s" % typecomment)
+
+ gpo.po_message_set_format(self._gpo_message, typecomment, 1)
+
def hasmarkedcomment(self, commentmarker):
commentmarker = "(%s)" % commentmarker
for comment in self.getnotes("translator").split("\n"):