2 # -*- coding: utf-8 -*-
5 # USAGE: texi-gettext.py [-o OUTDIR] LANG FILES
7 # -o OUTDIR specifies that output files should rather be written in OUTDIR
10 print "texi_gettext.py"
19 optlist, args = getopt.getopt (sys.argv[1:],'o:')
28 double_punct_char_separator = langdefs.LANGDICT[lang].double_punct_char_sep
29 _doc = langdefs.translation[lang]
31 include_re = re.compile (r'@include ((?!../lily-).*?)\.texi$', re.M)
32 whitespaces = re.compile (r'\s+')
33 ref_re = re.compile (r'(?ms)@(rglos|ruser|rprogram|ref)(\{)(.*?)(\})')
34 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)')
35 menu_entry_re = re.compile (r'\* (.*?)::')
37 def title_gettext (m):
38 if m.group (2) == '{':
39 r = whitespaces.sub (' ', m.group (3))
42 return '@' + m.group (1) + m.group (2) + _doc (r) + m.group (4)
44 def menu_entry_gettext (m):
45 return '* ' + _doc (m.group (1)) + '::'
47 def include_replace (m, filename):
48 if os.path.exists (os.path.join (os.path.dirname (filename), m.group(1)) + '.texi'):
49 return '@include ' + m.group(1) + '.pdftexi'
52 def process_file (filename):
53 print "Processing %s" % filename
54 f = open (filename, 'r')
57 page = node_section_re.sub (title_gettext, page)
58 page = ref_re.sub (title_gettext, page)
59 page = menu_entry_re.sub (menu_entry_gettext, page)
60 page = page.replace ("""-- SKELETON FILE --
61 When you actually translate this file, please remove these lines as
62 well as all `UNTRANSLATED NODE: IGNORE ME' lines.""", '')
63 page = page.replace ('UNTRANSLATED NODE: IGNORE ME', _doc ("This section has not been translated yet; please refer to the manual in English."))
64 includes = include_re.findall (page)
65 page = include_re.sub (lambda m: include_replace (m, filename), page)
66 p = os.path.join (outdir, filename) [:-4] + 'pdftexi'
70 dir = os.path.dirname (filename)
72 p = os.path.join (dir, file) + '.texi'
73 if os.path.exists (p):
76 for filename in files:
77 process_file (filename)