X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scripts%2Fauxiliar%2Ftranslations-status.py;h=221746360be79e305bf270fa13584f9fd1f6bf24;hb=ce43b953f70e2b7b36e11f3cb2bb0f179fc3b1a3;hp=84c6b0cefd3b607b6f3be0a80e433330894ba0a0;hpb=f522e027e9d1bd444821d0b519ef3fe81af1afce;p=lilypond.git diff --git a/scripts/auxiliar/translations-status.py b/scripts/auxiliar/translations-status.py index 84c6b0cefd..221746360b 100755 --- a/scripts/auxiliar/translations-status.py +++ b/scripts/auxiliar/translations-status.py @@ -10,6 +10,19 @@ USAGE: cd Documentation && translations-status.py 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 + + popups -- do we want that with texi output? -- how? + or possibly links to the git archive? + ''' import sys @@ -57,7 +70,7 @@ untranslated_node_str = '@untranslated' skeleton_str = '-- SKELETON FILE --' section_titles_string = _doc ('Section titles') -last_updated_string = _doc ('

Last updated %s

\n') +last_updated_string = _doc ('Last updated %s') detailed_status_heads = [_doc ('Translators'), _doc ('Translation checkers'), _doc ('Translated'), _doc ('Up to date'), _doc ('Other info')] @@ -177,27 +190,113 @@ def tely_word_count (tely_doc): nodes = node_re.split (tely_doc) return [len (space_re.split (n)) for n in nodes] -class TexiMarkup (object): +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' % locals () + def paragraph (self, string=''): + return self.entity ('p', string) + def table (self, string): + return self.entity ('table', string, [('align', 'center'), ('border', '2')]) + def row (self, string, attributes=[]): + return self.entity ('tr', string, attributes) + headrow = row + def headcell (self, string, attributes=[]): + return self.entity ('th', string, attributes) + def cell (self, string='', attributes=[]): + return self.entity ('td', string, attributes) + def newline (self, attributes=[]): + return self.entity ('br', '', attributes)[:-5] + def span (self, string, attributes=[]): + return self.entity ('span', string, attributes) + def small (self, string, attributes=[]): + return self.entity ('small', string, attributes) + def emph (self, string, attributes=[]): + return self.entity ('em', string, attributes) + +class TexiMarkup (HTMLMarkup): + def texi (self, string): + return (self.texi_header + + self.html (''' + +''') + + 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 %(string)s -@end %(name)s -''' % locals () +@end %(name)s''' % locals () def paragraph (self, string=''): return ''' %(string)s''' % locals () def table (self, string): - return self.entity ('multitable', string) - -class HTMLMarkup (TexiMarkup): - def entity (self, name, string='', attributes=[]): - attr_list = ''.join ([' %s="%s"' % x for x in attributes]) - return '<%(name)s%(attr_list)s>%(string)s' % locals () - def paragraph (self, string=''): - return self.entity ('p') - def table (self, string): - return self.entity ('table', string, [('align', 'center'), ('border', '2')]) + # Ugh, makeinfo is fine without @columnfractions + # but texi2html 1.82 barfs: `empty multicolumn' + return (self.entity ('multitable', string)) + def headrow (self, string, attributes=[]): + return ''' +@headitem ''' + string + def row (self, string, attributes=[]): + return ''' +@item ''' + string + def cell (self, string='', attributes=[]): + return ''' +@tab ''' + string + headcell = cell + def newline (self): + 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)) + + self.nothtml (string)) + def small (self, 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=[]): + return self.command ('emph', string) class TelyDocument (object): def __init__ (self, filename): @@ -272,8 +371,8 @@ class TranslatedTelyDocument (TelyDocument): 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: @@ -382,73 +481,68 @@ setting to %d %%" % (self.filename, self.uptodate_percentage, alternative)) return self.translation (format_table['pre-GDP']) def short_texi_status (self, markup): - s = ' ' % self.__dict__ + s = '' if self.partially_translated: - s += '
\n '.join (self.translators) + '
\n' + s += markup.newline ().join (self.translators + ['']) if self.checkers: - s += ' ' + \ - '
\n '.join (self.checkers) + '

\n' - + s += markup.newline ().join ([markup.small (x) for x in self.checkers + ['']]) c = self.completeness (['color', 'long']) - s += ' \ -%(long)s
\n' % c - + s += markup.span ('%(long)s' % c, [('style', 'background-color: #%(color)s' % c)]) + s += markup.newline () if self.partially_translated: u = self.uptodateness (['vague', 'color']) - s += ' \ -%(vague)s
\n' % u - - s += ' \n' - return s + s += markup.span ('%(vague)s' % u, [('style', 'background-color: #%(color)s' % u)]) + return markup.cell (s, [('title', filename)]) def text_status (self): s = self.completeness ('abbr')['abbr'] + ' ' - if self.partially_translated: s += self.uptodateness ('abbr')['abbr'] + ' ' return s def texi_status (self, markup, numbering=SectionNumber ()): - s = ''' - %s''' % self.print_title (numbering) - s += ''.join ([' %s\n' % self.translation (h) - for h in detailed_status_heads]) - s += ' \n' - s += (' \n %s
(%d)\n' - % (self.translation (section_titles_string), - sum (self.masterdocument.word_count))) % self.__dict__ - s += self.texi_body (markup, numbering) - return markup.table (s) + markup.paragraph () + return (markup.table ( + markup.headrow ( + (markup.headcell (self.print_title (numbering)) + + ''.join ([markup.headcell (self.translation (h)) + for h in detailed_status_heads])), + [('align', 'center')]) + + markup.row ( + (markup.cell ((self.translation (section_titles_string) + + markup.newline () + + '%d' % sum (self.masterdocument.word_count)), + [('title',filename)]) + + self.texi_body (markup, numbering)), + [('align','left')]) + + self.texi_translations (markup, numbering)) + ) + markup.paragraph () def texi_body (self, markup, numbering): return (self.texi_translators (markup) + self.texi_completeness (markup) + self.texi_uptodateness (markup) - + self.texi_gdp (markup) - + self.texi_translations (markup, numbering)) + + self.texi_gdp (markup)) def texi_translators (self, markup): if self.partially_translated: - return (' ' + '
\n '.join (self.translators) + '\n' - + ' ' + '
\n '.join (self.checkers) + '\n') - return ' \n' * 2 + return (markup.cell (markup.newline ().join (self.translators)) + + markup.cell (markup.newline ().join (self.checkers))) + return markup.cell () + markup.cell () def texi_completeness (self, markup): c = self.completeness (['color', 'short'], translated=True) - return ' \ -%(short)s\n' % {'color': c['color'], - 'short': c['short']} + return markup.cell (markup.span (c['short'], + [('style', 'background-color: #' + c['color'])])) def texi_uptodateness (self, markup): if self.partially_translated: u = self.uptodateness (['short', 'color'], translated=True) - return ' \ -%(short)s\n' % {'color': u['color'], - 'short': u['short']} - return ' \n' + return markup.cell (markup.span (u['short'], + [('style', 'background-color: #' + u['color'])])) + return markup.cell () def texi_gdp (self, markup): - return ' ' + self.gdp_status () + '\n \n' + return markup.cell (self.gdp_status ()) def texi_translations (self, markup, numbering): return ''.join ([i.translations[self.language].texi_status (markup, numbering) @@ -459,10 +553,15 @@ class IncludedTranslatedTelyDocument (TranslatedTelyDocument): get_level = TelyDocument.get_level def texi_status (self, markup, numbering=SectionNumber ()): if self.title != 'Untitled': - return ((' \n %s
(%d)\n' - % (self.print_title (numbering), - sum (self.masterdocument.word_count))) % self.__dict__ - + self.texi_body (markup, numbering)) + return (markup.row ( + (markup.cell (( + self.print_title (numbering) + + markup.newline () + + '%d' % sum (self.masterdocument.word_count)), + [('title',filename)]) + + self.texi_body (markup, numbering)), + [('align','left')]) + + self.texi_translations (markup, numbering)) return '' class UntranslatedTelyDocument (TranslatedTelyDocument): @@ -510,21 +609,27 @@ class MasterTelyDocument (TelyDocument): return s def texi_status (self, markup, numbering=SectionNumber ()): - s = ''' - - %s''' % self.print_title (numbering) - s += ''.join ([' %s\n' % l for l in sorted (self.translations.keys ())]) - s += ' \n' - s += (' \n Section titles
(%d)\n' - % sum (self.word_count)) % self.__dict__ - s += self.texi_body (markup, numbering) - return markup.table (s) + markup.paragraph () + return markup.table ( + (markup.headrow ( + (markup.headcell (self.print_title (numbering)) + + ''.join ([markup.headcell (l) for l in sorted (self.translations.keys ())])), + [('align','center')]) + + markup.row ( + (markup.cell (('Section titles' + + markup.newline () + + '(%d)' % sum (self.word_count)), + [('title',filename)]) + + self.texi_body (markup, numbering)), + [('align','left')]) + + self.texi_includes (markup, numbering) + )) + markup.paragraph () + + def texi_includes (self, markup, numbering): + return ''.join ([i.texi_status (markup, numbering) for i in self.includes]) def texi_body (self, markup, numbering): - return (''.join ([self.translations[k].short_texi_status (markup) + return ''.join ([self.translations[k].short_texi_status (markup) for k in sorted (self.translations.keys ())]) - + ' \n' - + ''.join ([i.texi_status (markup, numbering) for i in self.includes])) def text_status (self, markup, numbering=SectionNumber (), colspec=[48,12]): s = (self.print_title (numbering) + ' ').ljust (colspec[0]) @@ -553,16 +658,21 @@ class IncludedMasterTelyDocument (MasterTelyDocument): def texi_status (self, markup, numbering=SectionNumber ()): if self.title != 'Untitled': - return ((' \n %s
(%d)\n' - % (self.print_title (numbering), sum (self.word_count))) % self.__dict__ - + self.texi_body (markup, numbering)) + return (markup.row ( + (markup.cell ((self.print_title (numbering) + + markup.newline () + + '(%d)' % sum (self.word_count)), + [('title',filename)]) + + self.texi_body (markup, numbering)), + [('align','left')]) + + self.texi_includes (markup, numbering)) return '' def text_status (self, markup, numbering=SectionNumber (), colspec=[48,12]): if self.title != 'Untitled': - return (('%s (%d) ' - % (self.print_title (numbering), sum (self.word_count))) - + self.text_body (markup, numbering, colspec) + return (self.print_title (numbering) + + '(%d)' % sum (self.word_count) + + self.text_body (markup, numbering, colspec) ).ljust (colspec[0]) return '' @@ -597,40 +707,28 @@ progress ("Generating status pages...") date_time = buildlib.read_pipe ('LANG= date -u')[0] -markup = HTMLMarkup () -#markup = TexiMarkup () -main_status_body = 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 +# TEXI output sort of works +# TODO: table border, td-titles :-) +# 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''') -@ifnothtml -Translation status currently only available in HTML. -@end ifnothtml -@ifhtml -@html -''' - -texi_footer = ''' -@end html -@end ifhtml -''' - -main_status_page = texi_header % locals () + main_status_body + texi_footer +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]) +main_status_page = markup.texi (main_status_body) open ('translations.itexi', 'w').write (main_status_page) for l in enabled_languages: date_time = buildlib.read_pipe ('LANG=%s date -u' % l)[0] - updated = translation[l] (last_updated_string) % date_time + updated = markup.paragraph (markup.emph (translation[l] (last_updated_string) % date_time)) 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