cp po/lilypond-doc.pot po/$(ISOLANG).po
@echo "*** Please add a language definition for $(ISOLANG) in buildscripts/langdefs.py ***"
-check-translation:
- find $(ISOLANG)/user/ -maxdepth 1 -name '*.*te??' | xargs $(PYTHON) $(buildscript-dir)/check_translation.py $(buildscript-dir) $(ISOLANG)/index.html.in
+CHECKED_FILES = $(ISOLANG)/index.html.in $(shell find $(ISOLANG)/user/ -maxdepth 1 -name '*.*te??')
TELY_FILES = $(call src-wildcard,$(ISOLANG)/user/*.tely)
skeleton-update:
$(PYTHON) $(buildscript-dir)/update-snippets.py user $(ISOLANG)/user '*.itely'
endif
+check-translation:
+ $(PYTHON) $(buildscript-dir)/check_translation.py $(buildscript-dir) $(CHECKED_FILES)
+
+update-translation:
+ $(PYTHON) $(buildscript-dir)/check_translation.py --update $(buildscript-dir) $(CHECKED_FILES)
+
translation-status:
make -C po out=www messages
$(PYTHON) $(buildscript-dir)/translations-status.py $(buildscript-dir) po/out-www
--- /dev/null
+#!@PYTHON@
+
+import subprocess
+import re
+
+verbose = False
+
+def read_pipe (command):
+ child = subprocess.Popen (command,
+ stdout = subprocess.PIPE,
+ stderr = subprocess.PIPE,
+ shell = True)
+ (output, error) = child.communicate ()
+ code = str (child.wait ())
+ if not child.stdout or child.stdout.close ():
+ print "pipe failed: %(command)s" % locals ()
+ if code != '0':
+ error = code + ' ' + error
+ return (output, error)
+
+revision_re = re.compile ('GIT [Cc]ommittish: ([a-f0-9]+)')
+vc_diff_cmd = 'git diff %(color_flag)s %(revision)s HEAD -- %(original)s | cat'
+
+def check_translated_doc (original, translated_contents, color=False):
+ m = revision_re.search (translated_contents)
+ if not m:
+ sys.stderr.write ('error: ' + translated + \
+ ": no 'GIT committish: <hash>' found.\nPlease check " + \
+ 'the whole file against the original in English, then ' + \
+ 'fill in HEAD committish in the header.\n')
+ sys.exit (1)
+ revision = m.group (1)
+
+ if color:
+ color_flag = '--color'
+ else:
+ color_flag = '--no-color'
+ c = vc_diff_cmd % vars ()
+ if verbose:
+ sys.stderr.write ('running: ' + c)
+ return read_pipe (c)
import __main__
import optparse
-import gettext
import os
-import re
import sys
verbose = 0
path_components[lang_dir_index] = lang
return os.path.join (*path_components)
-## Translation of GIT Commit: <hash>
-REVISION_RE = re.compile ('GIT [Cc]ommittish: ([a-f0-9]+)')
-CVS_DIFF = 'git diff %(revision)s HEAD -- %(original)s | cat'
-
-def check_file (original, translated):
- s = open (translated).read ()
- m = REVISION_RE.search (s)
- if not m:
- sys.stderr.write ('error: ' + translated + \
- ": no 'GIT committish: <hash>' found.\nPlease check " + \
- 'the whole file against the original in English, then ' + \
- 'fill in HEAD committish in the header.\n')
- sys.exit (1)
- revision = m.group (1)
-
- c = CVS_DIFF % vars ()
- if verbose:
- sys.stderr.write ('running: ' + c)
- os.system (c)
-
-def do_file (file_name, lang_codes):
+def do_file (file_name, lang_codes, buildlib):
if verbose:
sys.stderr.write ('%s...\n' % file_name)
split_file_name = file_name.split ('/')
raise Exception ('cannot determine language for ' + file_name)
original = dir_lang (file_name, '', lang_dir_index)
- translated = file_name
- check_file (original, translated)
+ translated_contents = open (file_name).read ()
+ (diff_string, error) = buildlib.check_translated_doc (original, translated_contents, color=not update_mode)
+
+ if error:
+ sys.stderr.write ('warning: %s: %s' % (file_name, error))
+
+ if update_mode:
+ if error or len (diff_string) >= os.path.getsize (original):
+ buildlib.read_pipe (text_editor + ' ' + file_name + ' ' + original)
+ elif diff_string:
+ diff_file = original + '.diff'
+ f = open (diff_file, 'w')
+ f.write (diff_string)
+ f.close ()
+ buildlib.read_pipe (text_editor + ' ' + file_name + ' ' + diff_file)
+ os.remove (diff_file)
+ else:
+ sys.stdout.write (diff_string)
def usage ():
sys.stdout.write (r'''
Usage:
-check-translation [--language=LANG] [--verbose] BUILDSCRIPT-DIR FILE...
+check-translation [--language=LANG] [--verbose] [--update] BUILDSCRIPT-DIR FILE...
This script is licensed under the GNU GPL.
''')
def do_options ():
- global lang, verbose
+ global lang, verbose, update_mode
p = optparse.OptionParser (usage="check-translation [--language=LANG] [--verbose] FILE...",
description="This script is licensed under the GNU GPL.")
default=False,
dest="verbose",
help="the GIT directory to merge.")
+ p.add_option ('-u', "--update",
+ action='store_true',
+ default=False,
+ dest='update_mode',
+ help='call $EDITOR to update the translation')
(options, files) = p.parse_args ()
verbose = options.verbose
lang = options.language
+ update_mode = options.update_mode
return (files[0], files[1:])
def main ():
+ global update_mode, text_editor
+
import_path, files = do_options ()
+ if 'EDITOR' in os.environ.keys ():
+ text_editor = os.environ['EDITOR']
+ else:
+ update_mode = False
sys.path.append (import_path)
import langdefs
+ import buildlib
+ buildlib.verbose = verbose
for i in files:
- do_file (i, langdefs.LANGDICT.keys())
+ do_file (i, langdefs.LANGDICT.keys(), buildlib)
if __name__ == '__main__':
main ()
import string
import os
import gettext
-import subprocess
def progress (str):
sys.stderr.write (str + '\n')
sys.path.append (buildscript_dir)
import langdefs
+import buildlib
# load gettext messages catalogs
translation = {}
if l.enabled and l.code != 'en':
translation[l.code] = gettext.translation('lilypond-doc', localedir, [l.code]).gettext
-def read_pipe (command):
- child = subprocess.Popen (command,
- stdout = subprocess.PIPE,
- stderr = subprocess.PIPE,
- shell = True)
- (output, error) = child.communicate ()
- code = str (child.wait ())
- if not child.stdout or child.stdout.close ():
- print "pipe failed: %(command)s" % locals ()
- if code != '0':
- error = code + ' ' + error
- return (output, error)
comments_re = re.compile (r'^@ignore\n(.|\n)*?\n@end ignore$|@c .*?$', re.M)
space_re = re.compile (r'\s+', re.M)
title_re = re.compile ('^@(top|chapter|(?:sub){0,2}section|(?:unnumbered|appendix)(?:(?:sub){0,2}sec)?) (.*?)$', re.M)
include_re = re.compile ('^@include (.*?)$', re.M)
-committish_re = re.compile ('GIT [Cc]ommittish: ([a-f0-9]+)')
translators_re = re.compile (r'^@c\s+Translators\s*:\s*(.*?)$', re.M | re.I)
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)
untranslated_node_str = 'UNTRANSLATED NODE: IGNORE ME'
skeleton_str = '-- SKELETON FILE --'
-diff_cmd = 'git diff --no-color %(committish)s HEAD -- %(original)s | cat'
-
format_table = {
'not translated': {'color':'d0f0f8', 'short':_doc ('no'), 'abbr':'NT',
'long':_doc ('not translated')},
self.translation_percentage = 100 * translation_word_count / master_total_word_count
## calculate how much the file is outdated
- m = committish_re.search (self.contents)
- if not m:
- sys.stderr.write ('error: ' + filename + \
- ": no 'GIT committish: <hash>' found.\nPlease check " + \
- 'the whole file against the original in English, then ' + \
- 'fill in HEAD committish in the header.\n')
- sys.exit (1)
- (diff_string, error) = read_pipe (diff_cmd % {'committish':m.group (1), 'original':masterdocument.filename})
+ (diff_string, error) = buildlib.check_translated_doc (masterdocument.filename, self.contents)
if error:
sys.stderr.write ('warning: %s: %s' % (self.filename, error))
self.uptodate_percentage = None
progress ("Reading documents...")
-tely_files = read_pipe ("find -maxdepth 2 -name '*.tely'")[0].splitlines ()
+tely_files = buildlib.read_pipe ("find -maxdepth 2 -name '*.tely'")[0].splitlines ()
master_docs = [MasterTelyDocument (os.path.normpath (filename)) for filename in tely_files]
master_docs = [doc for doc in master_docs if doc.translations]
progress ("Generating status pages...")
-date_time = read_pipe ('LANG= date -u')[0]
+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 += '\n'.join ([doc.html_status () for doc in master_docs])