File indexing completed on 2024-12-01 05:13:47
0001 # -*- coding: UTF-8 -*- 0002 0003 """ 0004 Check catalogs covering Docbook 4.x documents for various problems. 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.markup import check_docbook4_msg 0014 from pology.msgreport import report_on_msg_hl, report_msg_content 0015 from pology.msgreport import report_msg_to_lokalize 0016 from pology.report import report 0017 from pology.sieve import add_param_poeditors 0018 0019 0020 def setup_sieve (p): 0021 0022 p.set_desc(_("@info sieve discription", 0023 "Check catalogs covering Docbook 4.x documents for various problems." 0024 )) 0025 0026 p.add_param("showmsg", bool, defval=False, 0027 desc=_("@info sieve parameter discription", 0028 "Also show the full message which has a problem." 0029 )) 0030 add_param_poeditors(p) 0031 0032 0033 class Sieve (object): 0034 0035 def __init__ (self, params): 0036 0037 self.showmsg = params.showmsg 0038 self.lokalize = params.lokalize 0039 0040 # Indicators to the caller: 0041 self.caller_sync = False # no need to sync catalogs to the caller 0042 self.caller_monitored = False # no need for monitored messages 0043 0044 self.check = check_docbook4_msg(strict=False, entities=None) 0045 0046 self.nproblems = 0 0047 0048 0049 def process (self, msg, cat): 0050 0051 # Check only translated messages. 0052 if not msg.translated: 0053 return 0054 0055 highlight = self.check(msg, cat) 0056 self.nproblems += sum(len(x[2]) for x in highlight) 0057 0058 # Report problems. 0059 if highlight: 0060 if self.showmsg: 0061 report_msg_content(msg, cat, showmsg=self.showmsg, 0062 highlight=highlight, delim=("-" * 20)) 0063 else: 0064 report_on_msg_hl(highlight, msg, cat) 0065 if self.lokalize: 0066 report_msg_to_lokalize(msg, cat, highlight) 0067 0068 0069 def finalize (self): 0070 0071 if self.nproblems > 0: 0072 msg = n_("@info:progress", 0073 "Found %(num)d problem in Docbook translations.", 0074 "Found %(num)d problems in Docbook translations.", 0075 num=self.nproblems) 0076 report("===== " + msg) 0077