]> git.ipfire.org Git - people/shoehn/ipfire.org.git/blob - www/webapp/translations.py
Initial checkin.
[people/shoehn/ipfire.org.git] / www / webapp / translations.py
1 #!/usr/bin/python
2
3 import os
4
5 import tornado.locale
6
7 class Po(object):
8 def __init__(self, path, project):
9 self.path = path
10 self.project = project
11
12 p = os.popen("msgfmt -v --statistics %s 2>&1" % self.path)
13 self.line = p.readlines()[0]
14
15 def __cmp__(self, other):
16 return cmp(self.lang, other.lang)
17
18 @property
19 def code2lang(self):
20 ret = {}
21 for lang in tornado.locale.LOCALE_NAMES.keys():
22 ret[lang[:2]] = "%(name)s (%(name_en)s)" % tornado.locale.LOCALE_NAMES[lang]
23 return ret
24
25 @property
26 def code(self):
27 return os.path.basename(self.path)[:-3]
28
29 @property
30 def lang(self):
31 return self.code2lang.get(self.code, "Unknown (%s)" % self.code)
32
33 @property
34 def translated(self):
35 return int(self.line.split()[0])
36
37 @property
38 def untranslated(self):
39 l = self.line.split()
40 if len(l) == 6:
41 return int(l[3])
42 elif len(l) == 9:
43 return int(l[6])
44 return 0
45
46 @property
47 def fuzzy(self):
48 l = self.line.split()
49 if len(l) == 9:
50 return l[3]
51 return 0
52
53 @property
54 def percent(self):
55 if not self.project.total_strings:
56 return "---.-- %"
57
58 return "%3.1f%%" % (self.translated * 100 / self.project.total_strings)
59
60
61 class Project(object):
62 def __init__(self, id, path, **kwargs):
63 self.id = id
64 self.path = path
65 self._name = kwargs.pop("name")
66 self.desc = kwargs.pop("desc")
67
68 self._translations = []
69 self.pot = None
70 self.find_pot()
71
72 @property
73 def name(self):
74 if self._name:
75 return self._name
76 return self.id
77
78 @property
79 def translations(self):
80 if not self._translations:
81 for path in os.listdir(self.path):
82 if path.endswith(".po"):
83 self._translations.append(Po(os.path.join(self.path, path), self))
84 self._translations.sort()
85 return self._translations
86
87 def find_pot(self):
88 for path in os.listdir(self.path):
89 if path.endswith(".pot"):
90 self.pot = Po(os.path.join(self.path, path), self)
91 break
92
93 @property
94 def total_strings(self):
95 if not self.pot:
96 return 0
97 return self.pot.untranslated
98
99 projects = [
100 Project("pomona", "/srv/checkout/ipfire-3.x/src/pomona/po",
101 name="Pomona", desc="The pomona installer for ipfire."),
102 ]