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|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'\* (.*?)::')
40 # - well, it would add one more dependency...
76 ("Í", "@'{@dotless{i}}"),
77 ("ì", "@`{@dotless{i}}"),
78 ("î", "@^{@dotless{i}}"),
79 ("ï", "@\"{@dotless{i}}"),
88 ("¡", "@exclamdown{}"),
89 ("¿", "@questiondown{}"),
99 def title_gettext (m):
100 if m.group (2) == '{':
101 r = whitespaces.sub (' ', m.group (3))
104 return '@' + m.group (1) + m.group (2) + _doc (r) + m.group (4)
106 def menu_entry_gettext (m):
107 return '* ' + _doc (m.group (1)) + '::'
109 def include_replace (m, filename):
110 if os.path.exists (os.path.join (os.path.dirname (filename), m.group(1)) + '.texi'):
111 return '@include ' + m.group(1) + '.pdftexi'
114 def process_file (filename):
115 print "Processing %s" % filename
116 f = open (filename, 'r')
119 page = node_section_re.sub (title_gettext, page)
120 page = ref_re.sub (title_gettext, page)
121 page = menu_entry_re.sub (menu_entry_gettext, page)
122 page = page.replace ("""-- SKELETON FILE --
123 When you actually translate this file, please remove these lines as
124 well as all `UNTRANSLATED NODE: IGNORE ME' lines.""", '')
125 page = page.replace ('UNTRANSLATED NODE: IGNORE ME', _doc ("This section has not been translated yet; please refer to the manual in English."))
126 includes = include_re.findall (page)
127 page = include_re.sub (lambda m: include_replace (m, filename), page)
128 for (u_char, texiaccent_char) in accents2texi:
129 page = page.replace (u_char, texiaccent_char)
130 p = os.path.join (outdir, filename) [:-4] + 'pdftexi'
134 dir = os.path.dirname (filename)
135 for file in includes:
136 p = os.path.join (dir, file) + '.texi'
137 if os.path.exists (p):
140 for filename in args[3:]:
141 process_file (filename)