]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Fix duplicate locations when writing without lineno
authorSigurd Ljødal <544451+ljodal@users.noreply.github.com>
Mon, 31 Jan 2022 16:47:21 +0000 (17:47 +0100)
committerAarni Koskela <akx@iki.fi>
Fri, 8 Apr 2022 10:27:18 +0000 (13:27 +0300)
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).

babel/messages/pofile.py
tests/messages/test_pofile.py

index 3485a2ab66def890f484d3b1b6c5fc740cfc2f3d..bd29e731aa9d14dbf3ee38c5e3c73c23e7b34601 100644 (file)
@@ -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)))
index 7239a8838e87d83f185e4ec23b2860224fab1b83..ff0295ad614021cf1fb381efef8b8348062e956b 100644 (file)
@@ -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)