File indexing completed on 2024-04-21 05:44:52

0001 # -*- coding: UTF-8 -*-
0002 
0003 """
0004 Make all fuzzy messages untranslated.
0005 
0006 Documented in C{doc/user/sieving.docbook}.
0007 
0008 @author: Chusslove Illich (Часлав Илић) <caslav.ilic@gmx.net>
0009 @license: GPLv3
0010 """
0011 
0012 from pology import _, n_
0013 from pology.report import report
0014 
0015 
0016 def setup_sieve (p):
0017 
0018     p.set_desc(_("@info sieve discription",
0019     "Clear all fuzzy messages of translation."
0020     ))
0021 
0022     p.add_param("rmcomments", bool, defval=False,
0023                 desc=_("@info sieve parameter discription",
0024     "Also remove translator comments from fuzzy messages."
0025     ))
0026     p.add_param("noprev", bool, defval=False,
0027                 desc=_("@info sieve parameter discription",
0028     "Clear only fuzzy messages which do not have previous fields."
0029     ))
0030 
0031 
0032 class Sieve (object):
0033 
0034     def __init__ (self, params):
0035 
0036         self.rmcomments = params.rmcomments
0037         self.noprev = params.noprev
0038 
0039         self.nemptied = 0
0040 
0041 
0042     def process (self, msg, cat):
0043 
0044         if (   (not self.noprev and msg.fuzzy)
0045             or (self.noprev and msg.fuzzy and msg.msgid_previous is None)
0046         ):
0047             if not msg.obsolete:
0048                 msg.clear(keepmanc=(not self.rmcomments))
0049                 self.nemptied += 1
0050             else:
0051                 cat.remove_on_sync(msg)
0052 
0053 
0054     def finalize (self):
0055 
0056         if self.nemptied > 0:
0057             msg = n_("@info:progress",
0058                      "Cleared %(num)d fuzzy message of translation.",
0059                      "Cleared %(num)d fuzzy messages of translation.",
0060                      num=self.nemptied)
0061             report("===== " + msg)
0062