aboutsummaryrefslogtreecommitdiff
path: root/translate.py
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-10-06 23:02:10 +0200
committermetamuffin <metamuffin@disroot.org>2024-10-06 23:02:10 +0200
commita7ae29a8257447227621efde489095ace81fd028 (patch)
tree106650baf2992661f840bc228687d471b7493609 /translate.py
parentde9d2e0ae8187014983fe08e25383d24b1f76d1b (diff)
downloadhurrycurry-website-a7ae29a8257447227621efde489095ace81fd028.tar
hurrycurry-website-a7ae29a8257447227621efde489095ace81fd028.tar.bz2
hurrycurry-website-a7ae29a8257447227621efde489095ace81fd028.tar.zst
localize
Diffstat (limited to 'translate.py')
-rw-r--r--translate.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/translate.py b/translate.py
new file mode 100644
index 0000000..c73a364
--- /dev/null
+++ b/translate.py
@@ -0,0 +1,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)