]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Skip empty message when writing mo file
authorCédric Krier <ced@b2ck.com>
Wed, 7 Mar 2018 23:16:47 +0000 (00:16 +0100)
committerCédric Krier <ced@b2ck.com>
Wed, 7 Mar 2018 23:16:47 +0000 (00:16 +0100)
Instead of using the msgid, this allows to have gettext fallback to
retrieve the translation. Otherwise gettext will anyway return msgid.

babel/messages/mofile.py

index 79042e003a80fc0d1ea08474e610faa627656872..8aa704f961a18508c4b327b694a99a0073a38a20 100644 (file)
@@ -153,8 +153,8 @@ def write_mo(fileobj, catalog, use_fuzzy=False):
                       in the output
     """
     messages = list(catalog)
-    if not use_fuzzy:
-        messages[1:] = [m for m in messages[1:] if not m.fuzzy]
+    messages[1:] = [m for m in messages[1:]
+                    if m.string and (use_fuzzy or not m.fuzzy)]
     messages.sort()
 
     ids = strs = b''
@@ -178,10 +178,7 @@ def write_mo(fileobj, catalog, use_fuzzy=False):
             ])
         else:
             msgid = message.id.encode(catalog.charset)
-            if not message.string:
-                msgstr = message.id.encode(catalog.charset)
-            else:
-                msgstr = message.string.encode(catalog.charset)
+            msgstr = message.string.encode(catalog.charset)
         if message.context:
             msgid = b'\x04'.join([message.context.encode(catalog.charset),
                                   msgid])