]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/tely-gettext.py
Merge branch 'lilypond/translation' of ssh://jomand@git.sv.gnu.org/srv/git/lilypond
[lilypond.git] / buildscripts / tely-gettext.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # tely-gettext.py
4
5 # Temporary script that helps translated docs sources conversion
6 # for texi2html processing
7
8 # USAGE:  tely-gettext.py BUILDSCRIPT-DIR LOCALEDIR LANG FILES
9
10 print "tely_gettext.py"
11
12 import sys
13 import re
14 import os
15 import gettext
16
17 if len (sys.argv) > 3:
18     buildscript_dir, localedir, lang = sys.argv[1:4]
19 else:
20     print """USAGE:  tely-gettext.py BUILDSCRIPT-DIR LOCALEDIR LANG FILES
21   For example buildscripts/tely-gettext.py buildscripts Documentation/po/out-www de Documentation/de/user/*.tely"""
22     sys.exit (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 whitespaces = re.compile (r'\s+')
33 ref_re = re.compile (r'(?ms)@(ruser|rprogram|ref|rlearning)\{(.*?)\}')
34 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')
35 menu_entry_re = re.compile (r'\* (.*?)::')
36
37 def ref_gettext (m):
38     r = whitespaces.sub (' ', m.group (2))
39     return '@' + m.group (1) + '{' + _doc (r) + '}'
40
41 def node_gettext (m):
42     return '@node ' + _doc (m.group (1)) + '\n@' + \
43         m.group (2) + ' ' + _doc (m.group (3)) + \
44         '\n@translationof ' + m.group (1) + '\n'
45
46 def menu_entry_gettext (m):
47     return '* ' + _doc (m.group (1)) + '::'
48
49 def process_file (filename):
50     print "Processing %s" % filename
51     f = open (filename, 'r')
52     page = f.read ()
53     f.close()
54     page = node_section_re.sub (node_gettext, page)
55     page = ref_re.sub (ref_gettext, page)
56     page = menu_entry_re.sub (menu_entry_gettext, page)
57     page = page.replace ("""-- SKELETON FILE --
58 When you actually translate this file, please remove these lines as
59 well as all `UNTRANSLATED NODE: IGNORE ME' lines.""", """@c -- SKELETON FILE --""")
60     page = page.replace ('UNTRANSLATED NODE: IGNORE ME', "@c UNTRANSLATED NODE: IGNORE ME")
61     includes = [whitespaces.sub ('', f) for f in include_re.findall (page)]
62     f = open (filename, 'w')
63     f.write (page)
64     f.close ()
65     dir = os.path.dirname (filename)
66     for file in includes:
67         p = os.path.join (dir, file)
68         if os.path.exists (p):
69             process_file (p)
70
71 for filename in sys.argv[4:]:
72     process_file (filename)