changeset 20515:6afbfb9b1af1

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.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Sat, 15 Feb 2014 18:40:39 +0900
parents 410c80539c5c
children 3af218cf2007
files i18n/check-translation.py
diffstat 1 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/i18n/check-translation.py	Sat Feb 15 18:40:39 2014 +0900
+++ b/i18n/check-translation.py	Sat Feb 15 18:40:39 2014 +0900
@@ -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):