Add scripts to generate translation statistics.

Text version by me, html version by Emdek. The CSS and flag images used
by the latter are in
https://github.com/Warzone2100/wz2100.net/blob/master/static.wz2100.net/htdocs/css/wztrac.css
and
https://github.com/Warzone2100/wz2100.net/tree/master/static.wz2100.net/htdocs/img/flags.
master
cybersphinx 2012-04-23 23:06:40 +02:00
parent 3dc5d8d796
commit 01e38ca88c
2 changed files with 69 additions and 0 deletions

64
po/generate-statistics-html.py Executable file
View File

@ -0,0 +1,64 @@
#!/usr/bin/env python
import glob
import os
import re
import subprocess
width = 300
images = 'http://static.wz2100.net/img/flags/'
messages = {}
percents = {}
catalogs = {}
for i in glob.glob('*.po'):
process = subprocess.Popen(['msgfmt', '--statistics', i], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
errors, output = process.communicate()
messages['translated'] = 0
messages['untranslated'] = 0
messages['fuzzy'] = 0
messages['amount'] = 0
matches = re.search('(\d+) translated', output)
if matches != None:
messages['translated'] = int(matches.group(1))
matches = re.search('(\d+) untranslated', output)
if matches != None:
messages['untranslated'] = int(matches.group(1))
matches = re.search('(\d+) fuzzy', output)
if matches != None:
messages['fuzzy'] = int(matches.group(1))
messages['amount'] = (messages['translated'] + messages['untranslated'] + messages['fuzzy'])
percents['fuzzy'] = (0 if messages['fuzzy'] == 0 else (float(messages['fuzzy']) / messages['amount']));
percents['untranslated'] = (0 if messages['untranslated'] == 0 else (float(messages['untranslated']) / messages['amount']));
percents['translated'] = (1 - percents['fuzzy'] - percents['untranslated']);
catalog = '%5d%s' % (((1 - percents['translated']) * 1000), i)
catalogs[catalog] = '<li class="' + ('translation_complete' if percents['translated'] >= 0.9 else ('translation_unfinished' if percents['translated'] >= 0.8 else 'translation_incomplete')) + '">\n<span class="messages_translated" style="width: ' + str(width) + 'px" title="' + output.rstrip()[0:-1] + '">\n'
if percents['untranslated'] > 0:
catalogs[catalog] += '<span class="messages_untranslated" style="width: %dpx"></span>\n' % max(2, (percents['untranslated'] * width))
if percents['fuzzy'] > 0:
catalogs[catalog] += '<span class="messages_fuzzy" style="width: %dpx"></span>\n' % max(2, (percents['fuzzy'] * width))
catalogs[catalog] += '</span>\n<img src="%s%s.png" alt="" title="%s" /> <strong>%s</strong> %.2f%%\n</li>' % (images, i[0:-3], i[0:-3], i[0:-3], (percents['translated'] * 100))
keys = catalogs.keys()
keys.sort()
print '<ul id="translation_status">'
for i in keys:
print catalogs[i]
print '</ul>'

5
po/generate-statistics-text.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
for i in *.po; do
echo -n $i:\ ; msgfmt --statistics $i 2>&1 | awk 'ORS="% done - " {print 100*$1/($1+$4+$7)}'; msgfmt --statistics $i 2>&1
done