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

Include check severity

This adds a visual clue how important the check might be.

Fixes #475
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 1937692b
......@@ -24,7 +24,7 @@
<div class="col-md-4">
<div class="list-group">
{% for c in checks %}
<a class="list-group-item" href="{{ review_url }}?type={{ c.0 }}"><span class="badge">{{ c.2 }}</span>{{ c.1 }}</a>
<a class="list-group-item list-group-item-{{ c.3 }}" href="{{ review_url }}?type={{ c.0 }}"><span class="badge">{{ c.2 }}</span>{{ c.1 }}</a>
{% endfor %}
</div>
</div>
......
......@@ -93,7 +93,7 @@
<div class="panel-body">
<div class="list-group">
{% for c in object.get_translation_checks %}
<a class="list-group-item" href="{{ object.get_translate_url }}?type={{ c.0 }}"><span class="badge">{{ c.2 }}</span>{{ c.1 }}</a>
<a class="list-group-item list-group-item-{{ c.3 }}" href="{{ object.get_translate_url }}?type={{ c.0 }}"><span class="badge">{{ c.2 }}</span>{{ c.1 }}</a>
{% endfor %}
</div>
</div>
......
......@@ -32,6 +32,7 @@ class Check(object):
target = False
source = False
ignore_untranslated = True
severity = 'info'
def __init__(self):
id_dash = self.check_id.replace('_', '-')
......
......@@ -29,6 +29,7 @@ class BeginNewlineCheck(TargetCheck):
check_id = 'begin_newline'
name = _('Starting newline')
description = _('Source and translation do not both start with a newline')
severity = 'warning'
def check_single(self, source, target, unit, cache_slot):
return self.check_chars(source, target, 0, ['\n'])
......@@ -41,6 +42,7 @@ class EndNewlineCheck(TargetCheck):
check_id = 'end_newline'
name = _('Trailing newline')
description = _('Source and translation do not both end with a newline')
severity = 'warning'
def check_single(self, source, target, unit, cache_slot):
return self.check_chars(source, target, -1, ['\n'])
......@@ -55,6 +57,7 @@ class BeginSpaceCheck(TargetCheck):
description = _(
'Source and translation do not both start with same number of spaces'
)
severity = 'warning'
def check_single(self, source, target, unit, cache_slot):
# One letter things are usually decimal/thousand separators
......@@ -83,6 +86,7 @@ class EndSpaceCheck(TargetCheck):
check_id = 'end_space'
name = _('Trailing space')
description = _('Source and translation do not both end with a space')
severity = 'warning'
def check_single(self, source, target, unit, cache_slot):
# One letter things are usually decimal/thousand separators
......@@ -116,6 +120,7 @@ class EndStopCheck(TargetCheck):
check_id = 'end_stop'
name = _('Trailing stop')
description = _('Source and translation do not both end with a full stop')
severity = 'warning'
def check_single(self, source, target, unit, cache_slot):
if len(source) <= 4:
......@@ -158,6 +163,7 @@ class EndColonCheck(TargetCheck):
'or colon is not correctly spaced'
)
colon_fr = (' :', '&nbsp;:', u' :')
severity = 'warning'
def check_single(self, source, target, unit, cache_slot):
if not source or not target:
......@@ -207,6 +213,7 @@ class EndQuestionCheck(TargetCheck):
)
question_fr = (' ?', ' ? ', '&nbsp;? ', '&nbsp;?', u' ?', u' ? ')
question_el = ('?', ';', u';')
severity = 'warning'
def check_single(self, source, target, unit, cache_slot):
if not source or not target:
......@@ -249,6 +256,7 @@ class EndExclamationCheck(TargetCheck):
'or it is not correctly spaced'
)
exclamation_fr = (' !', '&nbsp;!', u' !', ' ! ', '&nbsp;! ', u' ! ')
severity = 'warning'
def check_single(self, source, target, unit, cache_slot):
if not source or not target:
......@@ -281,6 +289,7 @@ class EndEllipsisCheck(TargetCheck):
check_id = 'end_ellipsis'
name = _('Trailing ellipsis')
description = _('Source and translation do not both end with an ellipsis')
severity = 'warning'
def check_single(self, source, target, unit, cache_slot):
if not target:
......@@ -299,6 +308,7 @@ class NewlineCountingCheck(CountingCheck):
check_id = 'escaped_newline'
name = _('Mismatched \\n')
description = _('Number of \\n in translation does not match source')
severity = 'warning'
class ZeroWidthSpaceCheck(TargetCheck):
......@@ -308,6 +318,7 @@ class ZeroWidthSpaceCheck(TargetCheck):
check_id = 'zero-width-space'
name = _('Zero-width space')
description = _('Translation contains extra zero-width space character')
severity = 'warning'
def check_single(self, source, target, unit, cache_slot):
if self.is_language(unit, ('km', )):
......
......@@ -29,6 +29,7 @@ class PluralsCheck(TargetCheck):
check_id = 'plurals'
name = _('Missing plurals')
description = _('Some plural forms are not translated')
severity = 'danger'
def check_target_unit(self, sources, targets, unit):
# Is this plural?
......@@ -57,6 +58,7 @@ class ConsistencyCheck(TargetCheck):
'This message has more than one translation in this project'
)
ignore_untranslated = False
severity = 'warning'
def check_target_unit(self, sources, targets, unit):
from weblate.trans.models import Unit
......
......@@ -105,6 +105,7 @@ class BaseFormatCheck(TargetCheck):
'''
flag = None
regexp = None
severity = 'danger'
def check_target_unit(self, sources, targets, unit):
'''
......
......@@ -46,6 +46,7 @@ class BBCodeCheck(TargetCheck):
check_id = 'bbcode'
name = _('Mismatched BBcode')
description = _('BBcode in translation does not match source')
severity = 'warning'
def check_single(self, source, target, unit, cache_slot):
# Try geting source parsing from cache
......@@ -75,6 +76,7 @@ class XMLTagsCheck(TargetCheck):
check_id = 'xml-tags'
name = _('XML tags mismatch')
description = _('XML tags in translation do not match source')
severity = 'warning'
def parse_xml(self, text):
'''
......
......@@ -906,6 +906,7 @@ class SameCheck(TargetCheck):
check_id = 'same'
name = _('Not translated')
description = _('Source and translated strings are same')
severity = 'warning'
def should_ignore(self, source, unit, cache_slot):
'''
......
......@@ -35,6 +35,7 @@ class OptionalPluralCheck(SourceCheck):
description = _(
'The string is optionally used as plural, but not using plural forms'
)
severity = 'info'
def check_source(self, source, unit):
if len(source) > 1:
......@@ -52,6 +53,7 @@ class EllipsisCheck(SourceCheck):
u'The string uses three dots (...) '
u'instead of an ellipsis character (…)'
)
severity = 'info'
def check_source(self, source, unit):
return '...' in source[0]
......@@ -66,6 +68,7 @@ class MultipleFailingCheck(SourceCheck):
description = _(
'The translations in several languages have failing checks'
)
severity = 'info'
def check_source(self, source, unit):
from weblate.trans.models.unitdata import Check
......
......@@ -1012,7 +1012,14 @@ class Translation(models.Model, URLMixin, PercentMixin):
'''
Returns list of failing source checks on current subproject.
'''
result = [('all', _('All strings'), self.total)]
result = [
(
'all',
_('All strings'),
self.total,
'success',
)
]
# All checks
sourcechecks = self.unit_set.count_type('sourcechecks', self)
......@@ -1020,7 +1027,8 @@ class Translation(models.Model, URLMixin, PercentMixin):
result.append((
'sourcechecks',
_('Strings with any failing checks'),
sourcechecks
sourcechecks,
'danger',
))
# Process specific checks
......@@ -1032,7 +1040,8 @@ class Translation(models.Model, URLMixin, PercentMixin):
result.append((
check,
CHECKS[check].description,
cnt
cnt,
CHECKS[check].severity,
))
# Grab comments
......@@ -1042,6 +1051,7 @@ class Translation(models.Model, URLMixin, PercentMixin):
'sourcecomments',
_('Strings with comments'),
sourcecomments,
'info',
))
return result
......@@ -1050,7 +1060,14 @@ class Translation(models.Model, URLMixin, PercentMixin):
'''
Returns list of failing checks on current translation.
'''
result = [('all', _('All strings'), self.total)]
result = [
(
'all',
_('All strings'),
self.total,
'success',
)
]
# Untranslated strings
nottranslated = self.unit_set.count_type('untranslated', self)
......@@ -1059,6 +1076,7 @@ class Translation(models.Model, URLMixin, PercentMixin):
'untranslated',
_('Untranslated strings'),
nottranslated,
'danger',
))
# Fuzzy strings
......@@ -1068,6 +1086,7 @@ class Translation(models.Model, URLMixin, PercentMixin):
'fuzzy',
_('Fuzzy strings'),
fuzzy,
'danger',
))
# Translations with suggestions
......@@ -1076,6 +1095,7 @@ class Translation(models.Model, URLMixin, PercentMixin):
'suggestions',
_('Strings with suggestions'),
self.have_suggestion,
'info',
))
# All checks
......@@ -1084,6 +1104,7 @@ class Translation(models.Model, URLMixin, PercentMixin):
'allchecks',
_('Strings with any failing checks'),
self.failing_checks,
'danger',
))
# Process specific checks
......@@ -1095,7 +1116,8 @@ class Translation(models.Model, URLMixin, PercentMixin):
result.append((
check,
CHECKS[check].description,
cnt
cnt,
CHECKS[check].severity,
))
# Grab comments
......@@ -1105,6 +1127,7 @@ class Translation(models.Model, URLMixin, PercentMixin):
'targetcomments',
_('Strings with comments'),
targetcomments,
'info',
))
return result
......
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