2 # -*- coding: utf-8 -*-
5 # Temporary script that helps translated docs sources conversion
6 # for texi2html processing
8 # USAGE: tely-gettext.py BUILDSCRIPT-DIR LOCALEDIR LANG FILES
10 print "tely_gettext.py"
17 if len (sys
.argv
) > 3:
18 buildscript_dir
, localedir
, lang
= sys
.argv
[1:4]
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"""
24 sys
.path
.append (buildscript_dir
)
27 double_punct_char_separator
= langdefs
.LANGDICT
[lang
].double_punct_char_sep
28 t
= gettext
.translation('lilypond-doc', localedir
, [lang
])
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
'\* (.*?)::')
38 r
= whitespaces
.sub (' ', m
.group (2))
39 return '@' + m
.group (1) + '{' + _doc (r
) + '}'
42 return '@node ' + _doc (m
.group (1)) + '\n@' + \
43 m
.group (2) + ' ' + _doc (m
.group (3)) + \
44 '\n@translationof ' + m
.group (1) + '\n'
46 def menu_entry_gettext (m
):
47 return '* ' + _doc (m
.group (1)) + '::'
49 def process_file (filename
):
50 print "Processing %s" % filename
51 f
= open (filename
, 'r')
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')
65 dir = os
.path
.dirname (filename
)
67 p
= os
.path
.join (dir, file)
68 if os
.path
.exists (p
):
71 for filename
in sys
.argv
[4:]:
72 process_file (filename
)