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
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())
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()
58 Language(language
, match
[1] or "0", match
[3] or "0", match
[5] or "0")
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
))
68 " %5s [%s%s%s] -- %3.0f %% translated"
69 % (language
.language
, tc
, fc
, uc
, language
.get_translated_ratio() * 100)
74 Total translations: %s