aboutsummaryrefslogtreecommitdiff
path: root/translate.py
blob: c73a3643b21b64d042053b2064dae68cc6fc13ce (plain)
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
import re
import sys

lang = sys.argv[1]

trmap = {
    '_a_browser_version': '<a href="https://hurrycurry-web.metamuffin.org/">',
    '_a_book': '<a href="https://s.metamuffin.org/static/hurrycurry/book.pdf">',
    '_a_codeberg': '<a href="https://codeberg.org/hurrycurry/hurrycurry/">',
    '_a_weblate': '<a href="https://translate.codeberg.org/engage/hurrycurry/">',
    '_a_end': '</a>',
    '_b': '<b>',
    '_b_end': '</b>',
    '_developers': '<span id="shuffle">nokoe, metamuffin, tpart</span>',
    '_lang': lang,
}
for l in ["en", lang]:
    for line in open(f"main/locale/{l}.ini"):
        line = line.strip()
        if line == "[hurrycurry]": continue
        if line == "": continue
        key, value = line.split("=")
        trmap[key.strip()] = value.strip().replace("<","&lt;").replace(">","&gt;")

s = open("index_template.html").read()

def replace(matches):
    x = matches.group(1)
    if x in trmap: x = trmap[x]
    else: x = f"MISSING TR ({x})"
    return x

while True:
    sb = s
    s = re.sub(r"\{([\w\.]+)\}", replace, s)
    if s == sb: break

open(f"index.{lang}.html","w+").write(s)