]> git.donarmstrong.com Git - lilypond.git/blobdiff - buildscripts/translations-status.py
Merge branch 'lilypond/translation' of ssh://jomand@git.sv.gnu.org/srv/git/lilypond
[lilypond.git] / buildscripts / translations-status.py
old mode 100755 (executable)
new mode 100644 (file)
index de688b8..c931993
@@ -17,26 +17,22 @@ import sys
 import re
 import string
 import os
-import gettext
 
 import langdefs
+import buildlib
 
 def progress (str):
     sys.stderr.write (str + '\n')
 
 progress ("translations-status.py")
 
-buildscript_dir = sys.argv[1]
-
 _doc = lambda s: s
 
-sys.path.append (buildscript_dir)
-import buildlib
-
 # load gettext messages catalogs
 translation = langdefs.translation
 
 
+language_re = re.compile (r'^@documentlanguage (.+)', re.M)
 comments_re = re.compile (r'^@ignore\n(.|\n)*?\n@end ignore$|@c .*?$', re.M)
 space_re = re.compile (r'\s+', re.M)
 lilypond_re = re.compile (r'@lilypond({.*?}|(.|\n)*?\n@end lilypond$)', re.M)
@@ -50,9 +46,14 @@ checkers_re = re.compile (r'^@c\s+Translation\s*checkers\s*:\s*(.*?)$',
                           re.M | re.I)
 status_re = re.compile (r'^@c\s+Translation\s*status\s*:\s*(.*?)$', re.M | re.I)
 post_gdp_re = re.compile ('post.GDP', re.I)
-untranslated_node_str = 'UNTRANSLATED NODE: IGNORE ME'
+untranslated_node_str = '@untranslated'
 skeleton_str = '-- SKELETON FILE --'
 
