'''
USAGE: cd Documentation && translations-status.py
-TODO:
- * layout tweaks for TexiMarkup
- - set html table border
- - collapse first column
- * switch to using TexiMarkup (see #markup = ..)
-
Write:
translations.itexi
<LANG>/translations.itexi
Update word counts in:
contributor/doc-translation-list.itexi
+
+TODO:
+ * using markup = TexiMarkup (), html tables (columns)
+ are evenly spaced and bit too wide. This can
+ be fixed by using
+ @multitable @columnfractions 0 0 0 0 0 0 0 0,
+ but with that, PDF and info output get borked.
+ * in info and PDF, columns have too little separation
+ * using markup = HTMLMarkup (), we get nice
+ <td title="FILENAME">
+ popups -- do we want that with texi output? -- how?
+ or possibly links to the git archive?
+
'''
import sys
return [len (space_re.split (n)) for n in nodes]
class HTMLMarkup (object):
+ texi_header = '''@c -*- coding: utf-8; mode: texinfo; -*-
+@c This file was generated by translation-status.py -- DO NOT EDIT!
+@ignore
+ Translation of GIT committish: 0
+@end ignore
+
+'''
+ texi_footer = '''
+'''
+ def texi (self, string):
+ return (self.texi_header
+ + '''
+@ifnothtml
+Translation status currently only available in HTML.
+@end ifnothtml
+'''
+ + string
+ + self.texi_footer)
def entity (self, name, string='', attributes=[]):
attr_list = ''.join ([' %s="%s"' % x for x in attributes])
return '<%(name)s%(attr_list)s>%(string)s</%(name)s>' % locals ()
return self.entity ('em', string, attributes)
class TexiMarkup (HTMLMarkup):
+ def texi (self, string):
+ return (self.texi_header
+ + self.html ('''
+<style type="text/css"><!--
+th { border: 1px solid black; text-align: center; }
+td { border: 1px solid black; text-align: center; }
+!--></style>
+''')
+ + self.columnfraction_disaster (self.itemtab_disaster (string))
+ + self.texi_footer)
+ def itemtab_disaster (self, string):
+ return string.replace ('''item \n@tab ''', '''item
+''')
+ def columnfraction_disaster (self, string):
+ if False:
+ # nice trick for html-only
+ return string.replace ('@multitable', '@multitable @columnfractions 0 0 0 0 0 0 0 0 0 0')
+ tables = re.findall ('(?s)(@multitable)(.*?)(@item)', string)
+ for t in tables:
+ columns = len (re.findall ('(?s)(\n@tab)', t[1])) + 1
+ columnfractions = '@columnfractions ' + (' ' + str (1.0/columns)) * columns
+ string = string.replace ('@multitable\n',
+ '@multitable %(columnfractions)s\n' % locals (), 1)
+ return string
def entity (self, name, string='', attributes=[]):
return '''
@%(name)s
def table (self, string):
# Ugh, makeinfo is fine without @columnfractions
# but texi2html 1.82 barfs: `empty multicolumn'
- return (self.entity ('multitable', string)
- .replace ('@multitable',
- '@multitable @columnfractions' + ' .1' * 10))
+ return (self.entity ('multitable', string))
def headrow (self, string, attributes=[]):
return '''
@headitem ''' + string
@tab ''' + string
headcell = cell
def newline (self):
- return ''' @*
+ return '''
+@*
'''
def html (self, string):
return self.entity ('ifhtml', self.entity ('html', string))
+ def nothtml (self, string):
+ return self.entity ('ifnothtml', string)
def span (self, string, attributes=[]):
- return self.html (HTMLMarkup ().span (string, attributes))
+ return (self.html (HTMLMarkup ().span (string, attributes))
+ + self.nothtml (string))
def small (self, string, attributes=[]):
- return self.html (HTMLMarkup ().small (string, attributes))
+ return (self.html (HTMLMarkup ().small (string, attributes))
+ + self.nothtml (string))
def command (self, name, string):
return '@%(name)s{%(string)s}' % locals ()
def emph (self, string, attributes=[]):
and (not self.translators or not self.translators[0])
and not 'macros.itexi' in self.filename):
error (self.filename + ''': error: no translator name found
-please specify one ore more lines in the master file
-@c Translator: FirstName LastName[, FirstName LastName]..''')
+ please specify one ore more lines in the master file
+ @c Translator: FirstName LastName[, FirstName LastName]..''')
self.checkers = []
m = checkers_re.findall (self.contents)
if m:
# TEXI output sort of works
# TODO: table border, td-titles :-)
-#markup = HTMLMarkup ()
+# markup = HTMLMarkup ()
+#sys.stderr.write ('''translations-status.py:713: warning: using markup = HTMLMarkup (): HTML only\n''')
markup = TexiMarkup ()
+sys.stderr.write ('''translations-status.py:717: warning: using markup = TexiMarkup (): ugly HTML
+ output, questionable PDF and info output.
+ Consider using HTML-only markup = HTMLMarkup ()\n''')
main_status_body = markup.paragraph (markup.emph (last_updated_string % date_time))
main_status_body += '\n'.join ([doc.texi_status (markup) for doc in master_docs])
-
-texi_header = '''@c -*- coding: utf-8; mode: texinfo; -*-
-@c This file was generated by translation-status.py -- DO NOT EDIT!
-@ignore
- Translation of GIT committish: 0
-@end ignore
-
-'''
-
-if not isinstance (markup, TexiMarkup):
- texi_header += '''
-@ifnothtml
-Translation status currently only available in HTML.
-@end ifnothtml
-@ifhtml
-@html
-'''
-
-texi_footer = '''
-'''
-
-if not isinstance (markup, TexiMarkup):
- texi_footer += '''
-@end html
-@end ifhtml
-'''
-
-main_status_page = texi_header % locals () + main_status_body + texi_footer
+main_status_page = markup.texi (main_status_body)
open ('translations.itexi', 'w').write (main_status_page)
texi_status = '\n'.join ([doc.translations[l].texi_status (markup)
for doc in master_docs
if l in doc.translations])
- lang_status_page = texi_header + updated + texi_status + texi_footer
+ lang_status_page = markup.texi (updated + texi_status)
open (os.path.join (l, 'translations.itexi'), 'w').write (lang_status_page)
main_status_txt = '''Documentation translations status