3 from mako
.template
import Template
4 from gettext
import GNUTranslations
5 from optparse
import OptionParser
22 u
"Joe Hansen <joedalton2@yahoo.dk>",
25 u
"Ian Weller <ianweller@gmail.com>",
28 u
"Sam Stuewe <Ch4in3dRe4cti0n@gmail.com>",
43 u
"Piotr Drąg <piotrdrag@gmail.com>",
46 u
"<jshm@programeshqip.org>",
49 u
"Dimitris Glezos <glezos@indifex.com>",
54 def generate_chooser():
56 for langcode
in LANGUAGES
:
57 if langcode
in RTL_LANGS
:
58 langname
= '<bdo dir="rtl">%s</bdo>' % LANGUAGES
[langcode
]
60 langname
= LANGUAGES
[langcode
]
61 data
+= '<li><a href="/%s/@PAGENAME@">%s</a></li>' % (
66 def generate_credits():
68 for langcode
in MAINTAINERS
:
69 if langcode
in RTL_LANGS
:
70 langname
= '<bdo dir="rtl">%s</bdo>' % LANGUAGES
[langcode
]
72 langname
= LANGUAGES
[langcode
]
73 data
+= "<dt>%s</dt>" % langname
74 for maint
in MAINTAINERS
[langcode
]:
75 data
+= "<dd>%s</dd>" % cgi
.escape(maint
)
78 def generate_files(lang
, chooser
, transcredits
):
79 print "Generating files for %s" % lang
84 translations
= GNUTranslations(open(os
.path
.join('po', lang
+ '.mo')))
85 for dirpath
, dirnames
, filenames
in os
.walk('data'):
87 for filename
in filenames
:
88 if filename
[0] == '.':
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(
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'))
109 parser
= OptionParser()
110 (options
, args
) = parser
.parse_args()
112 print "Language codes requried to run"
115 lang_chooser
= generate_chooser()
116 transcredits
= generate_credits()
117 generate_files(args
[0], lang_chooser
, transcredits
)
119 if __name__
== "__main__":