summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAarni Koskela <akx@iki.fi>2018-08-20 17:25:07 +0300
committerGitHub <noreply@github.com>2018-08-20 17:25:07 +0300
commitd2cf189ff0ce505b46191268c3cbdc4b130d8dd6 (patch)
treee2aec2d5f01e29fb07a3b1205133cc28d45f35ad
parent4222e1ac84d2f822c48a09c6c70fd61f782fe3ab (diff)
parent85f6587c8556592e969b23a92f7432d24d464532 (diff)
downloadbabel-d2cf189ff0ce505b46191268c3cbdc4b130d8dd6.tar.gz
Merge pull request #564 from cedk/skip-empty-msgid
Skip empty message when writing mo file
-rw-r--r--babel/messages/mofile.py9
-rw-r--r--tests/messages/test_mofile.py23
2 files changed, 26 insertions, 6 deletions
diff --git a/babel/messages/mofile.py b/babel/messages/mofile.py
index 7bddd18..663d93b 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])
diff --git a/tests/messages/test_mofile.py b/tests/messages/test_mofile.py
index 7038b1d..97af7ae 100644
--- a/tests/messages/test_mofile.py
+++ b/tests/messages/test_mofile.py
@@ -71,3 +71,26 @@ class WriteMoTestCase(unittest.TestCase):
catalog2.add(('Fuzz', 'Fuzzes'), ('', '', ''))
buf = BytesIO()
mofile.write_mo(buf, catalog2)
+
+ def test_empty_translation_with_fallback(self):
+ catalog1 = Catalog(locale='fr_FR')
+ catalog1.add(u'', '''\
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n''')
+ catalog1.add(u'Fuzz', '')
+ buf1 = BytesIO()
+ mofile.write_mo(buf1, catalog1)
+ buf1.seek(0)
+ catalog2 = Catalog(locale='fr')
+ catalog2.add(u'', '''\
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n''')
+ catalog2.add(u'Fuzz', 'Flou')
+ buf2 = BytesIO()
+ mofile.write_mo(buf2, catalog2)
+ buf2.seek(0)
+
+ translations = Translations(fp=buf1)
+ translations.add_fallback(Translations(fp=buf2))
+
+ self.assertEqual(u'Flou', translations.ugettext('Fuzz'))