]>
Commit | Line | Data |
---|---|---|
7c9e9ae0 MT |
1 | #!/usr/bin/python |
2 | ||
3 | import os | |
4 | ||
5 | import web | |
6 | import web.elements | |
7 | from web.javascript import Javascript | |
8 | ||
9 | BASE="/srv/checkout" | |
10 | ||
11 | projects = [] | |
12 | ||
13 | class Po(object): | |
14 | code2lang = { | |
15 | "da" : "Dansk (Dansk)", | |
16 | "de" : "Deutsch (German)", | |
17 | "fr" : "Français (French)", | |
18 | } | |
19 | ||
20 | def __init__(self, path): | |
21 | self.path = path | |
22 | ||
23 | p = os.popen("msgfmt -v --statistics %s 2>&1" % self.path) | |
24 | self.line = p.readlines()[0] | |
25 | ||
26 | def __cmp__(self, other): | |
27 | return cmp(self.lang, other.lang) | |
28 | ||
29 | @property | |
30 | def code(self): | |
31 | return os.path.basename(self.path)[:-3] | |
32 | ||
33 | @property | |
34 | def lang(self): | |
35 | return self.code2lang.get(self.code, "Unknown (%s)" % self.code) | |
36 | ||
37 | @property | |
38 | def translated(self): | |
39 | return int(self.line.split()[0]) | |
40 | ||
41 | @property | |
42 | def untranslated(self): | |
43 | l = self.line.split() | |
44 | if len(l) == 6: | |
45 | return int(l[3]) | |
46 | elif len(l) == 9: | |
47 | return int(l[6]) | |
48 | return 0 | |
49 | ||
50 | @property | |
51 | def fuzzy(self): | |
52 | l = self.line.split() | |
53 | if len(l) == 9: | |
54 | return l[3] | |
55 | return 0 | |
56 | ||
57 | ||
58 | class Project(object): | |
59 | def __init__(self, id, path, **kwargs): | |
60 | self.id = id | |
61 | self.path = path | |
62 | self._name = kwargs.pop("name") | |
63 | self.desc = kwargs.pop("desc") | |
64 | ||
65 | self._translations = [] | |
66 | self.pot = None | |
67 | self.find_pot() | |
68 | ||
69 | @property | |
70 | def name(self): | |
71 | if self._name: | |
72 | return self._name | |
73 | return self.id | |
74 | ||
75 | @property | |
76 | def translations(self): | |
77 | if not self._translations: | |
78 | for path in os.listdir(self.path): | |
79 | if path.endswith(".po"): | |
80 | self._translations.append(Po(os.path.join(self.path, path))) | |
81 | return self._translations | |
82 | ||
83 | def find_pot(self): | |
84 | for path in os.listdir(self.path): | |
85 | if path.endswith(".pot"): | |
86 | self.pot = Po(os.path.join(self.path, path)) | |
87 | break | |
88 | ||
89 | ||
90 | projects.append(Project("pomona", BASE + "/ipfire-3.x/src/pomona/po", name="Pomona", desc="The pomona installer for ipfire.")) | |
91 | ||
92 | class Content(web.Content): | |
93 | def __init__(self): | |
94 | web.Content.__init__(self) | |
95 | self.projects = projects | |
96 | ||
97 | def __call__(self, lang): | |
98 | ret = """<h3>IPFire Translation Status</h3> | |
99 | <div id="tabs"><ul>""" | |
100 | ||
101 | for project in self.projects: | |
102 | ret += """<li><a href="#%s">%s</a></li>""" % (project.id, project.name) | |
103 | ||
104 | ret += "</ul>" | |
105 | ||
106 | for project in self.projects: | |
107 | ret += """<div id="%s"> | |
108 | <p><strong>Description:</strong> %s</p> | |
109 | <br /> | |
110 | <table class="translate"> | |
111 | <tr> | |
112 | <th>Language</th> | |
113 | <th>Translated</th> | |
114 | <th>Untranslated</th> | |
115 | <th>Fuzzy</th> | |
116 | <th>Status</th> | |
117 | </tr>""" % (project.id, project.desc) | |
118 | ||
119 | total = 0 | |
120 | if project.pot: | |
121 | total = project.pot.untranslated | |
122 | ||
123 | for t in sorted(project.translations): | |
124 | if total: | |
125 | percent = "%3.1f%%" % (t.translated * 100 / total) | |
126 | else: | |
127 | percent = "---.-%" | |
128 | ||
129 | ret += """\ | |
130 | <tr> | |
131 | <td class="lang"><img src="/images/flags/%s.png" alt="%s" />%s</td> | |
132 | <td>%s</td> | |
133 | <td>%s</td> | |
134 | <td>%s</td> | |
135 | <td>%s</td> | |
136 | </tr>""" % \ | |
137 | (t.code, t.code, t.lang, t.translated, t.untranslated, t.fuzzy, percent) | |
138 | ||
139 | ret += "</table>" | |
140 | ||
141 | if project.pot: | |
142 | ret += """\ | |
143 | <p> | |
144 | <br /> | |
145 | <strong>Template</strong> - %s strings | |
146 | </p>""" % project.pot.untranslated | |
147 | ||
148 | ret += "</div>" | |
149 | ||
150 | ret += "</div>" | |
151 | return ret | |
152 | ||
153 | page = web.Page() | |
154 | page.content = Content() | |
155 | page.sidebar = web.elements.DevelopmentSidebar() | |
156 | page.javascript = Javascript(1, 1) | |
157 | page.javascript.write(""" | |
158 | <script type="text/javascript"> | |
159 | $(function() { | |
160 | $("#tabs").tabs(); | |
161 | }); | |
162 | </script> | |
163 | """) |