# -*- coding: UTF-8 -*- """ Find tooltip messages containing lines longer than 75 characters. Sieve options: - C{lokalize}: open catalogs at matched messages in Lokalize - C{original}: check "msgid"s instead of "msgstr"s @author: Alexander Potashev @license: GPLv3 Based on sieves from Pology. """ from pology import _, n_ from pology.misc.report import report from pology.misc.msgreport import report_msg_content from pology.misc.msgreport import report_msg_to_lokalize import re def setup_sieve (p): p.set_desc(_("@info sieve discription", "Find messages with msgstr[1] == msgstr[2]." )) p.add_param("lokalize", bool, defval=False, desc=_("@info sieve parameter discription", "Open catalogs at matched messages in Lokalize." )) p.add_param("original", bool, defval=False, desc=_("@info sieve parameter discription", "Check \"msgid\"s instead of \"msgstr\"s." )) def is_tooltip (msg): return re.search("property .toolTip", "\n".join(msg.auto_comment)) is not None def max_line_length (str): return max(map(lambda x: len(x), str.split("\n"))) class Sieve (object): def __init__ (self, params): self.p = params self.nfound = 0 def msg_max_line_length (self, msg): if (self.p.original): return max_line_length(msg.msgid) else: return max_line_length(msg.msgstr[0]) def process (self, msg, cat): if (not msg.obsolete and not msg.fuzzy and not msg.untranslated and is_tooltip(msg) and re.search("", msg.msgstr[0]) is None and self.msg_max_line_length(msg) > 75): self.nfound += 1 report_msg_content(msg, cat) if self.p.lokalize: report_msg_to_lokalize(msg, cat) print "-" * 20 def finalize (self): if self.nfound > 0: msg = n_("@info:progress", "Found %(num)d message of translation.", "Found %(num)d messages of translation.", num=self.nfound) report("===== " + msg)