2 # -*- coding: utf-8 -*-
4 # Temporary script that helps translated docs sources conversion
5 # for texi2html processing
7 # USAGE: tely-gettext.py LANG FILES
9 print "tely-gettext.py"
20 double_punct_char_separator = langdefs.LANGDICT[lang].double_punct_char_sep
21 _doc = langdefs.translation[lang]
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|$)')
32 r = whitespaces.sub (' ', m.group (2))
33 return '@' + m.group (1) + '{' + _doc (r) + '}'
36 return '@node ' + _doc (m.group (1)) + '\n@' + \
37 m.group (2) + ' ' + _doc (m.group (3)) + \
38 '\n@translationof ' + m.group (1) + '\n'
40 def menu_entry_gettext (m):
41 return '* ' + _doc (m.group (1)) + '::'
43 def process_file (filename):
44 print "Processing %s" % filename
45 f = open (filename, 'r')
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 --
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')
59 dir = os.path.dirname (filename)
61 p = os.path.join (dir, file)
62 if os.path.exists (p):
65 for filename in files:
66 process_file (filename)