okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge main 6c642df75 into f-own-int (round 16: network waits, robustness, Windows kill-on-close job start, GitHub and transfer fixes)cd9745050

main
2.1 KiB46 linesraw
1"""Writes src/locales/net-<lang>.json: the line shown while a download server has not answered yet (lane NET, owner wording 11-10, W14).
2Run from apps/host:  python scripts/make-net-locales.py
3The English text is strata_control/netpolicy.py WORDS["waiting"] with {host} -> {0} and {seconds} -> {1}; setup prints it and
4strata_control/progress_words.py hands it to the app as the install step's label. Every entry names all nine languages; keys are net01.. in
5the order of S. Placeholders ({0}, {1}) must be kept in every language. The eight translations are first drafts for the owner's later look."""
6import json
7import re
8from pathlib import Path
9
10LANGS = ["en", "zh", "ja", "de", "es", "ru", "pt", "ko", "fr"]
11S = []
12
13
14def add(en, zh, ja, de, es, ru, pt, ko, fr):
15    S.append(dict(en=en, zh=zh, ja=ja, de=de, es=es, ru=ru, pt=pt, ko=ko, fr=fr))
16
17
18add("Waiting for {0} to answer ({1} s so far)",
19    "正在等待 {0} 响应(已等待 {1} 秒)",
20    "{0} の応答を待っています({1} 秒経過)",
21    "Warten auf eine Antwort von {0} (bisher {1} s)",
22    "Esperando la respuesta de {0} ({1} s hasta ahora)",
23    "Ожидание ответа от {0} (прошло {1} с)",
24    "A aguardar a resposta de {0} ({1} s até agora)",
25    "{0}의 응답을 기다리는 중 ({1}초 경과)",
26    "En attente de la réponse de {0} ({1} s jusqu'ici)")
27
28here = Path(__file__).resolve().parent.parent / "src" / "locales"
29NBSP = " "
30
31
32def french(text):
33    text = re.sub(r"(?<=[A-Za-zÀ-ſ])'(?=[A-Za-zÀ-ſ{])", "’", text)
34    text = re.sub(r"(?<=\S) ([:;?!])", NBSP + r"\1", text)
35    return text
36
37
38for lang in LANGS:
39    data = {}
40    for i, entry in enumerate(S):
41        text = entry[lang]
42        assert sorted(re.findall(r"\{\d+\}", entry["en"])) == sorted(re.findall(r"\{\d+\}", text)), (lang, entry["en"], text)
43        data[f"net{i + 1:02d}"] = french(text) if lang == "fr" else text
44    with (here / f"net-{lang}.json").open("w", encoding="utf-8", newline="\n") as handle:
45        handle.write(json.dumps(data, ensure_ascii=False, indent=1) + "\n")
46print("written", len(S), "strings in", len(LANGS), "languages")