forked from sympy/sympy.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate
executable file
·50 lines (41 loc) · 1.29 KB
/
generate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#! /usr/bin/env python
import os
import hashlib
from gettext import GNUTranslations
from jinja2 import Environment, FileSystemLoader
def md5_filter(value):
return hashlib.md5(value).hexdigest()
env = Environment(loader=FileSystemLoader('templates'),
extensions=['jinja2.ext.i18n'])
env.filters["md5"] = md5_filter
templates = [
"index.html",
"download.html",
"docs.html",
"support.html",
"screenshots.html",
"development.html",
"donate.html",
]
# Sorted alphabetically:
languages = ["cs", "de", "en", "fr", "pt", "ru", "zh"]
for language in languages:
print "Generating '%s' pages" % language
if language == "en":
# The templates are written in English, so they don't need to be
# translated
env.install_null_translations()
else:
translations = GNUTranslations(open("i18n/%s.mo" % language))
env.install_gettext_translations(translations)
for template in templates:
t = env.get_template(template)
print " Processing '%s'" % template
name = os.path.splitext(template)[0]
s = t.render({name + "_active": "active"})
f = open(os.path.join(language, template), "wb")
try:
f.write(s.encode("utf-8"))
f.write("\n")
finally:
f.close()