Bump redis from 3.5.3 to 4.0.2
[mygpo.git] / tools / i18n / summary.py
blob4aea8cfd45e346b79c74f0e4f72699de116788d4
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
18 class Language(object):
19 def __init__(self, language, translated, fuzzy, untranslated):
20 self.language = language
21 self.translated = int(translated)
22 self.fuzzy = int(fuzzy)
23 self.untranslated = int(untranslated)
25 def get_translated_ratio(self):
26 return float(self.translated) / float(
27 self.translated + self.fuzzy + self.untranslated
30 def get_fuzzy_ratio(self):
31 return float(self.fuzzy) / float(
32 self.translated + self.fuzzy + self.untranslated
35 def get_untranslated_ratio(self):
36 return float(self.untranslated) / float(
37 self.translated + self.fuzzy + self.untranslated
40 def __cmp__(self, other):
41 return cmp(self.get_translated_ratio(), other.get_translated_ratio())
44 languages = []
46 COUNTS_RE = "((\d+) translated message[s]?)?(, (\d+) fuzzy translation[s]?)?(, (\d+) untranslated message[s]?)?\."
48 po_folder = os.path.join(os.path.dirname(__file__), "..", "..", "mygpo", "locale")
49 for filename in glob.glob(os.path.join(po_folder, "*", "LC_MESSAGES", "django.po")):
50 language = filename.split("/")[-3]
51 msgfmt = subprocess.Popen(
52 ["msgfmt", "--statistics", filename], stderr=subprocess.PIPE
54 _, stderr = msgfmt.communicate()
56 match = re.match(COUNTS_RE, stderr).groups()
57 languages.append(
58 Language(language, match[1] or "0", match[3] or "0", match[5] or "0")
61 print("")
62 for language in sorted(languages):
63 tc = "#" * (int(math.floor(width * language.get_translated_ratio())))
64 fc = "~" * (int(math.floor(width * language.get_fuzzy_ratio())))
65 uc = " " * (width - len(tc) - len(fc))
67 print(
68 " %5s [%s%s%s] -- %3.0f %% translated"
69 % (language.language, tc, fc, uc, language.get_translated_ratio() * 100)
72 print(
73 """
74 Total translations: %s
75 """
76 % (len(languages))