]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
When msgid are equal, sort according to msgctxt 482/head
authorXavier Fernandez <xavier.fernandez@polyconseil.fr>
Tue, 21 Mar 2017 15:36:56 +0000 (16:36 +0100)
committerXavier Fernandez <xavier.fernandez@polyconseil.fr>
Tue, 21 Mar 2017 15:46:28 +0000 (16:46 +0100)
Fix #481

babel/messages/catalog.py
tests/messages/test_pofile.py

index 193b72bcd3e87ac64eb35d545d731f09a949da6f..3145fa37a2c97a831174e5c6cda43daf0831bab7 100644 (file)
@@ -120,8 +120,8 @@ class Message(object):
         """Compare Messages, taking into account plural ids"""
         def values_to_compare(obj):
             if isinstance(obj, Message) and obj.pluralizable:
-                return obj.id[0]
-            return obj.id
+                return (obj.id[0], obj.context or '')
+            return (obj.id, obj.context or '')
         return cmp(values_to_compare(self), values_to_compare(other))
 
     def __gt__(self, other):
index cef69138725717746abcc1be91efd2d64f7b7f60..ebf9702d81fc14085d9e3c3de5b91ebe568c8662 100644 (file)
@@ -680,6 +680,41 @@ msgstr[0] "Voh"
 msgstr[1] "Voeh"''' in value
         assert value.find(b'msgid ""') < value.find(b'msgid "bar"') < value.find(b'msgid "foo"')
 
+    def test_sorted_po_context(self):
+        catalog = Catalog()
+        catalog.add((u'foo', u'foos'), (u'Voh', u'Voeh'),
+                    locations=[('main.py', 1)],
+                    context='there')
+        catalog.add((u'foo', u'foos'), (u'Voh', u'Voeh'),
+                    locations=[('main.py', 1)])
+        catalog.add((u'foo', u'foos'), (u'Voh', u'Voeh'),
+                    locations=[('main.py', 1)],
+                    context='here')
+        buf = BytesIO()
+        pofile.write_po(buf, catalog, sort_output=True)
+        value = buf.getvalue().strip()
+        # We expect the foo without ctx, followed by "here" foo and "there" foo
+        assert b'''\
+#: main.py:1
+msgid "foo"
+msgid_plural "foos"
+msgstr[0] "Voh"
+msgstr[1] "Voeh"
+
+#: main.py:1
+msgctxt "here"
+msgid "foo"
+msgid_plural "foos"
+msgstr[0] "Voh"
+msgstr[1] "Voeh"
+
+#: main.py:1
+msgctxt "there"
+msgid "foo"
+msgid_plural "foos"
+msgstr[0] "Voh"
+msgstr[1] "Voeh"''' in value
+
     def test_file_sorted_po(self):
         catalog = Catalog()
         catalog.add(u'bar', locations=[('utils.py', 3)])