From: Cédric Krier Date: Wed, 7 Mar 2018 23:16:47 +0000 (+0100) Subject: Skip empty message when writing mo file X-Git-Tag: v2.7.0~24^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=41e8169c63ac6b6ec673c74a9e1f7ebaa8c6be87;p=thirdparty%2Fbabel.git Skip empty message when writing mo file Instead of using the msgid, this allows to have gettext fallback to retrieve the translation. Otherwise gettext will anyway return msgid. --- diff --git a/babel/messages/mofile.py b/babel/messages/mofile.py index 79042e00..8aa704f9 100644 --- a/babel/messages/mofile.py +++ b/babel/messages/mofile.py @@ -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])