2 # -*- coding: utf-8 -*-
4 # Temporary script that helps translated docs sources conversion
5 # for texi2html processing
7 # USAGE: tely-gettext.py PYTHON-DIR LOCALEDIR LANG FILES
9 print "tely-gettext.py"
16 if len (sys.argv) > 3:
17 buildscript_dir, localedir, lang = sys.argv[1:4]
19 print """USAGE: tely-gettext.py PYTHON-DIR LOCALEDIR LANG FILES
20 For example scripts/aux/tely-gettext.py python/out Documentation/po/out-www de Documentation/de/user/*.tely"""
23 sys.path.append (buildscript_dir)
26 double_punct_char_separator = langdefs.LANGDICT[lang].double_punct_char_sep
27 t = gettext.translation('lilypond-doc', localedir, [lang])
30 include_re = re.compile (r'@include (.*?)$', re.M)
31 whitespaces = re.compile (r'\s+')
32 ref_re = re.compile (r'(?ms)@(ruser|rprogram|ref|rlearning)\{(.*?)\}')
33 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')
34 menu_entry_re = re.compile (r'\* (.*?)::')
37 r = whitespaces.sub (' ', m.group (2))
38 return '@' + m.group (1) + '{' + _doc (r) + '}'
41 return '@node ' + _doc (m.group (1)) + '\n@' + \
42 m.group (2) + ' ' + _doc (m.group (3)) + \
43 '\n@translationof ' + m.group (1) + '\n'
45 def menu_entry_gettext (m):
46 return '* ' + _doc (m.group (1)) + '::'
48 def process_file (filename):
49 print "Processing %s" % filename
50 f = open (filename, 'r')
53 page = node_section_re.sub (node_gettext, page)
54 page = ref_re.sub (ref_gettext, page)
55 page = menu_entry_re.sub (menu_entry_gettext, page)
56 page = page.replace ("""-- SKELETON FILE --
57 When you actually translate this file, please remove these lines as
58 well as all `UNTRANSLATED NODE: IGNORE ME' lines.""", """@c -- SKELETON FILE --""")
59 page = page.replace ('UNTRANSLATED NODE: IGNORE ME', "@c UNTRANSLATED NODE: IGNORE ME")
60 includes = [whitespaces.sub ('', f) for f in include_re.findall (page)]
61 f = open (filename, 'w')
64 dir = os.path.dirname (filename)
66 p = os.path.join (dir, file)
67 if os.path.exists (p):
70 for filename in sys.argv[4:]:
71 process_file (filename)