]> git.donarmstrong.com Git - lilypond.git/blob - scripts/auxiliar/translations-status.py
translations-status.py: Remove inline html from short_texi_status.
[lilypond.git] / scripts / auxiliar / translations-status.py
1 #!/usr/bin/env python
2
3 '''
4 USAGE: cd Documentation && translations-status.py
5
6   Write:
7     translations.itexi
8     <LANG>/translations.itexi
9     out/translations-status.txt
10
11   Update word counts in:
12     contributor/doc-translation-list.itexi
13 '''
14
15 import sys
16 import re
17 import string
18 import operator
19 import os
20 #
21 import langdefs
22 import buildlib
23
24 def progress (str):
25     sys.stderr.write (str + '\n')
26
27 exit_code = 0
28
29 def error (str, update_status=1):
30     global exit_code
31     sys.stderr.write ('translations-status.py: %s\n' % str)
32     exit_code = max (exit_code, update_status)
33
34 progress ("translations-status.py")
35
36 _doc = lambda s: s
37
38 # load gettext messages catalogs
39 translation = langdefs.translation
40
41
42 language_re = re.compile (r'^@documentlanguage (.+)', re.M)
43 comments_re = re.compile (r'^@ignore\n(.|\n)*?\n@end ignore$|@c .*?$', re.M)
44 space_re = re.compile (r'\s+', re.M)
45 lilypond_re = re.compile (r'@lilypond({.*?}|(.|\n)*?\n@end lilypond$)', re.M)
46 node_re = re.compile ('^@node .*?$', re.M)
47 title_re = re.compile ('^@(settitle|chapter|top|(?:sub){0,2}section|'
48                            '(?:unnumbered|appendix)(?:(?:sub){0,2}sec)?) (.*?)$', re.M)
49 include_re = re.compile ('^@include (.*?)$', re.M)
50
51 # allow multiple lines
52 translators_re = re.compile (r'^@c[ ]+[Tt]ranslators?[ ]*:[ ]*(.*?)$', re.M)
53 checkers_re = re.compile (r'^@c[ ]+[Tt]ranslation[ ]*[Cc]heckers?[ ]*:[ ]*(.*?)$', re.M)
54 status_re = re.compile (r'^@c[ ]+[Tt]ranslation[ ]*[Ss]tatus[ ]*:[ ]*(.*?)$', re.M)
55 post_gdp_re = re.compile ('post.GDP', re.I)
56 untranslated_node_str = '@untranslated'
57 skeleton_str = '-- SKELETON FILE --'
58
59 section_titles_string = _doc ('Section titles')
60 last_updated_string = _doc (' <p><i>Last updated %s</i></p>\n')
61 detailed_status_heads = [_doc ('Translators'), _doc ('Translation checkers'),
62                          _doc ('Translated'), _doc ('Up to date'),
63                          _doc ('Other info')]
64 format_table = {
65     'not translated': {'color':'d0f0f8', 'short':_doc ('no'), 'abbr':'NT',
66                        'long':_doc ('not translated')},
67     'partially translated': {'color':'dfef77',
68                              'short':_doc ('partially (%(p)d %%)'),
69                              'abbr':'%(p)d%%',
70                              'long':_doc ('partially translated (%(p)d %%)')},
71     'fully translated': {'color':'1fff1f', 'short':_doc ('yes'), 'abbr':'FT',
72                          'long': _doc ('translated')},
73     'up to date': {'short':_doc ('yes'), 'long':_doc ('up to date'),
74                    'abbr':'100%%', 'vague':_doc ('up to date')},
75     'outdated': {'short':_doc ('partially'), 'abbr':'%(p)d%%',
76                  'vague':_doc ('partially up to date')},
77     'N/A': {'short':_doc ('N/A'), 'abbr':'N/A', 'color':'d587ff', 'vague':''},
78     'pre-GDP':_doc ('pre-GDP'),
79     'post-GDP':_doc ('post-GDP')
80 }
81
82 texi_level = {
83 # (Unumbered/Numbered/Lettered, level)
84     'top': ('u', 0),
85     'unnumbered': ('u', 1),
86     'unnumberedsec': ('u', 2),
87     'unnumberedsubsec': ('u', 3),
88     'chapter': ('n', 1),
89     'section': ('n', 2),
90     'subsection': ('n', 3),
91     'appendix': ('l', 1),
92     'appendixsec': ('l', 2),
93 }
94
95 appendix_number_trans = string.maketrans ('@ABCDEFGHIJKLMNOPQRSTUVWXY',
96                                           'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
97
98 class SectionNumber (object):
99     def __init__ (self):
100         self.__data = [[0,'u']]
101
102     def __increase_last_index (self):
103         type = self.__data[-1][1]
104         if type == 'l':
105             self.__data[-1][0] = \
106                 self.__data[-1][0].translate (appendix_number_trans)
107         elif type == 'n':
108             self.__data[-1][0] += 1
109
110     def format (self):
111         if self.__data[-1][1] == 'u':
112             return ''
113         return '.'.join ([str (i[0]) for i in self.__data if i[1] != 'u']) + ' '
114
115     def increase (self, (type, level)):
116         if level == 0:
117             self.__data = [[0,'u']]
118         while level + 1 < len (self.__data):
119             del self.__data[-1]
120         if level + 1 > len (self.__data):
121             self.__data.append ([0, type])
122             if type == 'l':
123                 self.__data[-1][0] = '@'
124         if type == self.__data[-1][1]:
125             self.__increase_last_index ()
126         else:
127             self.__data[-1] = ([0, type])
128             if type == 'l':
129                 self.__data[-1][0] = 'A'
130             elif type == 'n':
131                 self.__data[-1][0] = 1
132         return self.format ()
133
134
135 def percentage_color (percent):
136     p = percent / 100.0
137     if p < 0.33:
138         c = [hex (int (3 * p * b + (1 - 3 * p) * a))[2:]
139              for (a, b) in [(0xff, 0xff), (0x5c, 0xa6), (0x5c, 0x4c)]]
140     elif p < 0.67:
141         c = [hex (int ((3 * p - 1) * b + (2 - 3 * p) * a))[2:]
142              for (a, b) in [(0xff, 0xff), (0xa6, 0xff), (0x4c, 0x3d)]]
143     else:
144         c = [hex (int ((3 * p - 2) * b + 3 * (1 - p) * a))[2:]
145              for (a, b) in [(0xff, 0x1f), (0xff, 0xff), (0x3d, 0x1f)]]
146     return ''.join (c)
147
148
149 def update_word_count (text, filename, word_count):
150     return re.sub (r'(?m)^(\d+) *' + filename,
151                    str (word_count).ljust (6) + filename,
152                    text)
153
154 po_msgid_re = re.compile (r'^msgid "(.*?)"(?:\n"(.*?)")*', re.M)
155
156 def po_word_count (po_content):
157     s = ' '.join ([''.join (t) for t in po_msgid_re.findall (po_content)])
158     return len (space_re.split (s))
159
160 sgml_tag_re = re.compile (r'<.*?>', re.S)
161
162 def sgml_word_count (sgml_doc):
163     s = sgml_tag_re.sub ('', sgml_doc)
164     return len (space_re.split (s))
165
166 def tely_word_count (tely_doc):
167     '''
168     Calculate word count of a Texinfo document node by node.
169
170     Take string tely_doc as an argument.
171     Return a list of integers.
172
173     Texinfo comments and @lilypond blocks are not included in word counts.
174     '''
175     tely_doc = comments_re.sub ('', tely_doc)
176     tely_doc = lilypond_re.sub ('', tely_doc)
177     nodes = node_re.split (tely_doc)
178     return [len (space_re.split (n)) for n in nodes]
179
180 class TexiMarkup (object):
181     def entity (self, name, string='', attributes=[]):
182         return '''
183 @%(name)s
184 %(string)s
185 @end %(name)s
186 ''' % locals ()
187     def paragraph (self, string=''):
188         return '''
189 %(string)s''' % locals ()
190     def table (self, string):
191         return self.entity ('multitable', string)
192     def row (self, string, attributes=[]):
193         return '''
194 @item ''' + string
195     def cell (self, string, attributes=[]):
196         return '''
197 @tab ''' + string
198     def headcell (self, string, attributes=[]):
199 # @headitem...
200         return '''
201 @tab ''' + string
202     def newline (self):
203         return '''
204 @* '''
205     def span (self, string, attributes=[]):
206         return string
207     def small (self, string, attributes=[]):
208         return string
209
210 class HTMLMarkup (TexiMarkup):
211     def entity (self, name, string='', attributes=[]):
212         attr_list = ''.join ([' %s="%s"' % x for x in attributes])
213         return '<%(name)s%(attr_list)s>%(string)s</%(name)s>' % locals ()
214     def paragraph (self, string=''):
215         return self.entity ('p')
216     def table (self, string):
217         return self.entity ('table', string, [('align', 'center'), ('border', '2')])
218     def row (self, string, attributes=[]):
219         return self.entity ('tr', string, attributes)
220     def cellhead (self, string, attributes=[]):
221         return self.entity ('th', string, attributes)
222     def cell (self, string, attributes=[]):
223         return self.entity ('td', string, attributes)
224     def newline (self, attributes=[]):
225         return self.entity ('br', '', attributes)[:-5]
226     def span (self, string, attributes=[]):
227         return self.entity ('span', string, attributes)
228     def small (self, string, attributes=[]):
229         return self.entity ('small', string, attributes)
230
231 class TelyDocument (object):
232     def __init__ (self, filename):
233         self.filename = filename
234         self.contents = 'GIT committish: 0'
235         if os.path.exists (filename):
236             self.contents = open (filename).read ()
237         ## record title and sectionning level of first Texinfo section
238         self.sectioning = 'unnumbered'
239         self.title = 'Untitled'
240         m = title_re.search (self.contents)
241         if m:
242             self.sectioning = m.group (1)
243             self.title = m.group (2)
244
245         if not hasattr (self, 'language'):
246             self.language = ''
247         m = language_re.search (self.contents)
248         if m:
249             self.language = m.group (1)
250
251         dir = os.path.dirname (filename).split ('/')[0]
252         if len (dir) == 2:
253             dir += '/'
254         else:
255             dir = ''
256         included_files = [dir + t
257                           for t in include_re.findall (self.contents)]
258         self.included_files = [p for p in included_files if os.path.exists (p)]
259
260     def get_level (self):
261         return texi_level [self.sectioning]
262
263     def print_title (self, section_number):
264         if not hasattr (self, 'level'):
265             self.level = self.get_level ()
266         return section_number.increase (self.level) + self.title
267
268
269 class TranslatedTelyDocument (TelyDocument):
270     def __init__ (self, filename, masterdocument, parent_translation=None):
271         TelyDocument.__init__ (self, filename)
272         self.masterdocument = masterdocument
273         if not hasattr (self, 'language'):
274             self.language = ''
275         if not self.language and parent_translation:
276             self.language = parent_translation.__dict__.get ('language', '')
277         if self.language == 'en':
278             print filename + ': language en specified: set @documentlanguage', self.filename[:2]
279             self.language = ''
280         if not self.language and filename[2] == '/':
281             print filename + ': no language specified: add @documentlanguage', self.filename[:2]
282             self.language = filename[:2]
283         if self.language:
284             self.translation = translation[self.language]
285         else:
286             self.translation = lambda x: x
287         self.title = self.translation (self.title)
288
289         ## record authoring information
290         self.translators = ['']
291         if parent_translation:
292             self.translators = parent_translation.__dict__.get ('translators', [''])
293         m = translators_re.findall (self.contents)
294         if m:
295             self.translators = [n.strip () for n in
296                                 reduce (operator.add, [n.split (',') for n in m])]
297         if self.language != self.filename[:2]:
298             print 'Barf:', self.filename
299             barf
300         if (not isinstance (self, UntranslatedTelyDocument)
301             and (not self.translators or not self.translators[0])
302             and not 'macros.itexi' in self.filename):
303             error (self.filename + ''': error: no translator name found
304 please specify one ore more lines in the master file
305 @c Translator: FirstName LastName[, FirstName LastName]..''')
306         self.checkers = []
307         m = checkers_re.findall (self.contents)
308         if m:
309             self.checkers = [n.strip () for n in
310                              reduce (operator.add, [n.split (',') for n in m])]
311         if not self.checkers and isinstance (parent_translation, TranslatedTelyDocument):
312             self.checkers = parent_translation.checkers
313
314         ## check whether translation is pre- or post-GDP
315         m = status_re.search (self.contents)
316         if m:
317             self.post_gdp = bool (post_gdp_re.search (m.group (1)))
318         else:
319             self.post_gdp = False
320
321         ## record which parts (nodes) of the file are actually translated
322         self.partially_translated = not skeleton_str in self.contents
323         nodes = node_re.split (self.contents)
324         self.translated_nodes = [not untranslated_node_str in n for n in nodes]
325
326         ## calculate translation percentage
327         master_total_word_count = sum (masterdocument.word_count)
328         translation_word_count = \
329             sum ([masterdocument.word_count[k] * self.translated_nodes[k]
330                   for k in range (min (len (masterdocument.word_count),
331                                        len (self.translated_nodes)))])
332         self.translation_percentage = \
333             100 * translation_word_count / master_total_word_count
334
335         ## calculate how much the file is outdated
336         (diff_string, git_error) = \
337             buildlib.check_translated_doc (masterdocument.filename, self.filename, self.contents)
338         if git_error:
339             sys.stderr.write ('warning: %s: %s' % (self.filename, git_error))
340             self.uptodate_percentage = None
341         else:
342             diff = diff_string.splitlines ()
343             insertions = sum ([len (l) - 1 for l in diff
344                                if l.startswith ('+')
345                                and not l.startswith ('+++')])
346             deletions = sum ([len (l) - 1 for l in diff
347                               if l.startswith ('-')
348                               and not l.startswith ('---')])
349             outdateness_percentage = 50.0 * (deletions + insertions) / \
350                 (masterdocument.size + 0.5 * (deletions - insertions))
351             self.uptodate_percentage = 100 - int (outdateness_percentage)
352             if self.uptodate_percentage > 100:
353                 alternative = 50
354                 progress ("%s: strange uptodateness percentage %d %%, \
355 setting to %d %%" % (self.filename, self.uptodate_percentage, alternative))
356                 self.uptodate_percentage = alternative
357             elif self.uptodate_percentage < 1:
358                 alternative = 1
359                 progress ("%s: strange uptodateness percentage %d %%, \
360 setting to %d %%" % (self.filename, self.uptodate_percentage, alternative))
361                 self.uptodate_percentage = alternative
362
363     def get_level (self):
364         return texi_level ['top']
365
366     def completeness (self, formats=['long'], translated=False):
367         if translated:
368             translation = self.translation
369         else:
370             translation = lambda x: x
371
372         if isinstance (formats, str):
373             formats = [formats]
374         p = self.translation_percentage
375         if p == 0:
376             status = 'not translated'
377         elif p == 100:
378             status = 'fully translated'
379         else:
380             status = 'partially translated'
381         return dict ([(f, translation (format_table[status][f]) % locals())
382                       for f in formats])
383
384     def uptodateness (self, formats=['long'], translated=False):
385         if translated:
386             translation = self.translation
387         else:
388             translation = lambda x: x
389
390         if isinstance (formats, str):
391             formats = [formats]
392         p = self.uptodate_percentage
393         if p == None:
394             status = 'N/A'
395         elif p == 100:
396             status = 'up to date'
397         else:
398             status = 'outdated'
399         l = {}
400         for f in formats:
401             if f == 'color' and p != None:
402                 l['color'] = percentage_color (p)
403             else:
404                 l[f] = translation (format_table[status][f]) % locals ()
405         return l
406
407     def gdp_status (self):
408         if self.post_gdp:
409             return self.translation (format_table['post-GDP'])
410         else:
411             return self.translation (format_table['pre-GDP'])
412
413     def short_texi_status (self, markup):
414         s = ''
415         if self.partially_translated:
416             s += markup.newline ().join (self.translators + [''])
417             if self.checkers:
418                 s += markup.small (markup.newline ().join (self.checkers + ['']))
419         c = self.completeness (['color', 'long'])
420         s += markup.span ('%(long)s' % c, [('style', 'background-color: #%(color)s' % c)])
421         s += markup.newline ()
422         if self.partially_translated:
423             u = self.uptodateness (['vague', 'color'])
424             s += markup.span ('%(vague)s' % u, [('style', 'background-color: #%(color)s' % u)])
425         return markup.cell (s, [('title', filename)])
426
427     def text_status (self):
428         s = self.completeness ('abbr')['abbr'] + ' '
429
430         if self.partially_translated:
431             s += self.uptodateness ('abbr')['abbr'] + ' '
432         return s
433
434     def texi_status (self, markup, numbering=SectionNumber ()):
435         s =  '''<tr align="center">
436   <th>%s</th>''' % self.print_title (numbering)
437         s += ''.join (['  <th>%s</th>\n' % self.translation (h)
438                        for h in detailed_status_heads])
439         s += ' </tr>\n'
440         s += (' <tr align="left">\n  <td title="%%(filename)s">%s<br>(%d)</td>\n'
441               % (self.translation (section_titles_string),
442                  sum (self.masterdocument.word_count))) % self.__dict__
443         s += self.texi_body (markup, numbering)
444         return markup.table (s) + markup.paragraph ()
445
446     def texi_body (self, markup, numbering):
447         return (self.texi_translators (markup)
448                 + self.texi_completeness (markup)
449                 + self.texi_uptodateness (markup)
450                 + self.texi_gdp (markup)
451                 + self.texi_translations (markup, numbering))
452
453     def texi_translators (self, markup):
454         if self.partially_translated:
455             return ('  <td>' + '<br>\n   '.join (self.translators) + '</td>\n'
456                     + '  <td>' + '<br>\n   '.join (self.checkers) + '</td>\n')
457         return '  <td></td>\n' * 2
458
459     def texi_completeness (self, markup):
460         c = self.completeness (['color', 'short'], translated=True)
461         return '  <td><span style="background-color: #%(color)s">\
462 %(short)s</span></td>\n' % {'color': c['color'],
463                            'short': c['short']}
464
465     def texi_uptodateness (self, markup):
466         if self.partially_translated:
467             u = self.uptodateness (['short', 'color'], translated=True)
468             return '  <td><span style="background-color: #%(color)s">\
469 %(short)s</span></td>\n' % {'color': u['color'],
470                            'short': u['short']}
471         return '  <td></td>\n'
472
473     def texi_gdp (self, markup):
474         return '  <td>' + self.gdp_status () + '</td>\n </tr>\n'
475
476     def texi_translations (self, markup, numbering):
477         return ''.join ([i.translations[self.language].texi_status (markup, numbering)
478                          for i in self.masterdocument.includes
479                          if self.language in i.translations])
480
481 class IncludedTranslatedTelyDocument (TranslatedTelyDocument):
482     get_level = TelyDocument.get_level
483     def texi_status (self, markup, numbering=SectionNumber ()):
484         if self.title != 'Untitled':
485             return ((' <tr align="left">\n  <td title="%%(filename)s">%s<br>(%d)</td>\n'
486                      % (self.print_title (numbering),
487                         sum (self.masterdocument.word_count))) % self.__dict__
488                     + self.texi_body (markup, numbering))
489         return ''
490
491 class UntranslatedTelyDocument (TranslatedTelyDocument):
492     def __init__ (self, filename, masterdocument, parent_translation=None):
493         if filename[2] == '/':
494             self.language = filename[:2]
495         TranslatedTelyDocument.__init__ (self, filename, masterdocument, parent_translation)
496
497 class IncludedUntranslatedTelyDocument (UntranslatedTelyDocument, IncludedTranslatedTelyDocument):
498     get_level = TelyDocument.get_level
499
500 class MasterTelyDocument (TelyDocument):
501     def __init__ (self,
502                   filename,
503                   parent_translations=dict ([(lang, None)
504                                              for lang in langdefs.LANGDICT])):
505         TelyDocument.__init__ (self, filename)
506         self.size = len (self.contents)
507         self.word_count = tely_word_count (self.contents)
508         self.translations = {}
509         self.includes = []
510         if not self.language or self.language == 'en':
511             languages = [x for x in parent_translations.keys () if x != 'en']
512             self.translations = dict ([x for x in
513                                        [(lang, self.translated_factory (os.path.join (lang, self.filename),
514                                                                         parent_translations.get (lang)))
515                                         for lang in languages]
516                                        if x[1]])
517             if self.translations:
518                 self.includes = [IncludedMasterTelyDocument (f, self.translations)
519                                  for f in self.included_files]
520
521     def get_level (self):
522         return texi_level ['top']
523
524     def translated_factory (self, filename, parent):
525         if os.path.exists (filename):
526             return TranslatedTelyDocument (filename, self, parent)
527         return None
528
529     def update_word_counts (self, s):
530         s = update_word_count (s, self.filename, sum (self.word_count))
531         for i in self.includes:
532             s = i.update_word_counts (s)
533         return s
534
535     def texi_status (self, markup, numbering=SectionNumber ()):
536         s = '''
537  <tr align="center">
538   <th>%s</th>''' % self.print_title (numbering)
539         s += ''.join (['  <th>%s</th>\n' % l for l in sorted (self.translations.keys ())])
540         s += ' </tr>\n'
541         s += (' <tr align="left">\n  <td title="%%(filename)s">Section titles<br>(%d)</td>\n'
542               % sum (self.word_count)) % self.__dict__
543         s += self.texi_body (markup, numbering)
544         return markup.table (s) + markup.paragraph ()
545
546     def texi_body (self, markup, numbering):
547         return (''.join ([self.translations[k].short_texi_status (markup)
548                           for k in sorted (self.translations.keys ())])
549                 + ' </tr>\n'
550                 + ''.join ([i.texi_status (markup, numbering) for i in self.includes]))
551
552     def text_status (self, markup, numbering=SectionNumber (), colspec=[48,12]):
553         s = (self.print_title (numbering) + ' ').ljust (colspec[0])
554         s += ''.join (['%s'.ljust (colspec[1]) % l
555                        for l in sorted (self.translations.keys ())])
556         s += '\n'
557         s += ('Section titles (%d)' % \
558                   sum (self.word_count)).ljust (colspec[0])
559         s += self.text_body (markup, numbering, colspec)
560         s += '\n'
561         return s
562
563     def text_body (self, markup, numbering, colspec):
564         return (''.join ([self.translations[k].text_status ().ljust(colspec[1])
565                           for k in sorted (self.translations.keys ())])
566                 + '\n\n'
567                 + ''.join ([i.text_status (markup, numbering) for i in self.includes]))
568
569 class IncludedMasterTelyDocument (MasterTelyDocument):
570     get_level = TelyDocument.get_level
571
572     def translated_factory (self, filename, parent):
573         if os.path.exists (filename):
574             return IncludedTranslatedTelyDocument (filename, self, parent)
575         return IncludedUntranslatedTelyDocument (filename, self, parent)
576
577     def texi_status (self, markup, numbering=SectionNumber ()):
578         if self.title != 'Untitled':
579             return ((' <tr align="left">\n  <td title=%%(filename)s>%s<br>(%d)</td>\n'
580                      % (self.print_title (numbering), sum (self.word_count))) % self.__dict__
581                     + self.texi_body (markup, numbering))
582         return ''
583
584     def text_status (self, markup, numbering=SectionNumber (), colspec=[48,12]):
585         if self.title != 'Untitled':
586             return (('%s (%d) '
587                      % (self.print_title (numbering), sum (self.word_count)))
588                     + self.text_body (markup, numbering, colspec)
589                     ).ljust (colspec[0])
590         return ''
591
592
593 update_category_word_counts_re = re.compile (r'(?ms)^-(\d+)-(.*?\n)\d+ *total')
594
595 counts_re = re.compile (r'(?m)^(\d+) ')
596
597 def update_category_word_counts_sub (m):
598     return ('-' + m.group (1) + '-' + m.group (2)
599             + str (sum ([int (c)
600                          for c in counts_re.findall (m.group (2))])).ljust (6)
601             + 'total')
602
603 # urg 
604 # main () starts here-abouts
605
606 progress ("Reading documents...")
607
608 master_files = \
609     buildlib.read_pipe ("git ls-files | grep -E '[^/]*/?[^/]*[.](tely|texi)$'")[0].splitlines ()
610 master_files.sort ()
611 master_docs = [MasterTelyDocument (os.path.normpath (filename))
612                for filename in master_files]
613 master_docs = [doc for doc in master_docs if doc.translations]
614
615 enabled_languages = [l for l in langdefs.LANGDICT
616                      if langdefs.LANGDICT[l].enabled
617                      and l != 'en']
618
619 progress ("Generating status pages...")
620
621 date_time = buildlib.read_pipe ('LANG= date -u')[0]
622
623 markup = HTMLMarkup ()
624 #markup = TexiMarkup ()
625 main_status_body = last_updated_string % date_time
626 main_status_body += '\n'.join ([doc.texi_status (markup) for doc in master_docs])
627
628 texi_header = '''@c -*- coding: utf-8; mode: texinfo; -*-
629 @c This file was generated by translation-status.py -- DO NOT EDIT!
630 @ignore
631     Translation of GIT committish: 0
632 @end ignore
633
634 @ifnothtml
635 Translation status currently only available in HTML.
636 @end ifnothtml
637 @ifhtml
638 @html
639 '''
640
641 texi_footer = '''
642 @end html
643 @end ifhtml
644 '''
645
646 main_status_page = texi_header % locals () + main_status_body + texi_footer
647
648 open ('translations.itexi', 'w').write (main_status_page)
649
650 for l in enabled_languages:
651     date_time = buildlib.read_pipe ('LANG=%s date -u' % l)[0]
652     updated = translation[l] (last_updated_string) % date_time
653     texi_status = '\n'.join ([doc.translations[l].texi_status (markup)
654                               for doc in master_docs
655                               if l in doc.translations])
656     lang_status_page = texi_header + updated + texi_status + texi_footer
657     open (os.path.join (l, 'translations.itexi'), 'w').write (lang_status_page)
658
659 main_status_txt = '''Documentation translations status
660 Generated %s
661 NT = not translated
662 FT = fully translated
663
664 ''' % date_time
665
666 main_status_txt += '\n'.join ([doc.text_status (markup) for doc in master_docs])
667
668 status_txt_file = 'out/translations-status.txt'
669 progress ("Writing %s..." % status_txt_file)
670 open (status_txt_file, 'w').write (main_status_txt)
671
672 translation_instructions_file = 'contributor/doc-translation-list.itexi'
673 progress ("Updating %s..." % translation_instructions_file)
674 translation_instructions = open (translation_instructions_file).read ()
675
676 for doc in master_docs:
677     translation_instructions = doc.update_word_counts (translation_instructions)
678
679 for html_file in re.findall (r'(?m)^\d+ *(\S+?\.html\S*?)(?: |$)',
680                              translation_instructions):
681     word_count = sgml_word_count (open (html_file).read ())
682     translation_instructions = update_word_count (translation_instructions,
683                                                   html_file,
684                                                   word_count)
685
686 for po_file in re.findall (r'(?m)^\d+ *(\S+?\.po\S*?)(?: |$)',
687                            translation_instructions):
688     word_count = po_word_count (open (po_file).read ())
689     translation_instructions = update_word_count (translation_instructions,
690                                                   po_file,
691                                                   word_count)
692
693 translation_instructions = \
694     update_category_word_counts_re.sub (update_category_word_counts_sub,
695                                         translation_instructions)
696
697 open (translation_instructions_file, 'w').write (translation_instructions)
698 sys.exit (exit_code)