+section_titles_string = _doc ('Section titles')
+last_updated_string = _doc (' <p><i>Last updated %s</i></p>\n')
+detailed_status_heads = [_doc ('Translators'), _doc ('Translation checkers'),
+                         _doc ('Translated'), _doc ('Up to date'),
+                         _doc ('Other info')]
 format_table = {
     'not translated': {'color':'d0f0f8', 'short':_doc ('no'), 'abbr':'NT',
                        'long':_doc ('not translated')},
@@ -64,7 +65,7 @@ format_table = {
                          'long': _doc ('translated')},
     'up to date': {'short':_doc ('yes'), 'long':_doc ('up to date'),
                    'abbr':'100%%', 'vague':_doc ('up to date')},
-    'outdated': {'short':_doc ('partially (%(p)d %%)'), 'abbr':'%(p)d%%',
+    'outdated': {'short':_doc ('partially'), 'abbr':'%(p)d%%',
                  'vague':_doc ('partially up to date')},
     'N/A': {'short':_doc ('N/A'), 'abbr':'N/A', 'color':'d587ff', 'vague':''},
     'pre-GDP':_doc ('pre-GDP'),
@@ -183,6 +184,10 @@ class TelyDocument (object):
             self.title = 'Untitled'
             self.level = ('u', 1)
 
+        m = language_re.search (self.contents)
+        if m:
+            self.language = m.group (1)
+
         included_files = [os.path.join (os.path.dirname (filename), t)
                           for t in include_re.findall (self.contents)]
         self.included_files = [p for p in included_files if os.path.exists (p)]
@@ -196,6 +201,14 @@ class TranslatedTelyDocument (TelyDocument):
         TelyDocument.__init__ (self, filename)
 
         self.masterdocument = masterdocument
+        if not hasattr (self, 'language') \
+                and hasattr (parent_translation, 'language'):
+            self.language = parent_translation.language
+        if hasattr (self, 'language'):
+            self.translation = translation[self.language]
+        else:
+            self.translation = lambda x: x
+        self.title = self.translation (self.title)
 
         ## record authoring information
         m = translators_re.search (self.contents)
@@ -234,7 +247,7 @@ class TranslatedTelyDocument (TelyDocument):
 
         ## calculate how much the file is outdated
         (diff_string, error) = \
-            buildlib.check_translated_doc (masterdocument.filename, self.contents)
+            buildlib.check_translated_doc (masterdocument.filename, self.filename, self.contents)
         if error:
             sys.stderr.write ('warning: %s: %s' % (self.filename, error))
             self.uptodate_percentage = None
@@ -260,7 +273,12 @@ setting to %d %%" % (self.filename, self.uptodate_percentage, alternative))
 setting to %d %%" % (self.filename, self.uptodate_percentage, alternative))
                 self.uptodate_percentage = alternative
 
-    def completeness (self, formats=['long']):
+    def completeness (self, formats=['long'], translated=False):
+        if translated:
+            translation = self.translation
+        else:
+            translation = lambda x: x
+
         if isinstance (formats, str):
             formats = [formats]
         p = self.translation_percentage
@@ -270,9 +288,15 @@ setting to %d %%" % (self.filename, self.uptodate_percentage, alternative))
             status = 'fully translated'
         else:
             status = 'partially translated'
-        return dict ([(f, format_table[status][f] % locals()) for f in formats])
+        return dict ([(f, translation (format_table[status][f]) % locals())
+                      for f in formats])
+
+    def uptodateness (self, formats=['long'], translated=False):
+        if translated:
+            translation = self.translation
+        else:
+            translation = lambda x: x
 
-    def uptodateness (self, formats=['long']):
         if isinstance (formats, str):
             formats = [formats]
         p = self.uptodate_percentage
@@ -287,14 +311,14 @@ setting to %d %%" % (self.filename, self.uptodate_percentage, alternative))
             if f == 'color' and p != None:
                 l['color'] = percentage_color (p)
             else:
-                l[f] = format_table[status][f] % locals ()
+                l[f] = translation (format_table[status][f]) % locals ()
         return l
 
-    def gdp_status (self, translation=lambda s: s):
+    def gdp_status (self):
         if self.post_gdp:
-            return translation (format-table['post-GDP'])
+            return self.translation (format_table['post-GDP'])
         else:
-            return translation (format-table['pre-GDP'])
+            return self.translation (format_table['pre-GDP'])
 
     def short_html_status (self):
         s = '  <td>'
@@ -323,9 +347,53 @@ setting to %d %%" % (self.filename, self.uptodate_percentage, alternative))
             s += self.uptodateness ('abbr')['abbr'] + ' '
         return s
 
-    def html_status (self):
-        # TODO
-        return ''
+    def html_status (self, numbering=SectionNumber ()):
+        if self.title == 'Untitled':
+            return ''
+
+        if self.level[1] == 0: # if self is a master document
+            s = '''<table align="center" border="2">
+ <tr align="center">
+  <th>%s</th>''' % self.print_title (numbering)
+            s += ''.join (['  <th>%s</th>\n' % self.translation (h)
+                           for h in detailed_status_heads])
+            s += ' </tr>\n'
+            s += ' <tr align="left">\n  <td>%s<br>(%d)</td>\n' \
+                % (self.translation (section_titles_string),
+                   sum (self.masterdocument.word_count))
+
+        else:
+            s = ' <tr align="left">\n  <td>%s<br>(%d)</td>\n' \
+                % (self.print_title (numbering),
+                   sum (self.masterdocument.word_count))
+
+        if self.partially_translated:
+            s += '  <td>' + '<br>\n   '.join (self.translators) + '</td>\n'
+            s += '  <td>' + '<br>\n   '.join (self.checkers) + '</td>\n'
+        else:
+            s += '  <td></td>\n' * 2
+
+        c = self.completeness (['color', 'short'], translated=True)
+        s += '  <td><span style="background-color: #%(color)s">\
+%(short)s</span></td>\n' % {'color': c['color'],
+                           'short': c['short']}
+
+        if self.partially_translated:
+            u = self.uptodateness (['short', 'color'], translated=True)
+            s += '  <td><span style="background-color: #%(color)s">\
+%(short)s</span></td>\n' % {'color': u['color'],
+                           'short': u['short']}
+        else:
+            s += '  <td></td>\n'
+
+        s += '  <td>' + self.gdp_status () + '</td>\n </tr>\n'
+        s += ''.join ([i.translations[self.language].html_status (numbering)
+                       for i in self.masterdocument.includes
+                       if self.language in i.translations])
+
+        if self.level[1] == 0:  # if self is a master document
+            s += '</table>\n<p></p>\n'
+        return s
 
 class MasterTelyDocument (TelyDocument):
     def __init__ (self,
@@ -367,7 +435,7 @@ class MasterTelyDocument (TelyDocument):
             s += ' <tr align="left">\n  <td>Section titles<br>(%d)</td>\n' \
                 % sum (self.word_count)
 
-        else:
+        else:  # if self is an included file
             s = ' <tr align="left">\n  <td>%s<br>(%d)</td>\n' \
                 % (self.print_title (numbering), sum (self.word_count))
 
@@ -376,7 +444,7 @@ class MasterTelyDocument (TelyDocument):
         s += ' </tr>\n'
         s += ''.join ([i.html_status (numbering) for i in self.includes])
 
-        if self.level[1] == 0:
+        if self.level[1] == 0:  # if self is a master document
             s += '</table>\n<p></p>\n'
         return s
 
@@ -423,37 +491,52 @@ progress ("Reading documents...")
 
 tely_files = \
     buildlib.read_pipe ("find -maxdepth 2 -name '*.tely'")[0].splitlines ()
+tely_files.sort ()
 master_docs = [MasterTelyDocument (os.path.normpath (filename))
                for filename in tely_files]
 master_docs = [doc for doc in master_docs if doc.translations]
 
 main_status_page = open ('translations.template.html.in').read ()
 
-## TODO
-#per_lang_status_pages = \
-#    dict ([(l, open (os.path.join (l, 'translations.template.html')). read ())
-#           for l in langdefs.LANGDICT
-#           if langdefs.LANGDICT[l].enabled])
+enabled_languages = [l for l in langdefs.LANGDICT
+                     if langdefs.LANGDICT[l].enabled
+                     and l != 'en']
+lang_status_pages = \
+    dict ([(l, open (os.path.join (l, 'translations.template.html.in')). read ())
+           for l in enabled_languages])
 
 progress ("Generating status pages...")
 
 date_time = buildlib.read_pipe ('LANG= date -u')[0]
 
-main_status_html = ' <p><i>Last updated %s</i></p>\n' % date_time
+main_status_html = last_updated_string % date_time
 main_status_html += '\n'.join ([doc.html_status () for doc in master_docs])
 
 html_re = re.compile ('<html>', re.I)
 end_body_re = re.compile ('</body>', re.I)
 
-main_status_page = html_re.sub ('''<html>
+html_header = '''<html>
 <!-- This page is automatically generated by translation-status.py from
-translations.template.html.in; DO NOT EDIT !-->''', main_status_page)
+translations.template.html.in; DO NOT EDIT !-->'''
+
+main_status_page = html_re.sub (html_header, main_status_page)
 
 main_status_page = end_body_re.sub (main_status_html + '\n</body>',
                                     main_status_page)
 
 open ('translations.html.in', 'w').write (main_status_page)
 
+for l in enabled_languages:
+    date_time = buildlib.read_pipe ('LANG=%s date -u' % l)[0]
+    lang_status_pages[l] = translation[l] (last_updated_string) % date_time + lang_status_pages[l]
+    lang_status_page = html_re.sub (html_header, lang_status_pages[l])
+    html_status = '\n'.join ([doc.translations[l].html_status ()
+                              for doc in master_docs
+                              if l in doc.translations])
+    lang_status_page = end_body_re.sub (html_status + '\n</body>',
+                                        lang_status_page)
+    open (os.path.join (l, 'translations.html.in'), 'w').write (lang_status_page)
+
 main_status_txt = '''Documentation translations status
 Generated %s
 NT = not translated