def process(self, msg, cat): # Detect documentation update date message if ("\n".join(msg.auto_comment) == "Tag: date"): new_msgstr = self.format_date(msg.msgid) if (msg.fuzzy or msg.msgstr[0] != new_msgstr): msg.msgstr[0] = new_msgstr msg.unfuzzy() report_msg_content(msg, cat)
def process (self, msg, cat): if not msg.translated: return highlight = [] for check in self.current_checks: self.nproblems += check(msg, cat, self.pcache, highlight) if highlight: if self.showmsg: report_msg_content(msg, cat, highlight=highlight, delim=("-" * 20)) else: report_on_msg_hl(highlight, msg, cat) if self.lokalize: report_msg_to_lokalize(msg, cat, highlight)
def process (self, msg, cat): # Check only translated messages. if not msg.translated: return highlight = self.check(msg, cat) self.nproblems += sum(len(x[2]) for x in highlight) # Report problems. if highlight: if self.showmsg: report_msg_content(msg, cat, showmsg=self.showmsg, highlight=highlight, delim=("-" * 20)) else: report_on_msg_hl(highlight, msg, cat) if self.lokalize: report_msg_to_lokalize(msg, cat, highlight)
def process (self, msg, cat): """ Returns 0 if the message is matched, 1 otherwise. """ # Prepare filtered message for matching. msgf = make_filtered_msg(msg, cat, filters=self.pfilters) # Match the message. hl_spec = [] match = self.matcher(msgf, msg, cat, hl_spec) if self.p.invert: match = not match if match: self.nmatch += 1 # Do the replacement in translation if requested. # NOTE: Use the real, not the filtered message. for regex in self.replrxs: for i in range(len(msg.msgstr)): msg.msgstr[i] = regex.sub(self.p.replace, msg.msgstr[i]) if not self.p.nomsg: delim = "-" * 20 if self.nmatch == 1: report(delim) report_msg_content(msg, cat, wrapf=cat.wrapf(), force=True, delim=delim, highlight=hl_spec) if self.p.mark: msg.flag.add(_flag_mark) if self.p.lokalize: report_msg_to_lokalize(msg, cat) elif self.p.mark and _flag_mark in msg.flag: # Remove the flag if present but the message does not match. msg.flag.remove(_flag_mark) return 0 if match else 1
def process(self, msg, cat): mcount = msg.modcount for i in range(len(msg.msgstr)): for tfilter, tfname in self.tfilters: try: # try as type *1A hook res = tfilter(msg.msgstr[i]) except TypeError: try: # try as type *3* hook res = tfilter(msg.msgstr[i], msg, cat) except TypeError: raise SieveError( _("@info", "Cannot execute filter '%(filt)s'.", filt=tfname)) # Process result based on hook type. if isinstance(res, basestring): # Modification hook. msg.msgstr[i] = res elif isinstance(res, list): # Validation hook. if res: report_msg_content(msg, cat, highlight=[("msgstr", i, res)], delim=("-" * 20)) else: # Side-effect hook, nothing to do. # TODO: Perhaps report returned number? pass if mcount < msg.modcount: self.nmod += 1 if self.p.showmsg: report_msg_content(msg, cat, delim=("-" * 20))
def hook(msg, cat): if _flag_no_bad_patterns in manc_parse_flag_list(msg, "|"): return 0 parts = [] nbad = 0 for i in range(len(msg.msgstr)): indspans = _match_patterns(msg.msgstr[i], patterns_cmp) spans = [] for pind, span in indspans: emsg = _("@info", "Bad pattern '%(pattern)s' detected.", pattern=patterns_str[pind]) spans.append(span + (emsg, )) nbad += 1 if spans: parts.append(("msgstr", i, spans)) if partrep: return parts else: if parts: report_msg_content(msg, cat, highlight=parts, delim=("-" * 20)) return nbad
def hybdl(path, path0, accnohyb=False): cat = Catalog(path) cat0 = Catalog(path0, monitored=False) nhybridized = 0 nstopped = 0 for msg in cat: if "no-hybdl" in manc_parse_flag_list(msg, "|"): continue # Unembed diff if message was diffed for review. # Replace ediff with manual review flag. diffed = False for flag in msg.flag: if flag.startswith("ediff"): msg.flag.remove(flag) diffed = True if diffed: msg_ediff_to_new(msg, msg) msg.flag.add(u"reviewed") # Fetch original message. msg0 = cat0.get(msg) if msg0 is None: warning_on_msg( _("@info", "Message does not exist in the original catalog."), msg, cat) nstopped += 1 continue if len(msg.msgstr) != len(msg0.msgstr): warning_on_msg( _( "@info", "Number of translations not same as in " "the original message."), msg, cat) nstopped += 1 continue if msg.msgstr == msg0.msgstr: # No changes, nothing new to hybridize. continue # Hybridize translation. textsh = [] textshinv = [] for text0, text in zip(msg0.msgstr, msg.msgstr): texth = tohi(text0, text, parthyb=True) textsh.append(texth) if not accnohyb: texthinv = tohi(text, text0, parthyb=True) textshinv.append(texthinv) if accnohyb or textsh == textshinv: for i, texth in zip(range(len(msg.msgstr)), textsh): msg.msgstr[i] = texth nhybridized += 1 else: nstopped += 1 msgh = MessageUnsafe(msg) msgh.msgstr = textsh msghinv = MessageUnsafe(msg) msghinv.msgstr = textshinv msg_ediff(msghinv, msgh, emsg=msgh, colorize=True) report_msg_content(msgh, cat, delim=("-" * 20)) if nstopped == 0: if cat.sync(): report("! %s (%d)" % (path, nhybridized)) else: warning( n_("@info", "%(num)d message in '%(file)s' cannot be " "cleanly hybridized.", "%(num)d messages in '%(file)s' cannot be " "cleanly hybridized.", num=nstopped, file=path)) nhybridized = 0 return nhybridized
def process (self, msg, cat): new_msgstr = self.translate(msg) if new_msgstr is not None and (msg.fuzzy or msg.msgstr[0] != new_msgstr): msg.msgstr[0] = new_msgstr msg.unfuzzy() report_msg_content(msg, cat)