Commit ce1e6fcb authored by Michal Čihař's avatar Michal Čihař

Starting whitespace check (issue #127)

parent 49b84234
......@@ -183,6 +183,15 @@ Trailing newline
Source and translated do not both end with a newline.
.. _check-begin_space:
Starting spaces
+++++++++++++++
Source and translation do not both start with same number of spaces. Space in
beginning is usually used for indentation in the interface and thus is
important.
.. _check-end_space:
Trailing space
......
......@@ -312,6 +312,7 @@ CHECK_LIST = (
'weblate.trans.checks.SameCheck',
'weblate.trans.checks.BeginNewlineCheck',
'weblate.trans.checks.EndNewlineCheck',
'weblate.trans.checks.BeginSpaceCheck',
'weblate.trans.checks.EndSpaceCheck',
'weblate.trans.checks.EndStopCheck',
'weblate.trans.checks.EndColonCheck',
......
......@@ -136,6 +136,7 @@ DEFAULT_CHECK_LIST = (
'weblate.trans.checks.SameCheck',
'weblate.trans.checks.BeginNewlineCheck',
'weblate.trans.checks.EndNewlineCheck',
'weblate.trans.checks.BeginSpaceCheck',
'weblate.trans.checks.EndSpaceCheck',
'weblate.trans.checks.EndStopCheck',
'weblate.trans.checks.EndColonCheck',
......@@ -298,6 +299,30 @@ class EndNewlineCheck(Check):
def check_single(self, source, target, flags, language, unit):
return self.check_chars(source, target, -1, ['\n'])
class BeginSpaceCheck(Check):
'''
Whitespace check, starting whitespace usually is important for UI
'''
check_id = 'begin_space'
name = _('Starting spaces')
description = _('Source and translation do not both start with same number of spaces')
def check_single(self, source, target, flags, language, unit):
# One letter things are usually decimal/thousand separators
if len(source) <= 1 and len(target) <= 1:
return False
# Count space chars in source
cnt = 0
while source[cnt] == ' ':
cnt += 1
# Compare that with target
if target[:cnt] != ' ' * cnt:
return True
return False
class EndSpaceCheck(Check):
'''
Whitespace check
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment