def filterunit(self, unit): """Runs filters on an element.""" if unit.isheader(): return [] if not self.options.includefuzzy and unit.isfuzzy(): return [] if not self.options.includereview and unit.isreview(): return [] failures = self.checker.run_filters(unit, categorised=True) if failures and self.options.autocorrect: # we can't get away with bad unquoting / requoting if we're going to change the result... correction = autocorrect.correct(unit.source, unit.target) if correction: unit.target = correction return autocorrect else: # ignore failures we can't correct when in autocorrect mode return [] return failures
def correct(self, msgid, msgstr, expected): """helper to run correct function from autocorrect module""" corrected = autocorrect.correct(msgid, msgstr) print repr(msgid) print repr(msgstr) print msgid.encode('utf-8') print msgstr.encode('utf-8') print(corrected or u"").encode('utf-8') assert corrected == expected
def correct(self, msgid, msgstr, expected): """helper to run correct function from autocorrect module""" corrected = autocorrect.correct(msgid, msgstr) print repr(msgid) print repr(msgstr) print msgid.encode('utf-8') print msgstr.encode('utf-8') print (corrected or u"").encode('utf-8') assert corrected == expected
def correct(msgid, msgstr, expected): """helper to run correct function from autocorrect module""" corrected = autocorrect.correct(msgid, msgstr) print(repr(msgid)) print(repr(msgstr)) print(msgid.encode("utf-8")) print(msgstr.encode("utf-8")) print((corrected or "").encode("utf-8")) assert corrected == expected
def fixup(source, response): source = data.forceunicode(source) response = data.forceunicode(response) from translate.filters.autocorrect import correct tmp = correct(source, response) if tmp: response = tmp response = response.replace(u" __::__ ", "\n") # and again for the sake of \n\n: response = response.replace(u"__::__ ", "\n") response = response.replace(u"( ", u"(") for c, repl in punc_tuples: response = response.replace(repl, c) return response