]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/texi-gettext.py
Make PDF manual in all languages really working
[lilypond.git] / buildscripts / texi-gettext.py
1 #!@PYTHON@
2 # -*- coding: utf-8 -*-
3 # texi-gettext.py
4
5 # USAGE:  texi-gettext.py [-o OUTDIR] BUILDSCRIPT-DIR LOCALEDIR LANG FILES
6 #
7 # -o OUTDIR specifies that output files should be written in OUTDIR
8 #    rather than be overwritten
9 #
10
11 print "texi_gettext.py"
12
13 import sys
14 import re
15 import os
16 import getopt
17 import gettext
18
19 optlist, args = getopt.getopt(sys.argv[1:],'o:')
20 buildscript_dir, localedir, lang = args[0:3]
21
22 outdir = '.'
23 for x in optlist:
24         if x[0] == '-o':
25                 outdir = x[1]
26
27 sys.path.append (buildscript_dir)
28 import langdefs
29
30 double_punct_char_separator = langdefs.LANGDICT[lang].double_punct_char_sep
31 t = gettext.translation('lilypond-doc', localedir, [lang])
32 _doc = t.gettext
33
34 include_re = re.compile (r'@include (.*?)$', re.M)
35
36 # Why not use recode?
37 # - well, it would add one more dependency...
38 accents2texi = (
39         ("á", "@'a"),
40         ("à", "@`a"),
41         ("â", "@^a"),
42         ("ä", "@\"a"),
43         ("é", "@'e"),
44         ("è", "@`e"),
45         ("ê", "@^e"),
46         ("ë", "@\"e"),
47         ("ó", "@'o"),
48         ("ò", "@`o"),
49         ("ô", "@^o"),
50         ("ö", "@\"o"),
51         ("ú", "@'u"),
52         ("ù", "@`u"),
53         ("û", "@^u"),
54         ("ü", "@\"u"),
55         ("ç", "@,{c}"),
56         ("À", "@`A"),
57         ("Á", "@'A"),
58         ("Â", "@^A"),
59         ("Ä", "@\"A"),
60         ("É", "@'E"),
61         ("È", "@`E"),
62         ("Ê", "@^E"),
63         ("Ë", "@\"E"),
64         ("Ó", "@'O"),
65         ("Ò", "@`O"),
66         ("Ô", "@^O"),
67         ("Ö", "@\"O"),
68         ("Ú ", "@'U"),
69         ("Ù", "@`U"),
70         ("Û", "@^U"),
71         ("Ü", "@\"U"),
72         ("Ç", "@,{C}"),
73         ("Í", "@'{@dotless{i}}"),
74         ("ì", "@`{@dotless{i}}"),
75         ("î", "@^{@dotless{i}}"),
76         ("ï", "@\"{@dotless{i}}"),
77         ("Í", "@'I"),
78         ("Ì", "@`I"),
79         ("Î", "@^I"),
80         ("Ï", "@\"I"),
81         ("œ", "@oe{}"),
82         ("Œ", "@OE{}"),
83         ("æ", "@ae{}"),
84         ("Æ", "@AE{}"),
85         ("¡", "@exclamdown{}"),
86         ("¿", "@questiondown{}"),
87         ("ø", "@o{}"),
88         ("Ø", "@O{}"),
89         ("ß", "@ss{}"),
90         ("ł", "@l{}"),
91         ("Ł", "@L{}"),
92         ("å", "@aa{}"),
93         ("Å", "@AA{}"))
94
95
96 def title_gettext (m):
97         return '@' + m.group (1) + m.group (2) + _doc (m.group (3)) + m.group (4)
98
99 def menu_entry_gettext (m):
100         return '* ' + _doc (m.group (1)) + '::'
101
102 def process_file (filename):
103         print "Processing %s" % filename
104         f = open (filename, 'r')
105         page = f.read ()
106         f.close()
107         page = re.sub (r'@(node|(?:unnumbered|appendix)(?:(?:sub){0,2}sec)?|top|chapter|(?:sub){0,2}section|(?:major|chap|(?:sub){0,2})heading)( )(.*?)(\n)', title_gettext, page)
108         page = re.sub (r'(?L)@(rglos|ref)(\{)(.*?)(\})', title_gettext, page)
109         page = re.sub (r'\* (.*?)::', menu_entry_gettext, page)
110         page = page.replace ("""-- SKELETON FILE --
111 When you actually translate this file, please remove these lines as
112 well as all `UNTRANSLATED NODE: IGNORE ME' lines.""", '')
113         page = page.replace ('UNTRANSLATED NODE: IGNORE ME', _doc ("This section has not been translated yet; please refer to the manual in English."))
114         for (u_char, texiaccent_char) in accents2texi:
115                 page = page.replace (u_char, texiaccent_char)
116         p = os.path.join (outdir, filename)
117         f = open (p, 'w')
118         f.write (page)
119         f.close ()
120         dir = os.path.dirname (filename)
121         for file in include_re.findall (page):
122                 p = os.path.join (dir, file)
123                 if os.path.exists (p):
124                         process_file (p)
125
126 for filename in args[3:]:
127         process_file (filename)