Commit aa570e8e authored by Weblate's avatar Weblate

Merge remote-tracking branch 'origin/master'

parents 561db89f 91179572
......@@ -22,6 +22,10 @@ import re
from django.utils.translation import ugettext_lazy as _
from weblate.trans.autofixes.base import AutoFix
NEWLINES = re.compile(r'\r\n|\r|\n')
START = re.compile(r'^(\s+)', re.UNICODE)
END = re.compile(r'(\s+)$', re.UNICODE)
class SameBookendingWhitespace(AutoFix):
'''
......@@ -32,17 +36,17 @@ class SameBookendingWhitespace(AutoFix):
def fix_single_target(self, target, source, unit):
# normalize newlines of source
source = re.compile(r'\r\n|\r|\n').sub('\n', source)
source = NEWLINES.sub('\n', source)
# capture preceding and tailing whitespace
start = re.compile(r'^(\s+)').search(source)
end = re.compile(r'(\s+)$').search(source)
start = START.search(source)
end = END.search(source)
head = start.group() if start else ''
tail = end.group() if end else ''
# add the whitespace around the target translation (ignore blanks)
stripped = target.strip()
if stripped:
newtarget = '%s%s%s' % (head, stripped, tail)
newtarget = u''.join((head, stripped, tail))
return newtarget, newtarget != target
return target, False
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