import re
import sys
lang = sys.argv[1]
trmap = {
    '_a_browser_version': '',
    '_a_book': '',
    '_a_codeberg': '',
    '_a_weblate': '',
    '_a_end': '',
    '_b': '',
    '_b_end': '',
    '_developers': 'nokoe, metamuffin, tpart',
    '_lang': lang,
}
for l in ["en", lang]:
    for line in open(f"dist-extra/locale/{l}.ini"):
        line = line.strip()
        if line == "[hurrycurry]": continue
        if line == "": continue
        key, value = line.split("=", 1)
        trmap[key.strip()] = value.strip().replace("<","<").replace(">",">")
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)