Skip to content

Commit

Permalink
Added a Reduced Quality checker
Browse files Browse the repository at this point in the history
This checker runs the following tests:
untranslated, unchanged, blank, doublespacing, doublewords, and spellcheck.

It's meant for cases where source strings aren't supposed to be similar to target strings
(e.g. when source strings are slugs), so it intentionally omits any checks that make
assumptions about matching source and target syntax.

It's larger than the Minimal checker though, by including three more tests that shouldn't
usually trigger false positives under such circumstances.
  • Loading branch information
rimas-kudelis committed Jun 20, 2017
1 parent 869e125 commit 6ec79ea
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
22 changes: 22 additions & 0 deletions translate/filters/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2334,6 +2334,28 @@ def __init__(self, **kwargs):
StandardChecker.__init__(self, **kwargs)


reducedconfig = CheckerConfig()


class ReducedChecker(StandardChecker):

def __init__(self, **kwargs):
checkerconfig = kwargs.get("checkerconfig", None)

if checkerconfig is None:
checkerconfig = CheckerConfig()
kwargs["checkerconfig"] = checkerconfig

limitfilters = kwargs.get("limitfilters", None)

if limitfilters is None:
limitfilters = ["untranslated", "unchanged", "blank", "doublespacing", "doublewords", "spellcheck"]
kwargs["limitfilters"] = limitfilters

checkerconfig.update(minimalconfig)
StandardChecker.__init__(self, **kwargs)


termconfig = CheckerConfig()


Expand Down
33 changes: 33 additions & 0 deletions translate/filters/test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,39 @@ def test_minimalchecker():
assert 'printf' not in minimalchecker.run_filters(unit).keys()


def test_reducedchecker():
"""tests the Reduced quality checker"""
from translate.storage import base

# The reduced checker only runs the following tests:
# untranslated, unchanged, blank, doublespacing, doublewords, spellcheck.
# All other quality checks should be ignored.
reducedchecker = checks.ReducedChecker()
assert fails(reducedchecker.untranslated, "I am untranslated", "")
assert passes(reducedchecker.untranslated, "I am translated", "Ek is vertaal")
assert fails(reducedchecker.unchanged, "Unchanged", "Unchanged")
assert passes(reducedchecker.unchanged, "Unchanged", "Changed")
assert fails(reducedchecker.blank, "Blank string", " ")
assert passes(reducedchecker.doublespacing, "Sentence. Another sentence.", "Sin. No double spacing.")
assert fails(reducedchecker.doublespacing, "Sentence. Another sentence.", "Sin. Uneeded double space in translation.")
assert passes(reducedchecker.doublewords, "Save the rhino", "Save the rhino")
assert fails(reducedchecker.doublewords, "Save the rhino", "Save the the rhino")

# Printf check is disabled.
src, tgt, __ = strprep(u"Non-matching printf variables", u"Ek is %s")
unit = base.TranslationUnit(src)
unit.target = tgt

assert 'printf' not in reducedchecker.run_filters(unit).keys()

# Escapes check is disabled.
src, tgt, __ = strprep(u"A file", u"'n Leer\n")
unit = base.TranslationUnit(src)
unit.target = tgt

assert 'escapes' not in reducedchecker.run_filters(unit).keys()


def test_variables_kde():
"""tests variables in KDE translations"""
# GNOME variables
Expand Down

0 comments on commit 6ec79ea

Please sign in to comment.