]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/auxiliar/tely-gettext.py
midi2ly: fix non-printable in MIDI text
[lilypond.git] / scripts / auxiliar / tely-gettext.py
index 341816a7dbe61646f38f3b9b75ad2bf4a21fd0cf..3adc4cb6d3b692b09d8b953af22e4c52c633fb8e 100755 (executable)
@@ -4,34 +4,30 @@
 # Temporary script that helps translated docs sources conversion
 # for texi2html processing
 
-# USAGE:  tely-gettext.py PYTHON-DIR LOCALEDIR LANG FILES
+# USAGE:  tely-gettext.py LANG FILES
 
 print "tely-gettext.py"
 
 import sys
 import re
 import os
-import gettext
 
-if len (sys.argv) > 3:
-    buildscript_dir, localedir, lang = sys.argv[1:4]
-else:
-    print """USAGE:  tely-gettext.py PYTHON-DIR LOCALEDIR LANG FILES
-  For example scripts/auxiliar/tely-gettext.py python/out Documentation/po/out-www de Documentation/de/user/*.tely"""
-    sys.exit (1)
-
-sys.path.append (buildscript_dir)
 import langdefs
 
+lang = sys.argv[1]
+files = sys.argv[2:]
+
 double_punct_char_separator = langdefs.LANGDICT[lang].double_punct_char_sep
-t = gettext.translation('lilypond-doc', localedir, [lang])
-_doc = t.gettext
+_doc = langdefs.translation[lang]
 
 include_re = re.compile (r'@include (.*?)$', re.M)
 whitespaces = re.compile (r'\s+')
-ref_re = re.compile (r'(?ms)@(ruser|rprogram|ref|rlearning)\{(.*?)\}')
+ref_re = re.compile (r'(?ms)@((?:ressay|rgloss|rinternals|rlearning|rslr|rprogram|ruser|ref)|named)\{(.*?)\}')
 node_section_re = re.compile (r'@node (.*?)\n@((?:unnumbered|appendix)(?:(?:sub){0,2}sec)?|top|chapter|(?:sub){0,2}section|(?:major|chap|(?:sub){0,2})heading) (.*?)\n')
+section_only_re = re.compile (r'@((?:unnumbered|appendix)(?:(?:sub){0,2}sec)?|top|chapter|(?:sub){0,2}section|(?:major|chap|(?:sub){0,2})heading) (.*?)\n')
 menu_entry_re = re.compile (r'\* (.*?)::')
+untranslated_node_re = re.compile (r'(@node\s+.*\n@.*\n.*)(\s+@untranslated(.|\n)+?)(?=@node|@subheading|@menu|$)')
+
 
 def ref_gettext (m):
     r = whitespaces.sub (' ', m.group (2))
@@ -40,32 +36,43 @@ def ref_gettext (m):
 def node_gettext (m):
     return '@node ' + _doc (m.group (1)) + '\n@' + \
         m.group (2) + ' ' + _doc (m.group (3)) + \
-       '\n@translationof ' + m.group (1) + '\n'
+       '\n@translationof ' + m.group (1) + '\n'
+
+def section_gettext (m):
+    return '@' + m.group (1) + ' ' + _doc (m.group (2)) + '\n'
 
 def menu_entry_gettext (m):
     return '* ' + _doc (m.group (1)) + '::'
 
-def process_file (filename):
+def process_file (filename, master_file_dir='.', included=False):
     print "Processing %s" % filename
     f = open (filename, 'r')
     page = f.read ()
     f.close()
-    page = node_section_re.sub (node_gettext, page)
     page = ref_re.sub (ref_gettext, page)
+    if not '\\n@translationof' in page:
+        page = node_section_re.sub (node_gettext, page)
+    page = section_only_re.sub (section_gettext, page)
     page = menu_entry_re.sub (menu_entry_gettext, page)
-    page = page.replace ("""-- SKELETON FILE --
-When you actually translate this file, please remove these lines as
-well as all `UNTRANSLATED NODE: IGNORE ME' lines.""", """@c -- SKELETON FILE --""")
-    page = page.replace ('UNTRANSLATED NODE: IGNORE ME', "@c UNTRANSLATED NODE: IGNORE ME")
-    includes = [whitespaces.sub ('', f) for f in include_re.findall (page)]
+    page = page.replace ("""@c -- SKELETON FILE --
+""", '')
+    page = page.replace ('UNTRANSLATED NODE: IGNORE ME', '@untranslated')
+    page = untranslated_node_re.sub ('\\1 @c external\\2', page)
+    includes = include_re.findall (page)
     f = open (filename, 'w')
     f.write (page)
     f.close ()
     dir = os.path.dirname (filename)
+    if not included:
+        master_file_dir = dir
     for file in includes:
         p = os.path.join (dir, file)
         if os.path.exists (p):
-            process_file (p)
+            process_file (p, master_file_dir, included=True)
+        else:
+            p = os.path.join (master_file_dir, file)
+            if os.path.exists (p):
+                process_file (p, master_file_dir, included=True)
 
-for filename in sys.argv[4:]:
+for filename in files:
     process_file (filename)