[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-i18n-doc
Subject:    Pology sieve to search for "sticky" messages
From:       Alexander Potashev <aspotashev () gmail ! com>
Date:       2014-05-26 11:06:53
Message-ID: CADMG6+_86ov46HTJEoOTOS-e2QRpNXjTtF1YY7d8WQF3Yy007Q () mail ! gmail ! com
[Download RAW message or body]

Hi Dmitry and KDE translators!

I've written a (draft) Pology sieve to find all messages that come
from multiple places. As I expected, this search condition is too
weak, so you might want to add other conditions, e.g.
 1. Message must not be too long,
 2. Occurrences of message should not all come from the same .cpp/.h file.

The sieve file is in the attachment. Please make an SVN checkout of
svn+ssh://svn@svn.kde.org/home/kde/trunk/l10n-support/pology (or
similar path for anonsvn) and put the attached file under the "sieve/"
directory. I also add the "pology/bin" directory to $PATH.

To use the sieve with EMACS grep-mode:
 1. Run "posieve find_sticky krita.po > krita-sticky-list.txt"
 2. Open the resulting .txt file in EMACS, switch to "grep-mode" and
click the links.

-- 
Alexander Potashev

["find_sticky.py" (text/x-python)]

# -*- coding: UTF-8 -*-

"""
Find messages that probably need to be split by adding context strings.

@author: Alexander Potashev <aspotashev@gmail.com>
@license: GPLv3
"""

from pology import _, n_
from pology.message import MessageUnsafe, Message
from pology.remove import remove_accel_msg
from pology.getfunc import get_hook_ireq
from pology.msgreport import report_msg_content
from pology.report import report
from pology.monitored import Monlist


def setup_sieve (p):
    p.set_desc(_("@info sieve discription",
    "Find sticky messages in catalogs."
    ))

class Sieve (object):

    def __init__ (self, params):
        self.nmatch = 0
        self.nsrc = 0
        self.p = params

    def process (self, msg, cat):
        """
        Returns 0 if the message is matched, 1 otherwise.
        """

        # We will make temporary changes to "msg" and do not want those
        # changes to be saved to the .po file. Make a deep copy.
        # 
        # What are the easier ways to create a deep copy of a Pology Message,
        # or disable automatic syncing to the file to messages or entire
        # catalogs?
        orig_msg = msg
        msg = Message().set(orig_msg)
        msg.refentry = orig_msg.refentry
        msg.refline = orig_msg.refline

        delim = "-" * 20
        if self.nmatch == 0:
            report(delim)
        if len(msg.source) > 1:
            for srcfile, lineno in msg.source:
                report("%s:%d:" % (srcfile, lineno))
            msg.source = Monlist() # TBD: do not modify .po file
            report_msg_content(msg, cat, wrapf=cat.wrapf(), force=False, delim=delim)
            self.nmatch += 1
            self.nsrc += len(msg.source)
            return 0
        else:
            return 1

    def finalize (self):
        if self.nmatch:
            msg = n_("@info:progress",
                     "Found %(num)d message satisfying the conditions.",
                     "Found %(num)d messages satisfying the conditions.",
                     num=self.nmatch)
            report("===== " + msg)
            msg = n_("@info:progress",
                     "Found %(num)d message source satisfying the conditions.",
                     "Found %(num)d message sources satisfying the conditions.",
                     num=self.nsrc)
            report("===== " + msg)



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic