<div dir="ltr">We may want to include this in trunk like we do with other .py tools in the main documentation repository, now that it is in python and everyone is able to use it.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 23, 2015 at 1:11 PM, Anton Felix Lorenzen <span dir="ltr">&lt;<a href="mailto:anfelor@web.de" target="_blank">anfelor@web.de</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
I re-wrote the script in python,<br>
it&#39;s now around 360 times as fast using python3<br>
(and even 675 times when using pypy).<br>
<br>
I overused grep before,<br>
so it took the script 9 minutes to finish,<br>
now it runs in approx. 1 second.<br>
<br>
It also shows files with fuzzy strings in it<br>
and should also run on windows.<br>
<br>
Sincerely,<br>
Anton Felix Lorenzen<br>
<br>
Usage:<br>
|- Paste into file named translations.py<br>
|- &quot;cd&quot; into folder<br>
|- execute python translations.py &quot;C:\path\to\LC_MESSAGES&quot;<br>
<br>
Script:<br>
<br>
#!/usr/bin/env python2<br>
# -*- coding: utf-8 -*-<br>
#<br>
#  Translations Tracker 1.0<br>
#  works best with pypy<br>
#<br>
#  Copyright 2015 Anton Felix Lorenzen &lt;<a href="mailto:anfelor@web.de">anfelor@web.de</a>&gt;<br>
#<br>
#  Permission is hereby granted, free of charge,<br>
#  to any person obtaining a copy of this software<br>
#  and associated documentation files (the &quot;Software&quot;),<br>
#  to deal in the Software without restriction,<br>
#  including without limitation the rights to use, copy,<br>
#  modify, merge, publish, distribute, sublicense,<br>
#  and/or sell copies of the Software,<br>
#  and to permit persons to whom the Software is furnished to do so,<br>
#  subject to the following conditions:<br>
#<br>
#  The above copyright notice and this permission notice<br>
#  shall be included in all copies or substantial portions of the Software.<br>
#<br>
#  THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,<br>
#  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF<br>
MERCHANTABILITY,<br>
#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.<br>
#  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY<br>
CLAIM,<br>
#  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,<br>
#  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE<br>
SOFTWARE<br>
#  OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.<br>
<br>
import os<br>
import codecs<br>
import sys<br>
<br>
if(sys.argv and sys.argv[1]):<br>
        path = sys.argv[1]<br>
else:<br>
        path = &quot;~/locale/fr/LC_MESSAGES&quot;<br>
<br>
# Configuration<br>
fileinfo  = &#39;{0[file]:&gt;3} empty, {1[file]:&gt;3} fuzzy of {2[file]:&gt;3}; or<br>
{3:.3f}% in {4}&#39;<br>
allinfo   = &#39;Summary: {0[all]} empty of {1[all]}; or {2:.3f}%&#39;<br>
fuzzyinfo = &#39;Fuzzy:   {0[all]} fuzzy strings in {0[filelist]}&#39;<br>
<br>
msgstrs = {&#39;file&#39;: 0, &#39;all&#39;:0}<br>
empty_msgstrs = {&#39;file&#39;: 0, &#39;all&#39;: 0}<br>
fuzzy = {&#39;file&#39;: 0, &#39;all&#39;: 0, &#39;filelist&#39;: []}<br>
lastLineWasEmptyMsgstr = False<br>
<br>
def forAllInMap(m, fnk, cond):<br>
        for key in m:<br>
                if(cond(m[key])):<br>
                        m[key] = fnk(m[key])<br>
<br>
def forAllIntsInMap(m, fnk):<br>
        forAllInMap(m, fnk, lambda x: type(x)==int)<br>
<br>
def increaseAllInMap(m):<br>
        forAllIntsInMap(m, lambda x: x+1)<br>
<br>
def decreseAllInMap(m):<br>
        forAllIntsInMap(m, lambda x: x-1)<br>
<br>
for (root, subs, files) in os.walk(path):<br>
        for name in files:<br>
                msgstrs[&#39;file&#39;] = -1 # First lines contain a &quot;fake&quot; msgstr<br>
                msgstrs[&#39;all&#39;] -= 1<br>
                empty_msgstrs[&#39;file&#39;] = 0<br>
                fuzzy[&#39;file&#39;] = 0<br>
                if name.endswith(&#39;.po&#39;):<br>
                        for line in codecs.open(os.path.join(root, name), encoding=&#39;utf8&#39;):<br>
                                if(line[0] == &#39;m&#39;):<br>
                                        if(line[0:6] == &#39;msgstr&#39;):<br>
                                                increaseAllInMap(msgstrs)<br>
                                                if(line[0:9] == &#39;msgstr &quot;&quot;&#39;):<br>
                                                        increaseAllInMap(empty_msgstrs)<br>
                                                        lastLineWasEmptyMsgstr = True<br>
                                else:<br>
                                        if(line[0] == &#39;&quot;&#39;):<br>
                                                if(lastLineWasEmptyMsgstr):<br>
                                                        decreseAllInMap(empty_msgstrs)<br>
                                                        lastLineWasEmptyMsgstr = False<br>
                                        else:<br>
                                                lastLineWasEmptyMsgstr = False<br>
                                                if(&#39;fuzzy&#39; in line):<br>
                                                        increaseAllInMap(fuzzy)<br>
                                                        fuzzy[&#39;filelist&#39;] += [name]<br>
<br>
                print(fileinfo.format(empty_msgstrs, fuzzy, msgstrs,<br>
                        float(empty_msgstrs[&#39;file&#39;] + fuzzy[&#39;file&#39;]) / msgstrs[&#39;file&#39;],<br>
                        os.path.join(root[len(path):], name)))<br>
<br>
print(allinfo.format(empty_msgstrs, msgstrs, float(empty_msgstrs[&#39;all&#39;])<br>
/ msgstrs[&#39;all&#39;]))<br>
print(fuzzyinfo.format(fuzzy))<br>
_______________________________________________<br>
Bf-docboard mailing list<br>
<a href="mailto:Bf-docboard@blender.org">Bf-docboard@blender.org</a><br>
<a href="http://lists.blender.org/mailman/listinfo/bf-docboard" rel="noreferrer" target="_blank">http://lists.blender.org/mailman/listinfo/bf-docboard</a><br>
</blockquote></div><br></div>