# HG changeset patch # User cmlenz # Date 1185311817 0 # Node ID 9a3f2acb55e625834949ba321bc23f7a2ed24abb # Parent fd29fabdc98638156e979ed4cf6394f6a98ac638 Remove duplicate locations of catalog messages. diff --git a/babel/messages/catalog.py b/babel/messages/catalog.py --- a/babel/messages/catalog.py +++ b/babel/messages/catalog.py @@ -33,7 +33,8 @@ __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 @@ 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 @@ # 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 + diff --git a/babel/messages/pofile.py b/babel/messages/pofile.py --- a/babel/messages/pofile.py +++ b/babel/messages/pofile.py @@ -356,7 +356,7 @@ 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) \ diff --git a/babel/messages/tests/catalog.py b/babel/messages/tests/catalog.py --- a/babel/messages/tests/catalog.py +++ b/babel/messages/tests/catalog.py @@ -67,6 +67,12 @@ 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)])