Enable da translation
[spreadlovenow-web.git] / build.py
blob1801297156d7164a1c60f84b0f3e8547339613b5
1 #!/usr/bin/python
2 # coding=utf-8
3 from mako.template import Template
4 from gettext import GNUTranslations
5 from optparse import OptionParser
6 import sys, os, cgi
8 LANGUAGES = {
9 'da': u'Dansk',
10 'en': u'English',
11 'fr': u'Français',
12 #'nl': u'Nederlands',
13 #'de': u'Deutsch',
14 #'ru': u'Русский',
15 #'ar': u'العربية',
16 'pl': u'polski',
17 'sq': u'Shqip',
18 'el': u'Ελληνικά',
20 MAINTAINERS = {
21 'da': [
22 u"Joe Hansen <joedalton2@yahoo.dk>",
24 'en': [
25 u"Ian Weller <ianweller@gmail.com>",
27 'fr': [
28 u"Sam Stuewe <Ch4in3dRe4cti0n@gmail.com>",
30 #'nl': [
31 # u"David Carpenter",
32 #],
33 #'de': [
34 # u"David Carpenter",
35 #],
36 #'ru': [
37 # u"David Carpenter",
38 #],
39 #'ar': [
40 # u"David Carpenter",
41 #],
42 'pl': [
43 u"Piotr Drąg <piotrdrag@gmail.com>",
45 'sq': [
46 u"<jshm@programeshqip.org>",
48 'el': [
49 u"Dimitris Glezos <glezos@indifex.com>",
52 RTL_LANGS = ['ar',]
54 def generate_chooser():
55 data = ""
56 for langcode in LANGUAGES:
57 if langcode in RTL_LANGS:
58 langname = '<bdo dir="rtl">%s</bdo>' % LANGUAGES[langcode]
59 else:
60 langname = LANGUAGES[langcode]
61 data += '<li><a href="/%s/@PAGENAME@">%s</a></li>' % (
62 langcode, langname
64 return data
66 def generate_credits():
67 data = ""
68 for langcode in MAINTAINERS:
69 if langcode in RTL_LANGS:
70 langname = '<bdo dir="rtl">%s</bdo>' % LANGUAGES[langcode]
71 else:
72 langname = LANGUAGES[langcode]
73 data += "<dt>%s</dt>" % langname
74 for maint in MAINTAINERS[langcode]:
75 data += "<dd>%s</dd>" % cgi.escape(maint)
76 return data
78 def generate_files(lang, chooser, transcredits):
79 print "Generating files for %s" % lang
80 if lang in RTL_LANGS:
81 direction = "rtl"
82 else:
83 direction = "ltr"
84 translations = GNUTranslations(open(os.path.join('po', lang + '.mo')))
85 for dirpath, dirnames, filenames in os.walk('data'):
86 continue
87 for filename in filenames:
88 if filename[0] == '.':
89 continue
90 if filename[-5:] == '.html':
91 template = Template(filename=os.path.join('data', filename),
92 input_encoding="utf8")
93 output = os.path.join('out', lang, filename)
94 fd = file(output, 'w')
95 fd.write(template.render_unicode(
96 lang=lang,
97 direction=direction,
98 transcredits=transcredits.encode('ascii', 'xmlcharrefreplace'),
99 chooser=chooser.replace(
100 "@PAGENAME@", filename[:-5]
101 ).encode('ascii', 'xmlcharrefreplace'),
102 _=lambda text: translations.ugettext(text).encode(
103 'ascii', 'xmlcharrefreplace'
105 ).encode('utf-8', 'replace'))
106 fd.close()
108 def main():
109 parser = OptionParser()
110 (options, args) = parser.parse_args()
111 if len(args) < 1:
112 print "Language codes requried to run"
113 sys.exit(1)
114 else:
115 lang_chooser = generate_chooser()
116 transcredits = generate_credits()
117 generate_files(args[0], lang_chooser, transcredits)
119 if __name__ == "__main__":
120 main()