Commit 6a32f17b authored by Michal Čihař's avatar Michal Čihař

Merge pull request #322 from bertm/patch-2

checks: fix empty source and target strings causing exceptions.
parents 2f4b3c04 34b9164b
...@@ -65,10 +65,11 @@ class Check(object): ...@@ -65,10 +65,11 @@ class Check(object):
''' '''
Generic checker for chars presence. Generic checker for chars presence.
''' '''
if len(target) == 0 or len(source) == 0: try:
src = source[pos]
tgt = target[pos]
except:
return False return False
src = source[pos]
tgt = target[pos]
return ( return (
(src in chars and tgt not in chars) (src in chars and tgt not in chars)
or (src not in chars and tgt in chars) or (src not in chars and tgt in chars)
......
...@@ -81,9 +81,9 @@ class EndSpaceCheck(TargetCheck): ...@@ -81,9 +81,9 @@ class EndSpaceCheck(TargetCheck):
# One letter things are usually decimal/thousand separators # One letter things are usually decimal/thousand separators
if len(source) <= 1 and len(target) <= 1: if len(source) <= 1 and len(target) <= 1:
return False return False
if self.is_language(unit, ['fr', 'br']): if not source or not target:
if len(target) == 0:
return False return False
if self.is_language(unit, ['fr', 'br']):
if source[-1] in [':', '!', '?'] and target[-1] == ' ': if source[-1] in [':', '!', '?'] and target[-1] == ' ':
return False return False
...@@ -106,6 +106,8 @@ class EndStopCheck(TargetCheck): ...@@ -106,6 +106,8 @@ class EndStopCheck(TargetCheck):
def check_single(self, source, target, unit, cache_slot): def check_single(self, source, target, unit, cache_slot):
if len(source) <= 4 and len(target) <= 4: if len(source) <= 4 and len(target) <= 4:
return False return False
if not source:
return False
if self.is_language(unit, ['ja']) and source[-1] in [':', ';']: if self.is_language(unit, ['ja']) and source[-1] in [':', ';']:
# Japanese sentence might need to end with full stop # Japanese sentence might need to end with full stop
# in case it's used before list. # in case it's used before list.
...@@ -136,9 +138,9 @@ class EndColonCheck(TargetCheck): ...@@ -136,9 +138,9 @@ class EndColonCheck(TargetCheck):
colon_fr = (' :', '&nbsp;:', u' :') colon_fr = (' :', '&nbsp;:', u' :')
def check_single(self, source, target, unit, cache_slot): def check_single(self, source, target, unit, cache_slot):
if not source or not target:
return False
if self.is_language(unit, ['fr', 'br']): if self.is_language(unit, ['fr', 'br']):
if len(target) == 0 or len(source) == 0:
return False
if source[-1] == ':': if source[-1] == ':':
# Accept variant with trailing space as well # Accept variant with trailing space as well
if target[-1] == ' ': if target[-1] == ' ':
...@@ -176,7 +178,7 @@ class EndQuestionCheck(TargetCheck): ...@@ -176,7 +178,7 @@ class EndQuestionCheck(TargetCheck):
question_el = ('?', ';', ';') question_el = ('?', ';', ';')
def check_single(self, source, target, unit, cache_slot): def check_single(self, source, target, unit, cache_slot):
if len(target) == 0 or len(source) == 0: if not source or not target:
return False return False
if self.is_language(unit, ['fr', 'br']): if self.is_language(unit, ['fr', 'br']):
if source[-1] != '?': if source[-1] != '?':
...@@ -209,15 +211,13 @@ class EndExclamationCheck(TargetCheck): ...@@ -209,15 +211,13 @@ class EndExclamationCheck(TargetCheck):
exclamation_fr = (' !', '&nbsp;!', u' !', ' ! ', '&nbsp;! ', u' ! ') exclamation_fr = (' !', '&nbsp;!', u' !', ' ! ', '&nbsp;! ', u' ! ')
def check_single(self, source, target, unit, cache_slot): def check_single(self, source, target, unit, cache_slot):
if len(source) == 0: if not source or not target:
return False return False
if self.is_language(unit, ['eu']): if self.is_language(unit, ['eu']):
if source[-1] == '!': if source[-1] == '!':
if u'¡' in target and u'!' in target: if u'¡' in target and u'!' in target:
return False return False
if self.is_language(unit, ['fr', 'br']): if self.is_language(unit, ['fr', 'br']):
if len(target) == 0:
return False
if source[-1] == '!': if source[-1] == '!':
if target[-2:] not in self.exclamation_fr: if target[-2:] not in self.exclamation_fr:
return True return True
...@@ -239,6 +239,8 @@ class EndEllipsisCheck(TargetCheck): ...@@ -239,6 +239,8 @@ class EndEllipsisCheck(TargetCheck):
description = _('Source and translation do not both end with an ellipsis') description = _('Source and translation do not both end with an ellipsis')
def check_single(self, source, target, unit, cache_slot): def check_single(self, source, target, unit, cache_slot):
if not target:
return False
# Allow ... to be translated into ellipsis # Allow ... to be translated into ellipsis
if source.endswith('...') and target[-1] == u'…': if source.endswith('...') and target[-1] == u'…':
return False return 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