Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate locations when writing without lineno #837

Merged
merged 1 commit into from Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions babel/messages/pofile.py
Expand Up @@ -597,9 +597,11 @@ def _write_message(message, prefix=''):

for filename, lineno in locations:
if lineno and include_lineno:
locs.append(u'%s:%d' % (filename.replace(os.sep, '/'), lineno))
location = u'%s:%d' % (filename.replace(os.sep, '/'), lineno)
else:
locs.append(u'%s' % filename.replace(os.sep, '/'))
location = u'%s' % filename.replace(os.sep, '/')
if location not in locs:
locs.append(location)
_write_comment(' '.join(locs), prefix=':')
if message.flags:
_write('#%s\n' % ', '.join([''] + sorted(message.flags)))
Expand Down
1 change: 1 addition & 0 deletions tests/messages/test_pofile.py
Expand Up @@ -827,6 +827,7 @@ def test_include_lineno(self):
def test_no_include_lineno(self):
catalog = Catalog()
catalog.add(u'foo', locations=[('main.py', 1)])
catalog.add(u'foo', locations=[('main.py', 2)])
catalog.add(u'foo', locations=[('utils.py', 3)])
buf = BytesIO()
pofile.write_po(buf, catalog, omit_header=True, include_lineno=False)
Expand Down