]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Remove duplicate locations of catalog messages.
authorChristopher Lenz <cmlenz@gmail.com>
Tue, 24 Jul 2007 21:16:57 +0000 (21:16 +0000)
committerChristopher Lenz <cmlenz@gmail.com>
Tue, 24 Jul 2007 21:16:57 +0000 (21:16 +0000)
babel/messages/catalog.py
babel/messages/pofile.py
babel/messages/tests/catalog.py

index fc39a019a61dd25e5dc32511d82b59189aac5102..dfe980b59a359b7fce8aa7466f048da5b522bdab 100644 (file)
@@ -33,7 +33,8 @@ from babel.util import odict, distinct, LOCALTZ, UTC, FixedOffsetTimezone
 __all__ = ['Message', 'Catalog', 'TranslationError']
 __docformat__ = 'restructuredtext en'
 
-PYTHON_FORMAT = re.compile(r'\%(\([\w]+\))?([-#0\ +])?(\*|[\d]+)?(\.(\*|[\d]+))?([hlL])?[diouxXeEfFgGcrs]')
+PYTHON_FORMAT = re.compile(r'\%(\([\w]+\))?([-#0\ +])?(\*|[\d]+)?'
+                           r'(\.(\*|[\d]+))?([hlL])?[diouxXeEfFgGcrs]')
 
 
 class Message(object):
@@ -60,7 +61,7 @@ class Message(object):
         if not string and self.pluralizable:
             string = (u'', u'')
         self.string = string #: The message translation
-        self.locations = list(locations)
+        self.locations = list(distinct(locations))
         self.flags = set(flags)
         if id and self.python_format:
             self.flags.add('python-format')
@@ -470,7 +471,8 @@ class Catalog(object):
                 # The new message adds pluralization
                 current.id = message.id
                 current.string = message.string
-            current.locations.extend(message.locations)
+            current.locations = list(distinct(current.locations +
+                                              message.locations))
             current.auto_comments = list(distinct(current.auto_comments +
                                                   message.auto_comments))
             current.user_comments = list(distinct(current.user_comments +
index 554328a8f4fe18f11d185763fae9e131325e82ad..4ed555448f5997b3edc0d3a20acbb0b74c353114 100644 (file)
@@ -356,7 +356,7 @@ def write_po(fileobj, catalog, width=76, no_location=False, omit_header=False,
                             them in the output; by default they are included as
                             comments
     :param include_previous: include the old msgid as a comment when
-                              updating the catalog
+                             updating the catalog
     """
     def _normalize(key, prefix=''):
         return normalize(key, prefix=prefix, width=width) \
index c2b6f45f235750a10c2fc72e1c4d73246c6feb91..a084d73db9ee1be8d8626a6485ab55e6e0fae6f0 100644 (file)
@@ -67,6 +67,12 @@ class CatalogTestCase(unittest.TestCase):
         self.assertEqual(['A comment', 'Another comment'],
                          cat['foo'].user_comments)
 
+    def test_duplicate_user_comment(self):
+        cat = catalog.Catalog()
+        cat.add('foo', locations=[('foo.py', 1)])
+        cat.add('foo', locations=[('foo.py', 1)])
+        self.assertEqual([('foo.py', 1)], cat['foo'].locations)
+
     def test_update_message_updates_comments(self):
         cat = catalog.Catalog()
         cat[u'foo'] = catalog.Message('foo', locations=[('main.py', 5)])