]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Make catalog header updating an option 320/head
authorAarni Koskela <akx@iki.fi>
Fri, 8 Jan 2016 08:17:05 +0000 (10:17 +0200)
committerAarni Koskela <akx@iki.fi>
Fri, 8 Jan 2016 12:09:00 +0000 (14:09 +0200)
The change in e0e7ef168856bb had an unexpected and likely undesired effect
when updating catalogs with, e.g. translator names in the header comment.

It's better to make the updating an option and revert back to the pre-2.2
behavior by default.

Fixes https://github.com/python-babel/babel/issues/318

babel/messages/catalog.py
babel/messages/frontend.py
tests/messages/test_catalog.py

index f72a34fcaec6d61776028925ec6417f22ff909c9..ca4a5680c6cd018b8dd589a069553dd56b98b1e4 100644 (file)
@@ -673,7 +673,7 @@ class Catalog(object):
         if key in self._messages:
             del self._messages[key]
 
-    def update(self, template, no_fuzzy_matching=False):
+    def update(self, template, no_fuzzy_matching=False, update_header_comment=False):
         """Update the catalog based on the given template catalog.
 
         >>> from babel.messages import Catalog
@@ -798,9 +798,10 @@ class Catalog(object):
             if no_fuzzy_matching or msgid not in fuzzy_matches:
                 self.obsolete[msgid] = remaining[msgid]
 
-        # Allow the updated catalog's header to be rewritten based on the
-        # template's header
-        self.header_comment = template.header_comment
+        if update_header_comment:
+            # Allow the updated catalog's header to be rewritten based on the
+            # template's header
+            self.header_comment = template.header_comment
 
         # Make updated catalog's POT-Creation-Date equal to the template
         # used to update the catalog
index 5f6b141650b0ddb22ea3c9b886f24355e85a0d2d..d9919f6310cbdc421b96eb0fea980a6af888d3f5 100755 (executable)
@@ -545,10 +545,12 @@ class update_catalog(Command):
          'whether to omit obsolete messages from the output'),
         ('no-fuzzy-matching', 'N',
          'do not use fuzzy matching'),
+        ('update-header-comment', None,
+         'update target header comment'),
         ('previous', None,
          'keep previous msgids of translated messages')
     ]
-    boolean_options = ['ignore_obsolete', 'no_fuzzy_matching', 'previous']
+    boolean_options = ['ignore_obsolete', 'no_fuzzy_matching', 'previous', 'update_header_comment']
 
     def initialize_options(self):
         self.domain = 'messages'
@@ -560,6 +562,7 @@ class update_catalog(Command):
         self.no_wrap = False
         self.ignore_obsolete = False
         self.no_fuzzy_matching = False
+        self.update_header_comment = False
         self.previous = False
 
     def finalize_options(self):
@@ -619,7 +622,10 @@ class update_catalog(Command):
             finally:
                 infile.close()
 
-            catalog.update(template, self.no_fuzzy_matching)
+            catalog.update(
+                template, self.no_fuzzy_matching,
+                update_header_comment=self.update_header_comment
+            )
 
             tmpname = os.path.join(os.path.dirname(filename),
                                    tempfile.gettempprefix() +
index 7d18d80a9ec267e7730432c150cb82317e27a2dc..3eeaf64ec02d215e177a914038ed1f624f832acf 100644 (file)
@@ -440,7 +440,6 @@ def test_catalog_update():
 
     cat.update(template)
     assert len(cat) == 3
-    assert cat.header_comment == template.header_comment  # Header comment also gets updated
 
     msg1 = cat['green']
     msg1.string
@@ -457,6 +456,9 @@ def test_catalog_update():
     assert not 'head' in cat
     assert list(cat.obsolete.values())[0].id == 'head'
 
+    cat.update(template, update_header_comment=True)
+    assert cat.header_comment == template.header_comment  # Header comment also gets updated
+
 
 def test_datetime_parsing():
     val1 = catalog._parse_datetime_header('2006-06-28 23:24+0200')