Fix utility function `make-type-checker'.
[lilypond/mpolesky.git] / python / langdefs.py
blob3351a4fa7420be5583375732712690ce7c736c18
1 #!@PYTHON@
2 #-*- coding: utf-8 -*-
4 """
5 Documentation i18n module
6 """
8 import re
9 import sys
10 import os
12 def lang_file_name (p, langext, ext):
13 if langext != '':
14 return p + '.' + langext + ext
15 return p + ext
17 class LanguageDef:
18 def __init__ (self, code, name, webext=None, double_punct_char_sep='', html_filter=lambda s: s, enable_ly_identifier_l10n=True):
19 self.code = code
20 self.name = name
21 self.enabled = True
22 if webext == None:
23 self.webext = self.code
24 else:
25 self.webext = webext
26 self.double_punct_char_sep = double_punct_char_sep
27 self.html_filter = html_filter
28 self.enable_ly_identifier_l10n = enable_ly_identifier_l10n
29 def file_name (self, prefix, ext):
30 return lang_file_name (prefix, self.webext, ext)
33 # All language information needed for documentation i18n is defined
34 # here. For each 'Documentation/ab' directory containing docs
35 # translated in 'ab', there should be one entry in LANGUAGES.
37 site = LanguageDef ('en', 'English', webext='')
39 html_body_re = re.compile ('<body.*?>', re.I)
40 html_end_body_re = re.compile ('</body>', re.I)
41 french_html_typo_rules = ((' :', '&nbsp;:'),
42 (' ;', '&nbsp;;'),
43 (' ?', '<font size="-4">&nbsp;</font>?'),
44 (' !', '<font size="-4">&nbsp;</font>!'))
46 def french_html_filter (page):
47 m = html_body_re.search (page)
48 if m:
49 body_begin = m.end ()
50 else:
51 body_begin = 0
52 m = html_end_body_re.search (page)
53 if m:
54 body_end = m.start ()
55 else:
56 body_end = len (page)
57 body = page[body_begin:body_end]
58 for r in french_html_typo_rules:
59 body = body.replace (r[0], r[1])
60 return page[:body_begin] + body + page[body_end:]
62 fr = LanguageDef ('fr', 'français', double_punct_char_sep='&nbsp;', html_filter = french_html_filter)
63 es = LanguageDef ('es', 'español')
64 de = LanguageDef ('de', 'deutsch')
65 nl = LanguageDef ('nl', 'nederlands')
66 ja = LanguageDef ('ja', '日本語', enable_ly_identifier_l10n=False)
67 hu = LanguageDef ('hu', 'magyar')
68 it = LanguageDef ('it', 'italiano')
70 # Outdated or broken translations may be disabled
71 # (please run 'make doc-clean' before doing that):
72 #fr.enabled = False
74 LANGUAGES = (site, fr, es, de, nl, ja, hu, it)
76 if __name__ == '__main__':
77 print ' '.join ([l.code for l in LANGUAGES if l.enabled and l.code != 'en'])
78 else:
79 LANGDICT = {}
80 for l in LANGUAGES:
81 LANGDICT[l.code] = l
83 try:
84 import gettext
86 translation = {}
87 for l in LANGUAGES:
88 if l.enabled and l.code != 'en':
89 t = gettext.translation('lilypond-doc',
90 os.environ['LYDOC_LOCALEDIR'],
91 [l.code])
92 translation[l.code] = t.gettext
93 except:
94 if os.environ.has_key ('LYDOC_LOCALEDIR'):
95 sys.stderr.write ('langdefs.py: warning: lilypond-doc gettext domain not found.\n')
96 translation = dict ([(l.code, lambda x: x) for l in LANGUAGES])