forked from libresilicon/libresilicon.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranslate.py
More file actions
executable file
·72 lines (59 loc) · 1.77 KB
/
translate.py
File metadata and controls
executable file
·72 lines (59 loc) · 1.77 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from jinja2 import Environment, FileSystemLoader
import json
import codecs
PATH = os.path.dirname(os.path.abspath(__file__))
languages = [False,'zh','ja','ko','en','de']
TEMPLATE_ENVIRONMENT = Environment(
autoescape = False,
loader=FileSystemLoader(os.path.join(PATH, 'templates')),
#loader = FileSystemLoader(PATH),
trim_blocks = False
)
def render_template(template_filename, language):
print("Language: "+language)
json_content = json.load(fp=open("lang/"+language+".json"),encoding="utf-8")
return TEMPLATE_ENVIRONMENT.get_template(template_filename).render(json_content)
def create_index_html():
for lang in languages:
fname = "index"
if lang:
fname+='_'
fname+=lang
else:
lang='en'
fname+=".html"
# rendering
with codecs.open(fname, 'w', "utf-8-sig") as f:
html = render_template('index.tpl',lang)
f.write(html)
def create_news_html():
for lang in languages:
fname = "news"
if lang:
fname+='_'
fname+=lang
else:
lang='en'
fname+=".rss"
# rendering
with codecs.open(fname, 'w', "utf-8-sig") as f:
html = render_template('news.tpl',lang)
f.write(html)
def main():
create_index_html()
create_news_html()
########################################
if __name__ == "__main__":
main()
#ginger index.tpl lang/en.json | grep -v "^null$" > index.html
#ginger news.tpl lang/en.json | grep -v "^null$" > news.rss
#ginger img/LSA-whitepaper.tpl lang/en.json | grep -v "^null$" > img/LSA-whitepaper.svg
#for lang in zh ja ko en de
#do
# ginger index.tpl lang/$lang.json | grep -v "^null$" > index_$lang.html
# ginger news.tpl lang/$lang.json | grep -v "^null$" > news_$lang.rss
#ginger img/LSA-whitepaper.tpl lang/$lang.json | grep -v "^null$" > img/LSA-whitepaper_$lang.svg
#done