]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Add an option to the frontend commands for catalog updating that removes completely...
authorChristopher Lenz <cmlenz@gmail.com>
Sun, 1 Jul 2007 17:59:44 +0000 (17:59 +0000)
committerChristopher Lenz <cmlenz@gmail.com>
Sun, 1 Jul 2007 17:59:44 +0000 (17:59 +0000)
babel/messages/frontend.py
babel/messages/pofile.py
babel/messages/tests/pofile.py
doc/cmdline.txt
doc/setup.txt

index 732ec014f0de8f3cb7f20e8cb82670ff7af1bf01..2ca56936e037337cbec46b5a36d79f6397ccdf18 100755 (executable)
@@ -452,7 +452,10 @@ class update_catalog(Command):
          "'<output_dir>/<locale>/LC_MESSAGES/<domain>.po')"),
         ('locale=', 'l',
          'locale of the catalog to compile'),
+        ('ignore-obsolete=', None,
+         'whether to omit obsolete messages from the output')
     ]
+    boolean_options = ['ignore_obsolete']
 
     def initialize_options(self):
         self.domain = 'messages'
@@ -460,6 +463,7 @@ class update_catalog(Command):
         self.output_dir = None
         self.output_file = None
         self.locale = None
+        self.ignore_obsolete = False
 
     def finalize_options(self):
         if not self.input_file:
@@ -504,7 +508,7 @@ class update_catalog(Command):
 
             outfile = open(po_file, 'w')
             try:
-                write_po(outfile, catalog)
+                write_po(outfile, catalog, ignore_obsolete=self.ignore_obsolete)
             finally:
                 outfile.close()
 
@@ -853,8 +857,12 @@ class CommandLineInterface(object):
                                "<domain>.po')")
         parser.add_option('--locale', '-l', dest='locale', metavar='LOCALE',
                           help='locale of the translations catalog')
+        parser.add_option('--ignore-obsolete', dest='ignore_obsolete',
+                          action='store_true',
+                          help='do not include obsolete messages in the output '
+                               '(default %default)'),
 
-        parser.set_defaults(domain='messages')
+        parser.set_defaults(domain='messages', ignore_obsolete=False)
         options, args = parser.parse_args(argv)
 
         if not options.input_file:
@@ -898,7 +906,8 @@ class CommandLineInterface(object):
 
             outfile = open(po_file, 'w')
             try:
-                write_po(outfile, catalog)
+                write_po(outfile, catalog,
+                         ignore_obsolete=options.ignore_obsolete)
             finally:
                 outfile.close()
 
index 8b06122ad32a9ccd77f54b1ff6bc41e4f3bf2cac..1f6e2dd4e25ab50ee68be9be9f13db920e376695 100644 (file)
@@ -298,7 +298,7 @@ def normalize(string, prefix='', width=76):
     return u'""\n' + u'\n'.join([(prefix + escape(l)) for l in lines])
 
 def write_po(fileobj, catalog, width=76, no_location=False, omit_header=False,
-             sort_output=False, sort_by_file=False):
+             sort_output=False, sort_by_file=False, ignore_obsolete=False):
     r"""Write a ``gettext`` PO (portable object) template file for a given
     message catalog to the provided file-like object.
     
@@ -330,6 +330,10 @@ def write_po(fileobj, catalog, width=76, no_location=False, omit_header=False,
     :param no_location: do not emit a location comment for every message
     :param omit_header: do not include the ``msgid ""`` entry at the top of the
                         output
+    :sort_output: whether to sort the messages in the output by msgid
+    :sort_by_file: whether to sort the messages in the output by their locations
+    :ignore_obsolete: whether to ignore obsolete messages and not include them
+                      in the output; by default they are included as comments
     """
     def _normalize(key, prefix=''):
         return normalize(key, prefix=prefix, width=width) \
@@ -397,8 +401,9 @@ def write_po(fileobj, catalog, width=76, no_location=False, omit_header=False,
         _write_message(message)
         _write('\n')
 
-    for message in catalog.obsolete.values():
-        for comment in message.user_comments:
-            _write_comment(comment)
-        _write_message(message, prefix='#~ ')
-        _write('\n')
+    if not ignore_obsolete:
+        for message in catalog.obsolete.values():
+            for comment in message.user_comments:
+                _write_comment(comment)
+            _write_message(message, prefix='#~ ')
+            _write('\n')
index 94a7d22465cba7e922e2bd239b22076b0bd51fed..3e6c5b3a17933174a8da3b152912c2c114950ef7 100644 (file)
@@ -194,6 +194,18 @@ msgstr "Voh"
 #~ "multiple lines, and should still be handled\n"
 #~ "correctly.\n"''', buf.getvalue().strip())
 
+    def test_po_with_obsolete_message_ignored(self):
+        catalog = Catalog()
+        catalog.add(u'foo', u'Voh', locations=[('main.py', 1)])
+        catalog.obsolete['bar'] = Message(u'bar', u'Bahr',
+                                          locations=[('utils.py', 3)],
+                                          user_comments=['User comment'])
+        buf = StringIO()
+        pofile.write_po(buf, catalog, omit_header=True, ignore_obsolete=True)
+        self.assertEqual('''#: main.py:1
+msgid "foo"
+msgstr "Voh"''', buf.getvalue().strip())
+
 
 def suite():
     suite = unittest.TestSuite()
index a2ea456b7e7d99413c67e3aa3743488c0c3fb4b2..dcf247aeb57a0a805497231edd245da38d9a5694 100644 (file)
@@ -170,6 +170,8 @@ a PO template file::
                             '<output_dir>/<locale>/LC_MESSAGES/<domain>.po')
       -l LOCALE, --locale=LOCALE
                             locale of the translations catalog
+      --ignore-obsolete     do not include obsolete messages in the output
+                            (default False)
 
 If ``output_dir`` is specified, but ``output-file`` is not, the default
 filename of the output file will be::
index 29b254d4993e968b70cdfad87e8fdd3404821eec..ba5ddc26e893a64a8830d6d1d92ff92d4d4176df 100644 (file)
@@ -323,6 +323,9 @@ The ``update_catalog`` command accepts the following options:
   +-----------------------------+----------------------------------------------+
   | ``--locale``                | locale for the new localized string          |
   +-----------------------------+----------------------------------------------+
+  | ``--ignore-obsolete``       | do not include obsolete messages in the      |
+  |                             | output                                       |
+  +-----------------------------+----------------------------------------------+
 
 If ``output-dir`` is specified, but ``output-file`` is not, the default filename
 of the output file will be::