-
Notifications
You must be signed in to change notification settings - Fork 0
/
translate.py
executable file
·39 lines (31 loc) · 1.13 KB
/
translate.py
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
#!/usr/bin/env python3
from bottle import SimpleTemplate
import importlib
languages = ["en", "de", "fr", "nl"]
wordlists = {
"en": "words/english.txt",
"de": "words/german.txt",
"fr": "words/french.txt",
"nl": "words/netherlands.txt",
}
pages = ["index.html", "compact.html", "options.html"]
strings = dict()
for language in languages:
mod = importlib.import_module(language)
strings = mod.strings
strings["wordlist"] = "";
strings["currentlang"] = language;
with open(wordlists[language]) as wordlistfile:
wordcount = 0;
for line in wordlistfile:
if wordcount > 0:
strings["wordlist"] += " "
strings["wordlist"] += line[:-1];
wordcount += 1;
#if wordcount % 10 == 0:
# strings["wordlist"] += ""\n";
for page in pages:
strings["currentsite"] = page;
with open(language + "/" + page, 'w') as outputfile:
with open('template.tpl', 'r') as templatefile:
outputfile.write(SimpleTemplate(templatefile.read()).render(strings));