2 # -*- coding: utf-8 -*-
5 # USAGE: texi-gettext.py [-o OUTDIR] BUILDSCRIPT-DIR LOCALEDIR LANG FILES
7 # -o OUTDIR specifies that output files should be written in OUTDIR
8 # rather than be overwritten
11 print "texi_gettext.py"
19 optlist, args = getopt.getopt(sys.argv[1:],'o:')
20 buildscript_dir, localedir, lang = args[0:3]
27 sys.path.append (buildscript_dir)
30 double_punct_char_separator = langdefs.LANGDICT[lang].double_punct_char_sep
31 t = gettext.translation('lilypond-doc', localedir, [lang])
34 include_re = re.compile (r'@include (.*?)$', re.M)
37 # - well, it would add one more dependency...
73 ("Í", "@'{@dotless{i}}"),
74 ("ì", "@`{@dotless{i}}"),
75 ("î", "@^{@dotless{i}}"),
76 ("ï", "@\"{@dotless{i}}"),
85 ("¡", "@exclamdown{}"),
86 ("¿", "@questiondown{}"),
96 def title_gettext (m):
97 return '@' + m.group (1) + m.group (2) + _doc (m.group (3)) + m.group (4)
99 def menu_entry_gettext (m):
100 return '* ' + _doc (m.group (1)) + '::'
102 def process_file (filename):
103 print "Processing %s" % filename
104 f = open (filename, 'r')
107 page = re.sub (r'@(node|(?:unnumbered|appendix)(?:(?:sub){0,2}sec)?|top|chapter|(?:sub){0,2}section|(?:major|chap|(?:sub){0,2})heading)( )(.*?)(\n)', title_gettext, page)
108 page = re.sub (r'(?L)@(rglos|ref)(\{)(.*?)(\})', title_gettext, page)
109 page = re.sub (r'\* (.*?)::', menu_entry_gettext, page)
110 page = page.replace ("""-- SKELETON FILE --
111 When you actually translate this file, please remove these lines as
112 well as all `UNTRANSLATED NODE: IGNORE ME' lines.""", '')
113 page = page.replace ('UNTRANSLATED NODE: IGNORE ME', _doc ("This section has not been translated yet; please refer to the manual in English."))
114 for (u_char, texiaccent_char) in accents2texi:
115 page = page.replace (u_char, texiaccent_char)
116 p = os.path.join (outdir, filename)
120 dir = os.path.dirname (filename)
121 for file in include_re.findall (page):
122 p = os.path.join (dir, file)
123 if os.path.exists (p):
126 for filename in args[3:]:
127 process_file (filename)