diff --git a/babel/messages/catalog.py b/babel/messages/catalog.py index 228b10b71..850f68a67 100644 --- a/babel/messages/catalog.py +++ b/babel/messages/catalog.py @@ -35,7 +35,7 @@ (?:\.(?:\*|[\d]+))? [hlL]? ) - ([diouxXeEfFgGcrs%]) + ((?\?]|$)) ''', re.VERBOSE) @@ -94,7 +94,7 @@ def __init__(self, id, string=u'', locations=(), flags=(), auto_comments=(), if not string and self.pluralizable: string = (u'', u'') self.string = string - self.locations = list(distinct(locations)) + self.locations = list(set(locations)) self.flags = set(flags) if id and self.python_format: self.flags.add('python-format') diff --git a/babel/messages/pofile.py b/babel/messages/pofile.py index bd29e731a..67e071c0c 100644 --- a/babel/messages/pofile.py +++ b/babel/messages/pofile.py @@ -275,7 +275,7 @@ def _process_comment(self, line): continue self.locations.append((location[:pos], lineno)) else: - self.locations.append((location, None)) + self.locations.append((location, None)) elif line[1:].startswith(','): for flag in line[2:].lstrip().split(','): self.flags.append(flag.strip()) @@ -522,13 +522,15 @@ def _write(text): fileobj.write(text) def _write_comment(comment, prefix=''): - # xgettext always wraps comments even if --no-wrap is passed; - # provide the same behaviour - if width and width > 0: - _width = width - else: - _width = 76 - for line in wraptext(comment, _width): + # NEVER wrap comments, this observation: "xgettext always wraps comments even if --no-wrap is passed;" is FALSE. There seemed to be a bug in the xgettext code, because wrapping doesn't always occur + # Make sure comments are unique and sorted alphabetically so locations can be easily searched and identify + if not comment: + return + + is_list_type = isinstance(comment, list) + comment_list = (list(comment) if not is_list_type else comment) + comment_list.sort() + for line in comment_list: _write('#%s %s\n' % (prefix, line.strip())) def _write_message(message, prefix=''): @@ -577,10 +579,8 @@ def _write_message(message, prefix=''): comment_header = u'\n'.join(lines) _write(comment_header + u'\n') - for comment in message.user_comments: - _write_comment(comment) - for comment in message.auto_comments: - _write_comment(comment, prefix='.') + _write_comment(message.user_comments) + _write_comment(message.auto_comments, prefix='.') if not no_location: locs = [] @@ -602,7 +602,7 @@ def _write_message(message, prefix=''): location = u'%s' % filename.replace(os.sep, '/') if location not in locs: locs.append(location) - _write_comment(' '.join(locs), prefix=':') + _write_comment(locs, prefix=':') if message.flags: _write('#%s\n' % ', '.join([''] + sorted(message.flags))) @@ -622,8 +622,7 @@ def _write_message(message, prefix=''): catalog.obsolete.values(), sort_by=sort_by ): - for comment in message.user_comments: - _write_comment(comment) + _write_comment(message.user_comments) _write_message(message, prefix='#~ ') _write('\n')