]> git.donarmstrong.com Git - lilypond.git/commitdiff
Add support for texidocs in check-translation
authorJohn Mandereau <john.mandereau@gmail.com>
Fri, 22 May 2009 16:42:38 +0000 (18:42 +0200)
committerPatrick McCarty <pnorcks@gmail.com>
Fri, 17 Jul 2009 09:34:05 +0000 (02:34 -0700)
Also add a hack to update committishes in texdidocs, this should
be used with extreme care.
(cherry picked from commit cdcabcde8a1d7e476379b130166becb1abaa3f97)

Documentation/GNUmakefile
scripts/auxiliar/check_translation.py

index eaed920a9a025ce665f58a1bd326b0197305e2f0..03a6a8a909d29e6f40b3ad59dac6e7ca90bbea8c 100644 (file)
@@ -66,7 +66,8 @@ new-lang:
        cp po/lilypond-doc.pot po/$(ISOLANG).po
        @echo "***  Please add a language definition for $(ISOLANG) in python/langdefs.py  ***"
 
-CHECKED_FILES = $(ISOLANG)/index.html.in $(shell find $(ISOLANG)/user/ -maxdepth 1 -name '*.*te??')
+CHECKED_FILES = $(ISOLANG)/index.html.in $(shell find $(ISOLANG)/user/ -maxdepth 1 -name '*.*te??') \
+  $(shell find $(depth)/input/texidocs/ -name '*.texidoc')
 
 TELY_FILES = $(call src-wildcard,$(ISOLANG)/user/*.tely)
 skeleton-update:
@@ -100,10 +101,10 @@ fix-xrefs:
        $(DOCUMENTS_INCLUDES) $(auxpython-dir)/manuals_definitions.py
 
 check-translation:
-       $(auxscript-dir)/check_translation.py $(CHECK_TRANSLATION_FLAGS) $(CHECKED_FILES)
+       ISOLANG=$(ISOLANG) $(auxscript-dir)/check_translation.py $(CHECK_TRANSLATION_FLAGS) $(CHECKED_FILES)
 
 update-translation:
-       $(auxscript-dir)/check_translation.py --update $(CHECK_TRANSLATION_FLAGS) $(CHECKED_FILES)
+       ISOLANG=$(ISOLANG) $(auxscript-dir)/check_translation.py --update $(CHECK_TRANSLATION_FLAGS) $(CHECKED_FILES)
 
 translation-status:
        make -C po out=www messages
index 090b1fbe8a73811af2dd98c0d2c74f2078ca6aa3..ef2decd0d79d11562e7fce27f3911b668f2ba75a 100755 (executable)
@@ -4,6 +4,7 @@ import __main__
 import optparse
 import os
 import sys
+import re
 
 import langdefs
 import buildlib
@@ -18,7 +19,16 @@ def dir_lang (file, lang, lang_dir_index):
     path_components[lang_dir_index] = lang
     return os.path.join (*path_components)
 
-def do_file (file_name, lang_codes, buildlib):
+vc_last_revision = 'git log --pretty=format:%%H %(file_name)s | head -1'
+vc_last_texidoc_revision = 'git log -Stexidoc%(preferred_language)s --pretty=format:%%H %(file_name)s | head -1'
+
+s = 'Translation of GIT [Cc]ommittish'
+texidoc_chunk_re = re.compile (r'^((?:%+\s*' + s + \
+    r'.+)?\s*(?:texidoc|doctitle)([a-zA-Z]{2,4})\s+=(?:.|\n)*?)(?=%+\s*' + \
+    s + r'|\s*(?:texidoc|doctitle)(?:[a-zA-Z]{2,4})\s+=|$(?!.|\n))', re.M)
+
+
+def do_file (file_name, lang_codes):
     if verbose:
         sys.stderr.write ('%s...\n' % file_name)
     split_file_name = file_name.split ('/')
@@ -32,10 +42,46 @@ def do_file (file_name, lang_codes, buildlib):
     else:
         check_lang = lang
     if check_lang == C:
-        raise Exception ('cannot determine language for ' + file_name)
-    
-    original = dir_lang (file_name, '', lang_dir_index)
-    translated_contents = open (file_name).read ()
+        if not os.path.splitext (file_name)[1] == '.texidoc':
+            raise Exception ('cannot determine language for ' + file_name)
+        translated_contents = open (file_name).read ()
+        if 'ISOLANG' in os.environ:
+            preferred_language = os.environ['ISOLANG']
+        else:
+            raise Exception ('cannot determine language for ' + file_name)
+        for m in texidoc_chunk_re.finditer (translated_contents):
+            if m.group (2) == preferred_language:
+                full_translated_contents = translated_contents
+                translated_contents = m.group (1)
+                translated_contents_start = m.start ()
+                translated_contents_end = m.end ()
+                break
+        else:
+            return
+        original = file_name.replace ('texidocs' + os.path.sep, 'lsr' + os.path.sep, 1)
+        original = original.replace ('.texidoc', '.ly', 1)
+
+        # URG dirty .texidoc files manipulation in a dirty way
+        if touch_committishes and buildlib.check_translated_doc (original,
+                                         file_name,
+                                         translated_contents,
+                                         color=use_colors and not update_mode)[1]:
+            (estimated_revision, error) = buildlib.read_pipe (vc_last_texidoc_revision % vars ())
+            if error:
+                sys.stderr.write ('warning: %s: %s' % (file_name, error))
+            estimated_revision = estimated_revision.strip ()
+            translated_contents = re.sub (r'(?m)^%+\s*Translation of GIT committish:.*\n', '', translated_contents)
+            f = open (file_name, 'w')
+            f.write (full_translated_contents[:translated_contents_start])
+            f.write ('%% Translation of GIT committish: ' + estimated_revision + '\n')
+            f.write (translated_contents)
+            f.write (full_translated_contents[translated_contents_end:])
+            return
+
+    else:
+        original = dir_lang (file_name, '', lang_dir_index)
+        translated_contents = open (file_name).read ()
+
     (diff_string, error) \
         = buildlib.check_translated_doc (original,
                                          file_name,
@@ -67,24 +113,29 @@ This script is licensed under the GNU GPL.
 ''')
 
 def do_options ():
-    global lang, verbose, update_mode, use_colors
+    global lang, verbose, update_mode, touch_committishes, use_colors
 
     p = optparse.OptionParser (usage="check-translation [--language=LANG] [--verbose] FILE...",
                                description="This script is licensed under the GNU GPL.")
     p.add_option ("--language",
                   action='store',
-                  default='site',
+                  default=C,
                   dest="language")
     p.add_option ("--no-color",
                   action='store_false',
                   default=True,
                   dest="color",
-                  help="do not print ANSI-cooured output")
+                  help="do not print ANSI-colored output")
     p.add_option ("--verbose",
                   action='store_true',
                   default=False,
                   dest="verbose",
                   help="print details, including executed shell commands")
+    p.add_option ('-t',
+                  action='store_true',
+                  default=False,
+                  dest="touch_committishes",
+                  help=optparse.SUPPRESS_HELP)
     p.add_option ('-u', "--update",
                   action='store_true',
                   default=False,
@@ -96,6 +147,7 @@ def do_options ():
     lang = options.language
     use_colors = options.color
     update_mode = options.update_mode
+    touch_committishes = options.touch_committishes
     
     return files
 
@@ -111,7 +163,7 @@ def main ():
     buildlib.verbose = verbose
 
     for i in files:
-        do_file (i, langdefs.LANGDICT.keys (), buildlib)
+        do_file (i, langdefs.LANGDICT.keys ())
 
 if __name__ == '__main__':
     main ()