+3








bf70f2cf23
* refactor priorities * performance report doodling * shutup pycharm * more doodling * doodle tricol * tweak report, fix bug in insert * reorder colors * another metric * sorting engines, trying to catch exc * restructure engine err * restructure engine err * test stuff * test report * test report * test and readme * test and readme * layout * engine recov * pixelfix and exes * readme * keyboard shortcut override * oops * mistakes only deeper * black and readme * readme * fix #421, scale repor * Add shortcut variables (#420) * Add shortcut variables * Address comments and missed shortcuts * fix shortcuts * rename, design report, fix report * make translators work more * relative mid/opening/endgame bounds * win size dbg * more errros * entry * jeff mode * fix * readme * edit THEMES.md * edit katrain/core/ai.py, edit katrain/gui/kivyutils.py * jp (#423) * edit THEMES.md * edit katrain/__main__.py, edit katrain/gui/kivyutils.py and 1 other changes * Update katrain.po (#425) 1.9 first French .po * edit katrain/i18n/locales/fr/LC_MESSAGES/katrain.mo * edit katrain/core/ai.py, edit katrain/gui/popups.py * bluedabadee * fix sgf and black * edit katrain/i18n/locales/fr/LC_MESSAGES/katrain.po * ko * Update zh-TW translation (#426) * cn * cn * Some corrections to Chinese translations (#427) * some corrections in cn and tw * better trans * edit CONTRIBUTIONS.md, edit katrain/i18n/locales/cn/LC_MESSAGES/katrain.mo and 1 other changes * de * tw * player what only * add green background to better value (#428) * edit katrain/gui/popups.py, edit katrain/gui/theme.py * Russian for 1.9 (#432) * edit katrain/i18n/locales/ru/LC_MESSAGES/katrain.po, edit katrain/gui.kv and 1 other changes * sound fix * sound fix * fmt * fix sound * edit THEMES.md, edit CONTRIBUTIONS.md and 1 other changes * sound fix * Do not use ffpyplayer on Windows (#434) * edit katrain/gui/sound.py * no pr * jeff theme * stopsound * sound and theme fix * font fix and more errs * French po corrections (#441) Former translations were misleading. It should be accurate now. * add mouse scroll to browser through node variations. (#442) * add mouse scroll to browser through node variations. * add mouse scroll to browser through node variations. * add mouse scroll to browser through node variations. * edit katrain/popups.kv, edit katrain/__main__.py and 2 other changes * windows binary, black * linux binary * edit INSTALL.md * edit .github/workflows/osxbuild.yaml * edit .github/workflows/osxbuild.yaml * edit .github/workflows/osxbuild.yaml Co-authored-by: Sander Land <sander.land@cognite.com> Co-authored-by: roux g. buciu <11182210+electricRGB@users.noreply.github.com> Co-authored-by: kaorahi <38910552+kaorahi@users.noreply.github.com> Co-authored-by: Dontbtme <66470440+Dontbtme@users.noreply.github.com> Co-authored-by: Liou, Guan-Cheng <Tony-Liou@users.noreply.github.com> Co-authored-by: Ching-yu Lin <60384727+chingyulin@users.noreply.github.com> Co-authored-by: xiaoyifang <105986+xiaoyifang@users.noreply.github.com> Co-authored-by: Alexander Kiselev <satoshi.yoda.register.264@gmail.com> Co-authored-by: Sander Land <Sander@bioeng219-lap.isd.kcl.ac.uk> Co-authored-by: Carton He <cartonhe@gmail.com> Co-authored-by: Sander Land <sander.land@aroni.fritz.box> Co-authored-by: Sander Land <sander.land@futurefacts.nl>
122 lines
4.8 KiB
Python
122 lines
4.8 KiB
Python
import copy
|
|
import glob
|
|
import os
|
|
import re
|
|
import sys
|
|
from collections import defaultdict
|
|
|
|
import polib
|
|
|
|
localedir = "katrain/i18n/locales"
|
|
locales = set(os.listdir(localedir))
|
|
print("locales found:", locales)
|
|
|
|
strings_to_langs = defaultdict(dict)
|
|
strings_to_keys = defaultdict(dict)
|
|
lang_to_strings = defaultdict(set)
|
|
|
|
DEFAULT_LANG = "en"
|
|
|
|
errors = False
|
|
|
|
po = {}
|
|
pofile = {}
|
|
todos = defaultdict(list)
|
|
|
|
for lang in locales:
|
|
pofile[lang] = os.path.join(localedir, lang, "LC_MESSAGES", "katrain.po")
|
|
po[lang] = polib.pofile(pofile[lang])
|
|
for entry in po[lang].translated_entries():
|
|
if "TODO" in entry.comment and "DEPRECATED" not in entry.comment:
|
|
todos[lang].append(entry)
|
|
strings_to_langs[entry.msgid][lang] = entry
|
|
strings_to_keys[entry.msgid][lang] = set(re.findall("{.*?}", entry.msgstr))
|
|
if entry.msgid in lang_to_strings[lang]:
|
|
print("duplicate", entry.msgid, "in", lang, "--> deleting", entry.msgstr)
|
|
errors = True
|
|
po[lang].remove(entry)
|
|
else:
|
|
lang_to_strings[lang].add(entry.msgid)
|
|
if todos[lang] and any("todo" in a for a in sys.argv):
|
|
print(f"========== {lang} has {len(todos[lang])} TODO entries ========== ")
|
|
for item in todos[lang]:
|
|
print(item)
|
|
|
|
|
|
for lang in locales:
|
|
if lang != DEFAULT_LANG:
|
|
for msgid in lang_to_strings[lang]:
|
|
if (
|
|
DEFAULT_LANG in strings_to_keys[msgid]
|
|
and strings_to_keys[msgid][lang] != strings_to_keys[msgid][DEFAULT_LANG]
|
|
):
|
|
print(
|
|
f"{msgid} has inconstent formatting keys for {lang}: ",
|
|
strings_to_keys[msgid][lang],
|
|
"is different from default",
|
|
strings_to_keys[msgid][DEFAULT_LANG],
|
|
)
|
|
errors = True
|
|
|
|
for msgid in strings_to_langs.keys() - lang_to_strings[lang]:
|
|
if lang == DEFAULT_LANG:
|
|
print("Message id", msgid, "found as ", strings_to_langs[msgid], "but missing in default", DEFAULT_LANG)
|
|
errors = True
|
|
elif DEFAULT_LANG in strings_to_langs[msgid]:
|
|
copied_entry = copy.copy(strings_to_langs[msgid][DEFAULT_LANG])
|
|
print("Message id", msgid, "missing in ", lang, "-> Adding it from", DEFAULT_LANG)
|
|
if copied_entry.comment:
|
|
copied_entry.comment = f"TODO - {copied_entry.comment}"
|
|
else:
|
|
copied_entry.comment = "TODO"
|
|
po[lang].append(copied_entry)
|
|
errors = True
|
|
else:
|
|
print(f"MISSING IN DEFAULT AND {lang}", msgid)
|
|
errors = True
|
|
|
|
for msgid, lang_entries in strings_to_langs.items():
|
|
if lang in lang_entries and "TODO" in lang_entries[lang].comment:
|
|
if any(e.msgstr == lang_entries[lang].msgstr for ll, e in lang_entries.items() if ll != lang):
|
|
if lang_entries.get(DEFAULT_LANG):
|
|
todo_comment = (
|
|
f"TODO - {lang_entries[DEFAULT_LANG].comment}" if lang_entries[DEFAULT_LANG].comment else "TODO"
|
|
) # update todo
|
|
if (
|
|
lang_entries[lang].msgstr != lang_entries[DEFAULT_LANG].msgstr
|
|
or lang_entries[lang].comment.replace("\n", " ") != todo_comment
|
|
):
|
|
print(
|
|
[
|
|
lang_entries[lang].msgstr,
|
|
lang_entries[DEFAULT_LANG].msgstr,
|
|
lang_entries[lang].comment,
|
|
todo_comment,
|
|
]
|
|
)
|
|
lang_entries[lang].msgstr = lang_entries[DEFAULT_LANG].msgstr # update
|
|
lang_entries[lang].comment = todo_comment
|
|
print(f"{lang}/{msgid} todo entry updated")
|
|
|
|
po[lang].save(pofile[lang])
|
|
mofile = pofile[lang].replace(".po", ".mo")
|
|
po[lang].save_as_mofile(mofile)
|
|
print("Fixed", pofile[lang], "and converted ->", mofile)
|
|
|
|
|
|
for ext in ["py", "kv"]:
|
|
lc = 0
|
|
for file in glob.glob(f"katrain/*.{ext}") + glob.glob(f"katrain/**/*.{ext}"):
|
|
with open(file, "r") as f:
|
|
for i, line in enumerate(f.readlines()):
|
|
if line.strip():
|
|
lc += 1
|
|
matches = [m.strip() for m in re.findall(r"i18n._\((.*?)\)", line)]
|
|
for msgid in matches:
|
|
stripped_msgid = msgid.strip("\"'")
|
|
if stripped_msgid and msgid[0] in ['"', "'"] and stripped_msgid not in strings_to_langs: # not code
|
|
print(f"Missing {msgid} used in code at \t{file}:{i} \t'{line.strip()}'")
|
|
errors += 1
|
|
print(f"Checked {lc} lines of {ext} code for missing i18n entries.")
|
|
sys.exit(int(errors))
|