File indexing completed on 2024-03-24 17:21:47

0001 # -*- coding: UTF-8 -*-
0002 
0003 """
0004 Unfuzzy messages fuzzied only due to changed Qt class name.
0005 
0006 Documented in C{doc/user/sieving.docbook}.
0007 
0008 @author: Chusslove Illich (Часлав Илић) <caslav.ilic@gmx.net>
0009 @license: GPLv3
0010 """
0011 
0012 import re
0013 
0014 from pology import _, n_
0015 from pology.report import report
0016 
0017 
0018 def setup_sieve (p):
0019 
0020     p.set_desc(_("@info sieve discription",
0021     "Unfuzzy messages which got fuzzy only due to changed Qt class name."
0022     "\n\n"
0023     "Possible only if catalogs were merged with --previous option.",
0024     ))
0025 
0026 
0027 _strip_rx = re.compile(r"^[a-z][\w:]*\|(.*)", re.U|re.I)
0028 
0029 # Strip the Qt class.
0030 def _stripped (ctxt):
0031     m = _strip_rx.search(ctxt)
0032     stripped = m.group(1) if m else ctxt
0033     return stripped
0034 
0035 
0036 class Sieve (object):
0037 
0038     def __init__ (self, params):
0039 
0040         self.nmatch = 0
0041 
0042 
0043     def process (self, msg, cat):
0044 
0045         if (    msg.fuzzy
0046             and msg.msgid == msg.msgid_previous
0047             and msg.msgid_plural == msg.msgid_plural_previous
0048             and (   _stripped(msg.msgctxt or "")
0049                  == _stripped(msg.msgctxt_previous or ""))
0050         ):
0051             msg.unfuzzy()
0052             self.nmatch += 1
0053 
0054 
0055     def finalize (self):
0056 
0057         if self.nmatch > 0:
0058             msg = n_("@info:progress",
0059                      "Unfuzzied %(num)d message fuzzy due to "
0060                      "difference in Qt class context only.",
0061                      "Unfuzzied %(num)d messages fuzzy due to "
0062                      "difference in Qt class context only.",
0063                      num=self.nmatch)
0064             report("===== " + msg)
0065 
0066