]> git.donarmstrong.com Git - lilypond.git/blob - scripts/auxiliar/tely-gettext.py
Docs: prepare direct translation of node names in Texinfo sources
[lilypond.git] / scripts / auxiliar / tely-gettext.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 # Temporary script that helps translated docs sources conversion
5 # for texi2html processing
6
7 # USAGE:  tely-gettext.py LANG FILES
8
9 print "tely-gettext.py"
10
11 import sys
12 import re
13 import os
14
15 import langdefs
16
17 lang = sys.argv[1]
18 files = sys.argv[2:]
19
20 double_punct_char_separator = langdefs.LANGDICT[lang].double_punct_char_sep
21 _doc = langdefs.translation[lang]
22
23 include_re = re.compile (r'@include (.*?)$', re.M)
24 whitespaces = re.compile (r'\s+')
25 ref_re = re.compile (r'(?ms)@(ruser|rprogram|ref|rlearning)\{(.*?)\}')
26 node_section_re = re.compile (r'@node (.*?)\n@((?:unnumbered|appendix)(?:(?:sub){0,2}sec)?|top|chapter|(?:sub){0,2}section|(?:major|chap|(?:sub){0,2})heading) (.*?)\n')
27 menu_entry_re = re.compile (r'\* (.*?)::')
28 untranslated_node_re = re.compile (r'(@node\s+.*\n@.*\n.*)(\s+@untranslated(.|\n)+?)(?=@node|@subheading|@menu|$)')
29
30
31 def ref_gettext (m):
32     r = whitespaces.sub (' ', m.group (2))
33     return '@' + m.group (1) + '{' + _doc (r) + '}'
34
35 def node_gettext (m):
36     return '@node ' + _doc (m.group (1)) + '\n@' + \
37         m.group (2) + ' ' + _doc (m.group (3)) + \
38        '\n@translationof ' + m.group (1) + '\n'
39
40 def menu_entry_gettext (m):
41     return '* ' + _doc (m.group (1)) + '::'
42
43 def process_file (filename):
44     print "Processing %s" % filename
45     f = open (filename, 'r')
46     page = f.read ()
47     f.close()
48     page = node_section_re.sub (node_gettext, page)
49     page = ref_re.sub (ref_gettext, page)
50     page = menu_entry_re.sub (menu_entry_gettext, page)
51     page = page.replace ("""@c -- SKELETON FILE --
52 """, '')
53     page = page.replace ('UNTRANSLATED NODE: IGNORE ME', '@untranslated')
54     page = untranslated_node_re.sub ('\\1 @c external\\2', page)
55     includes = include_re.findall (page)
56     f = open (filename, 'w')
57     f.write (page)
58     f.close ()
59     dir = os.path.dirname (filename)
60     for file in includes:
61         p = os.path.join (dir, file)
62         if os.path.exists (p):
63             process_file (p)
64
65 for filename in files:
66     process_file (filename)