Patchwork [2,of,2] i18n: check equality of initial indentation between msgid and msgstr

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Jan. 19, 2014, 2:35 p.m.
Message ID <b98fc49032c76171a97f.1390142103@vm-debian.dzone.foozy.private>
Download mbox | patch
Permalink /patch/3386/
State Superseded
Headers show

Comments

Katsunori FUJIWARA - Jan. 19, 2014, 2:35 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1390141996 -32400
#      Sun Jan 19 23:33:16 2014 +0900
# Node ID b98fc49032c76171a97fa25d278f08eaa73d5895
# Parent  74b805dc8a967c8c48308e0c53a24940645dabd3
i18n: check equality of initial indentation between msgid and msgstr

Document generation by runrst in "doc" directory may succeed silently,
even though initial indentation is different between msgid and msgstr:
for example, it may be unexpected or missing indentation.

This patch adds the checker to check equality of initial indentation
between msgid and msgstr.

This checker is categorized as "warning" level, because problem
detected by this is not so serious for usual Mercurial usage.

Patch

diff --git a/i18n/check-translation.py b/i18n/check-translation.py
--- a/i18n/check-translation.py
+++ b/i18n/check-translation.py
@@ -88,6 +88,24 @@ 
     if pe.msgid.endswith('::') != pe.msgstr.endswith('::'):
         yield "tail '::'-ness differs between msgid and msgstr"
 
+@warningchecker()
+def indentation(pe):
+    """Check equality of initial indentation between msgid and msgstr
+
+    This may report unexpected warning, because this doesn't aware
+    the syntax of rst document and the context of msgstr.
+
+    >>> pe = polib.POEntry(
+    ...     msgid ='    indented text',
+    ...     msgstr='  narrowed indentation')
+    >>> for e in indentation(pe): print e
+    initial indentation width differs betweeen msgid and msgstr
+    """
+    idindent = len(pe.msgid) - len(pe.msgid.lstrip())
+    strindent = len(pe.msgstr) - len(pe.msgstr.lstrip())
+    if idindent != strindent:
+        yield "initial indentation width differs betweeen msgid and msgstr"
+
 ####################
 
 def check(pofile, fatal=True, warning=False):