]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/texi-gettext.py
Add localized PDF user manual support
[lilypond.git] / buildscripts / texi-gettext.py
1 #!@PYTHON@
2 # texi-gettext.py
3
4 # USAGE:  texi-gettext.py [-o OUTDIR] BUILDSCRIPT-DIR LOCALEDIR LANG FILES
5 #
6 # -o OUTDIR specifies that output files should be written in OUTDIR
7 #    rather than be overwritten
8 #
9
10 import sys
11 import re
12 import os
13 import getopt
14 import gettext
15
16 optlist, args = getopt.getopt(sys.argv[1:],'o:')
17 buildscript_dir, localedir, lang = args[0:3]
18
19 outdir = '.'
20 for x in optlist:
21         if x[0] == '-o':
22                 outdir = x[1]
23
24 sys.path.append (buildscript_dir)
25 import langdefs
26
27 double_punct_char_separator = langdefs.LANGDICT[lang].double_punct_char_sep
28 t = gettext.translation('lilypond-doc', localedir, [lang])
29 _doc = t.gettext
30
31 include_re = re.compile (r'@include (.*?)$', re.M)
32
33 def title_gettext (m):
34         return '@' + m.group (1) + m.group (2) + _doc (m.group (3)) + m.group (4)
35
36 def process_file (filename):
37         print "Processing %s" % filename
38         f = open (filename, 'r')
39         page = f.read ()
40         f.close()
41         page = re.sub (r'(?L)@(rglos|(?:unnumbered|appendix)(?:(?:sub){0,2}sec)?|top|chapter|(?:sub){0,2}section|(?:major|chap|(?:sub){0,2})heading)(\{| )(.*?)(\}|\n)', title_gettext, page)
42         page = page.replace ("""-- SKELETON FILE --
43 When you actually translate this file, please remove these lines as
44 well as all `UNTRANSLATED NODE: IGNORE ME' lines.""", '')
45         page = page.replace ('UNTRANSLATED NODE: IGNORE ME', _doc ("This section has not been translated yet; please refer to the manual in English."))
46         f = open (os.path.join (outdir, filename), 'w')
47         f.write (page)
48         f.close ()
49         dir = os.path.dirname (filename)
50         for file in include_re.findall (page):
51                 p = os.path.join (dir, file)
52                 if os.path.exists (p):
53                         process_file (p)
54
55 for filename in args[3:]:
56         process_file (filename)
57
58 toto = raw_input ("Press enter to continue")