X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scripts%2Fauxiliar%2Ftranslations-status.py;h=221746360be79e305bf270fa13584f9fd1f6bf24;hb=HEAD;hp=c17e9532f7d98afc5c8440723a3d3eb002fee5a9;hpb=00322ca2a6ce40fa689ae65be0e6f8c8267e26ad;p=lilypond.git diff --git a/scripts/auxiliar/translations-status.py b/scripts/auxiliar/translations-status.py index c17e9532f7..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 +
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')] @@ -179,39 +190,155 @@ def tely_word_count (tely_doc): nodes = node_re.split (tely_doc) 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 () + 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 () + def paragraph (self, string=''): + return ''' +%(string)s''' % locals () + def table (self, string): + # 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): self.filename = filename - self.contents = open (filename).read () - self.top = os.path.splitext (filename)[1] in ['.tely', '.texi'] + self.contents = 'GIT committish: 0' + if os.path.exists (filename): + self.contents = open (filename).read () ## record title and sectionning level of first Texinfo section self.sectioning = 'unnumbered' self.title = 'Untitled' m = title_re.search (self.contents) if m: self.sectioning = m.group (1) - if self.sectioning == 'top': - self.sectioning = 'unnumbered' self.title = m.group (2) - self.level = texi_level [self.sectioning] + if not hasattr (self, 'language'): + self.language = '' m = language_re.search (self.contents) if m: self.language = m.group (1) - included_files = [os.path.join (os.path.dirname (filename), t) + dir = os.path.dirname (filename).split ('/')[0] + if len (dir) == 2: + dir += '/' + else: + dir = '' + included_files = [dir + t for t in include_re.findall (self.contents)] self.included_files = [p for p in included_files if os.path.exists (p)] + def get_level (self): + return texi_level [self.sectioning] + def print_title (self, section_number): + if not hasattr (self, 'level'): + self.level = self.get_level () return section_number.increase (self.level) + self.title class TranslatedTelyDocument (TelyDocument): def __init__ (self, filename, masterdocument, parent_translation=None): TelyDocument.__init__ (self, filename) - self.masterdocument = masterdocument if not hasattr (self, 'language'): self.language = '' @@ -230,18 +357,22 @@ class TranslatedTelyDocument (TelyDocument): self.title = self.translation (self.title) ## record authoring information - self.translators = [] + self.translators = [''] if parent_translation: - self.translators = parent_translation.__dict__.get ('translators', []) + self.translators = parent_translation.__dict__.get ('translators', ['']) m = translators_re.findall (self.contents) if m: self.translators = [n.strip () for n in reduce (operator.add, [n.split (',') for n in m])] - if (not self.translators + if self.language != self.filename[:2]: + print 'Barf:', self.filename + barf + if (not isinstance (self, UntranslatedTelyDocument) + and (not self.translators or not self.translators[0]) and not 'macros.itexi' in self.filename): - error ('%s: no translator name found, \nplease \ -specify at least one in the master file as a line containing\n\ -@c Translators: FirstName1 LastName1, FirstName2 LastName2' % 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]..''') self.checkers = [] m = checkers_re.findall (self.contents) if m: @@ -299,6 +430,9 @@ setting to %d %%" % (self.filename, self.uptodate_percentage, alternative)) setting to %d %%" % (self.filename, self.uptodate_percentage, alternative)) self.uptodate_percentage = alternative + def get_level (self): + return texi_level ['top'] + def completeness (self, formats=['long'], translated=False): if translated: translation = self.translation @@ -346,85 +480,98 @@ setting to %d %%" % (self.filename, self.uptodate_percentage, alternative)) else: return self.translation (format_table['pre-GDP']) - def short_texi_status (self): - s = '%s | ''' % self.print_title (numbering) - s += ''.join (['%s | \n' % self.translation (h) - for h in detailed_status_heads]) - s += '||||||
---|---|---|---|---|---|---|---|
%s (%d) | \n' \
- % (self.translation (section_titles_string),
- sum (self.masterdocument.word_count))
-
- else:
- s = ''' ''' % self.__dict__
- s += ' |||||||
%s (%d) | \n' \
- % (self.print_title (numbering),
- sum (self.masterdocument.word_count))
-
+ def texi_status (self, markup, numbering=SectionNumber ()):
+ 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))
+
+ def texi_translators (self, markup):
if self.partially_translated:
- s += ' ' + ' \n '.join (self.translators) + ' | \n'
- s += ' ' + ' \n '.join (self.checkers) + ' | \n'
- else:
- s += ' \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) - s += ' | \ -%(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) - s += '\ -%(short)s | \n' % {'color': u['color'], - 'short': u['short']} - else: - s += '\n' - - s += ' | ' + self.gdp_status () + ' | \n
%s | ''' % self.print_title (numbering) - s += ''.join (['%s | \n' % l for l in self.translations]) - s += '
---|---|
Section titles (%d) | \n' \
- % sum (self.word_count)
-
- else: # if self is an included file
- s = ''' ''' % self.__dict__
- s += ' |
%s (%d) | \n' \
- % (self.print_title (numbering), sum (self.word_count))
-
- s += ''.join ([t.short_texi_status ()
- for t in self.translations.values ()])
- s += '