diff babel/messages/catalog.py @ 248:bedaaeadc1db

add a __cmp__ to Message that correctly sorts by id, taking into account plurals thanks zepolen
author pjenvey
date Mon, 13 Aug 2007 00:59:09 +0000
parents 9a3f2acb55e6
children cd7e378b8190
line wrap: on
line diff
--- a/babel/messages/catalog.py
+++ b/babel/messages/catalog.py
@@ -79,6 +79,19 @@
         return '<%s %r (flags: %r)>' % (type(self).__name__, self.id,
                                         list(self.flags))
 
+    def __cmp__(self, obj):
+        """Compare Messages, taking into account plural ids"""
+        if isinstance(obj, Message):
+            plural = self.pluralizable
+            obj_plural = obj.pluralizable
+            if plural and obj_plural:
+                return cmp(self.id[0], obj.id[0])
+            elif plural:
+                return cmp(self.id[0], obj.id)
+            elif obj_plural:
+                return cmp(self.id, obj.id[0])
+        return cmp(self.id, obj.id)
+
     def fuzzy(self):
         return 'fuzzy' in self.flags
     fuzzy = property(fuzzy, doc="""\
Copyright (C) 2012-2017 Edgewall Software