diff options
author | Cédric Krier <ced@b2ck.com> | 2018-03-08 00:16:47 +0100 |
---|---|---|
committer | Cédric Krier <ced@b2ck.com> | 2018-03-08 00:16:47 +0100 |
commit | 41e8169c63ac6b6ec673c74a9e1f7ebaa8c6be87 (patch) | |
tree | 83f150ff35423438223b445fe702ec8fa61f3548 | |
parent | 1378a3d5e7f7f111ea7828ff7429f0abbb513700 (diff) | |
download | babel-41e8169c63ac6b6ec673c74a9e1f7ebaa8c6be87.tar.gz |
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.
-rw-r--r-- | babel/messages/mofile.py | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/babel/messages/mofile.py b/babel/messages/mofile.py index 79042e0..8aa704f 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]) |