summaryrefslogtreecommitdiff
path: root/scripts/build
diff options
context:
space:
mode:
authorJohn Mandereau <john.mandereau@gmail.com>2012-07-10 12:06:17 +0200
committerJohn Mandereau <john.mandereau@gmail.com>2012-07-17 17:26:26 +0200
commit2d52187d5492ce7492c78fc8f1dca4aa7b702ba0 (patch)
tree87f71da236c31d101f215b9354fbe0e28a954f21 /scripts/build
parent7d195ce54c3fd467a1434d5399930d6610327e69 (diff)
Get texidoc translations out of snippets source files
Texidoc translations are inserted in .ly snippets at build stage instead of makelsr.py run. This simplifies overall maintenance of snippets, in particular this avoids Git committish update headache for translators. See final discussion at http://lists.gnu.org/archive/html/lilypond-devel/2012-06/msg00438.html
Diffstat (limited to 'scripts/build')
-rw-r--r--scripts/build/makesnippets.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/scripts/build/makesnippets.py b/scripts/build/makesnippets.py
new file mode 100644
index 0000000000..9e7c5a63fe
--- /dev/null
+++ b/scripts/build/makesnippets.py
@@ -0,0 +1,37 @@
+#!@PYTHON@
+# makesnippets.py
+
+'''USAGE: makesnippets.py INPUT_DIR OUTPUT_DIR DOC_DIR
+
+Read all .ly files from INPUT_DIR, insert translations from .texidoc
+files found in DOC_DIR/LANG/texdiocs, and write ther result to OUTPUT_DIR.'''
+
+import glob
+import sys
+import os.path
+import re
+
+import langdefs
+
+(input_dir, output_dir, doc_dir) = sys.argv[1:4]
+
+texidoc_dirs = [os.path.join (doc_dir, language_code, 'texidocs')
+ for language_code in langdefs.LANGDICT]
+
+begin_header_re = re.compile (r'\\header\s*{', re.M)
+
+for f in glob.glob (os.path.join (input_dir, '*.ly')):
+ name = os.path.basename (f)
+ s = open (f).read ()
+ for path in texidoc_dirs:
+ texidoc_translation_path = \
+ os.path.join (path, os.path.splitext (name)[0] + '.texidoc')
+ if os.path.exists (texidoc_translation_path):
+ texidoc_translation = open (texidoc_translation_path).read ()
+ # Since we want to insert the translations verbatim using a
+ # regexp, \\ is understood as ONE escaped backslash. So we have
+ # to escape those backslashes once more...
+ texidoc_translation = texidoc_translation.replace ('\\', '\\\\')
+ s = begin_header_re.sub ('\\g<0>\n' + texidoc_translation, s, 1)
+ dest = os.path.join (output_dir, name)
+ open (dest, 'w').write (s)