2 # -*- coding: utf-8 -*-
5 # USAGE: texi-gettext.py [-o OUTDIR] BUILDSCRIPT-DIR LOCALEDIR LANG FILES
7 # -o OUTDIR specifies that output files should rather be written in OUTDIR
10 print "texi_gettext.py"
18 optlist, args = getopt.getopt (sys.argv[1:],'o:')
19 buildscript_dir, localedir, lang = args[0:3]
26 sys.path.append (buildscript_dir)
29 double_punct_char_separator = langdefs.LANGDICT[lang].double_punct_char_sep
30 t = gettext.translation('lilypond-doc', localedir, [lang])
33 include_re = re.compile (r'@include ((?!lily-).*?)\.texi$', re.M)
34 whitespaces = re.compile (r'\s+')
35 ref_re = re.compile (r'(?ms)@(rglos|ruser|rprogram|ref)(\{)(.*?)(\})')
36 node_section_re = re.compile (r'@(node|(?:unnumbered|appendix)(?:(?:sub){0,2}sec)?|top|chapter|(?:sub){0,2}section|(?:major|chap|(?:sub){0,2})heading)( )(.*?)(\n)')
37 menu_entry_re = re.compile (r'\* (.*?)::')
39 def title_gettext (m):
40 if m.group (2) == '{':
41 r = whitespaces.sub (' ', m.group (3))
44 return '@' + m.group (1) + m.group (2) + _doc (r) + m.group (4)
46 def menu_entry_gettext (m):
47 return '* ' + _doc (m.group (1)) + '::'
49 def include_replace (m, filename):
50 if os.path.exists (os.path.join (os.path.dirname (filename), m.group(1)) + '.texi'):
51 return '@include ' + m.group(1) + '.pdftexi'
54 def process_file (filename):
55 print "Processing %s" % filename
56 f = open (filename, 'r')
59 page = node_section_re.sub (title_gettext, page)
60 page = ref_re.sub (title_gettext, page)
61 page = menu_entry_re.sub (menu_entry_gettext, page)
62 page = page.replace ("""-- SKELETON FILE --
63 When you actually translate this file, please remove these lines as
64 well as all `UNTRANSLATED NODE: IGNORE ME' lines.""", '')
65 page = page.replace ('UNTRANSLATED NODE: IGNORE ME', _doc ("This section has not been translated yet; please refer to the manual in English."))
66 includes = include_re.findall (page)
67 page = include_re.sub (lambda m: include_replace (m, filename), page)
68 p = os.path.join (outdir, filename) [:-4] + 'pdftexi'
72 dir = os.path.dirname (filename)
74 p = os.path.join (dir, file) + '.texi'
75 if os.path.exists (p):
78 for filename in args[3:]:
79 process_file (filename)