diff babel/messages/pofile.py @ 73:5d8e87acdcc7

Implemented message sorting, see #7.
author palgarvio
date Fri, 08 Jun 2007 17:30:12 +0000
parents 620fdd25657a
children 8e2e9d549693
line wrap: on
line diff
--- a/babel/messages/pofile.py
+++ b/babel/messages/pofile.py
@@ -222,7 +222,8 @@
     return u'""\n' + u'\n'.join([escape(l) for l in lines])
 
 def write_pot(fileobj, catalog, project='PROJECT', version='VERSION', width=76,
-             charset='utf-8', no_location=False, omit_header=False):
+             charset='utf-8', no_location=False, omit_header=False,
+             sort_output=False, sort_by_file=False):
     r"""Write a ``gettext`` PO (portable object) template file for a given
     message catalog to the provided file-like object.
     
@@ -270,8 +271,17 @@
     catalog.project = project
     catalog.version = version
     catalog.charset = charset
+    
+    if sort_output:
+        messages = list(catalog)
+        messages.sort(lambda x,y: cmp(x.id, y.id))
+    elif sort_by_file:
+        messages = list(catalog)
+        messages.sort(lambda x,y: cmp(x.locations, y.locations))
+    else:
+        messages = catalog       
 
-    for message in catalog:
+    for message in messages:
         if not message.id: # This is the header "message"
             if omit_header:
                 continue
Copyright (C) 2012-2017 Edgewall Software