From af120fdf531f4ef004223311c0e7ff509b837dea Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Mon, 6 Jan 2014 15:52:15 -0500 Subject: [PATCH] Better handling of plurals during .po validation Now any of the plurals being missing will count as an Empty translation, and for looking at tags, the two English strings and all the translated strings are mooshed together. --- i18n/tests/test_validate.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/i18n/tests/test_validate.py b/i18n/tests/test_validate.py index 54ef1abe2c..a7c400da0f 100644 --- a/i18n/tests/test_validate.py +++ b/i18n/tests/test_validate.py @@ -93,13 +93,21 @@ def check_messages(filename): problems.append(("Non-BMP char", msg.msgid, msg.msgstr)) if msg.msgid_plural: - # Skip plurals, I don't know how the tags relate. - continue - if not msg.msgstr: - problems.append(("Empty translation", msg.msgid)) + # Plurals: two strings in, N strings out. + source = msg.msgid + " | " + msg.msgid_plural + translation = " | ".join(v for k,v in sorted(msg.msgstr_plural.items())) + empty = any(not t.strip() for t in msg.msgstr_plural.values()) else: - id_tags = tags_in_string(msg.msgid) - tx_tags = tags_in_string(msg.msgstr) + # Singular: just one string in and one string out. + source = msg.msgid + translation = msg.msgstr + empty = not msg.msgstr.strip() + + if empty: + problems.append(("Empty translation", source)) + else: + id_tags = tags_in_string(source) + tx_tags = tags_in_string(translation) if id_tags != tx_tags: id_has = u", ".join(u'"{}"'.format(t) for t in id_tags - tx_tags) tx_has = u", ".join(u'"{}"'.format(t) for t in tx_tags - id_tags) @@ -111,8 +119,8 @@ def check_messages(filename): diff = u"{} added".format(tx_has) problems.append(( "Different tags in source and translation", - msg.msgid, - msg.msgstr, + source, + translation, diff ))