[Tests] Test slug functionality, fix Slug ordering
[mygpo.git] / tools / i18n / summary.py
blob6d73b01ea54350c56977cc68ff91b8b593cfcad8
1 #!/usr/bin/python
2 # summary.py - Text-based visual translation completeness summary
3 # Thomas Perl <thp@gpodder.org>, 2009-01-03
5 # Usage: make statistics | python summary.py
8 import sys
9 import re
10 import math
11 import glob
12 import os
13 import subprocess
15 width = 40
17 class Language(object):
18 def __init__(self, language, translated, fuzzy, untranslated):
19 self.language = language
20 self.translated = int(translated)
21 self.fuzzy = int(fuzzy)
22 self.untranslated = int(untranslated)
24 def get_translated_ratio(self):
25 return float(self.translated)/float(self.translated+self.fuzzy+self.untranslated)
27 def get_fuzzy_ratio(self):
28 return float(self.fuzzy)/float(self.translated+self.fuzzy+self.untranslated)
30 def get_untranslated_ratio(self):
31 return float(self.untranslated)/float(self.translated+self.fuzzy+self.untranslated)
33 def __cmp__(self, other):
34 return cmp(self.get_translated_ratio(), other.get_translated_ratio())
36 languages = []
38 COUNTS_RE = '((\d+) translated message[s]?)?(, (\d+) fuzzy translation[s]?)?(, (\d+) untranslated message[s]?)?\.'
40 po_folder = os.path.join(os.path.dirname(__file__), '..', '..', 'mygpo', 'locale')
41 for filename in glob.glob(os.path.join(po_folder, '*', 'LC_MESSAGES', 'django.po')):
42 language = filename.split('/')[-3]
43 msgfmt = subprocess.Popen(['msgfmt', '--statistics', filename],
44 stderr=subprocess.PIPE)
45 _, stderr = msgfmt.communicate()
47 match = re.match(COUNTS_RE, stderr).groups()
48 languages.append(Language(language, match[1] or '0', match[3] or '0', match[5] or '0'))
50 print ''
51 for language in sorted(languages):
52 tc = '#'*(int(math.floor(width*language.get_translated_ratio())))
53 fc = '~'*(int(math.floor(width*language.get_fuzzy_ratio())))
54 uc = ' '*(width-len(tc)-len(fc))
56 print ' %5s [%s%s%s] -- %3.0f %% translated' % (language.language, tc, fc, uc, language.get_translated_ratio()*100)
58 print """
59 Total translations: %s
60 """ % (len(languages))