]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/html-gettext.py
Use a `define-builtin-markup-command' macro for builtin markups, which
[lilypond.git] / buildscripts / html-gettext.py
1 #!@PYTHON@
2 # html-gettext.py
3
4 # Usage:  html-gettext.py [-o OUTDIR] LOCALEDIR LANG FILES
5 #
6 # -o OUTDIR specifies that output files should be written in OUTDIR
7 #    rather than be overwritten
8 #
9 # LANG
10 # LOCALEDIR should contain 'lilypond-doc' message catalogs
11
12
13 ### DATA
14 # Currently, typo_rules[LANG] only defines the HTML-coded space occuring
15 # before double punctuation characters (i.e. : ; ? ! ) for LANG
16
17 typo_rules = { 'fr':' ', 'default':'' }
18
19
20 ### PROGRAM
21
22 import sys
23 import re
24 import os
25 import string
26 import gettext
27 import getopt
28
29 optlist, args = getopt.getopt(sys.argv[1:],'o:')
30
31 outdir = '.'
32 for x in optlist:
33         if x[0] == '-o':
34                 outdir = x[1]
35
36 if args[1] in typo_rules.keys():
37         dbl_punct_char_separator = typo_rules[args[1]]
38 else:
39         dbl_punct_char_separator = typo_rules['default']
40
41 t = gettext.translation('lilypond-doc', args[0], [args[1]])
42 _ = t.gettext
43
44 def link_gettext (m):
45         return '<link rel="' + m.group(1) + '" ' + m.group(2) + ' title="' + _(m.group(3)) + '">'
46
47 def title_gettext (m):
48         return '<title>' + _(m.group(1)) + ' - ' + m.group(2) + '</title>'
49
50 def a_href_gettext (m):
51         if m.group(4) == ':':
52                 s = dbl_punct_char_separator + ':'
53         elif m.group(4) == None:
54                 s = ''
55         return '<a ' + (m.group(1) or '') + m.group(2) + _(m.group(3)) + '</a>' + s
56
57 def h_gettext (m):
58         return '<h' + m.group(1) + ' class="' + m.group(2) + '">' + \
59                (m.group(3) or '') + _(m.group(4)) + '</h' + m.group(1) + '>'
60
61 for filename in args[2:]:
62         f = open (filename, 'r')
63         page = f.read ()
64         f.close()
65         page = re.sub (r'<link rel="(up|prev|next)" (.*?) title="([^"]*?)">', link_gettext, page)
66         page = re.sub (r'<title>([^<]*?) - ([^<]*?)</title>', title_gettext, page)
67         page = re.sub (r'<a ((?:rel="\w+")? ?(?:accesskey="[^"]+?" ?)?)(href="[^"]+?">)([^<]+)</a>(:)?', a_href_gettext, page)
68         page = re.sub (r'<h(\d) class="(\w+)">([\d.]+ )?([^<]+)</h\1>', h_gettext, page)
69         for w in ('Next:', 'Previous:', 'Up:'):
70                 page = re.sub (w, _(w), page)
71         f = open (os.path.join (outdir, filename), 'w')
72         f.write (page)
73         f.close ()