diff options
author | Sigurd Ljødal <544451+ljodal@users.noreply.github.com> | 2022-01-31 17:47:21 +0100 |
---|---|---|
committer | Aarni Koskela <akx@iki.fi> | 2022-04-08 13:27:18 +0300 |
commit | 7e90d6b8fe1327ed863b626db51be9061b6b5781 (patch) | |
tree | 7e72731006b2dffc9105d850ccebd327d3bacdc9 | |
parent | bc7a51bc8809f9d62dca43a634d3b803dc054cf0 (diff) | |
download | babel-7e90d6b8fe1327ed863b626db51be9061b6b5781.tar.gz |
Fix duplicate locations when writing without lineno
If the same translation appears multiple times in the same file,
duplicate locations would be written to the .po file when using
write_po(..., include_lineno=False).
-rw-r--r-- | babel/messages/pofile.py | 6 | ||||
-rw-r--r-- | tests/messages/test_pofile.py | 1 |
2 files changed, 5 insertions, 2 deletions
diff --git a/babel/messages/pofile.py b/babel/messages/pofile.py index 3485a2a..bd29e73 100644 --- a/babel/messages/pofile.py +++ b/babel/messages/pofile.py @@ -597,9 +597,11 @@ def write_po(fileobj, catalog, width=76, no_location=False, omit_header=False, 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))) diff --git a/tests/messages/test_pofile.py b/tests/messages/test_pofile.py index 7239a88..ff0295a 100644 --- a/tests/messages/test_pofile.py +++ b/tests/messages/test_pofile.py @@ -827,6 +827,7 @@ msgstr ""''', buf.getvalue().strip()) 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) |