diff --git a/scripts/compile.py b/scripts/compile.py index 0d339a6f..28a88418 100755 --- a/scripts/compile.py +++ b/scripts/compile.py @@ -4,83 +4,22 @@ Builds language files """ -import os import sys import csv import json import argparse from pathlib import Path -import polib - -META = "engine/meta" - -RECIPES = { - "ENGINE": [META, "engine/common", "engine/zdoom"], - "GAMES": [ - "games/chex", - "games/doom", - "games/doom2", - "games/heretic", - "games/hexen", - "games/hexen-deathkings", - "games/plutonia", - "games/strife", - "games/tnt", - ], - "GAMES_CHEX3": ["games/filter/chex_quest_3"], - "GAMES_HARMONY": ["games/filter/harmony"], - "GAMES_HACX": ["games/filter/hacx"] -} -RECIPES["ALL"] = list(sum(RECIPES.values(), [])) - -SOURCE_LANG = "en_US" -SOURCE_LANG_ALT = SOURCE_LANG.split("_", maxsplit=1)[0] - -# auto-add once a certain portion of strings have been translated -THRESHOLD = 0.5 - -# add to table even if THRESHOLD is not met -ENABLED = [ - "en_GB", # eng enc ena enz eni ens enj enb enl ent enw - "cs", - "da", - "de", - "es", - "es_MX", # esm - "eo", - "fi", - "fr", - "hu", - "it", - "ja", # jp - "ko", - "nl", - "nb_NO", # no - "pl", - "pt", # ptg - "pt_BR", # pt - "ro", - "ru", - "sr", - "tr", -] - -# Don't add to table even if THRESHOLD is met -# If adding a language here, please add a comment why, so it can be -# re-evaluated later -DISABLED = [ - "ar", # no rtl support in uzdoom yet - "he", # no rtl support in uzdoom yet -] - -KEEP_REMARKS = False - -DEBUG = True -try: - DEBUG = DEBUG or 'DEBUG_LANGUAGE' in os.environ -except OSError: - pass +from libs import polib +from config import \ + DEBUG, \ + DISABLED, \ + ENABLED, \ + KEEP_REMARKS, \ + RECIPES, \ + SOURCE_LANG, \ + SOURCE_LANG_ALT, \ + THRESHOLD def dump_csv(destination, table): diff --git a/scripts/config.py b/scripts/config.py new file mode 100644 index 00000000..cb80785b --- /dev/null +++ b/scripts/config.py @@ -0,0 +1,82 @@ +""" +Config data +""" + +import datetime +import os +import platform + +from libs import polib + + +META = "engine/meta" + +RECIPES = { + "ENGINE": [META, "engine/common", "engine/zdoom"], + "GAMES": [ + "games/chex", + "games/doom", + "games/doom2", + "games/heretic", + "games/hexen", + "games/hexen-deathkings", + "games/plutonia", + "games/strife", + "games/tnt", + ], + "GAMES_CHEX3": ["games/filter/chex_quest_3"], + "GAMES_HARMONY": ["games/filter/harmony"], + "GAMES_HACX": ["games/filter/hacx"] +} +RECIPES["ALL"] = list(set(sum(RECIPES.values(), []))) + +SOURCE_LANG = "en_US" +SOURCE_LANG_ALT = SOURCE_LANG.split("_", maxsplit=1)[0] + +# auto-add once a certain portion of strings have been translated +THRESHOLD = 0.5 + +# add to table even if THRESHOLD is not met +ENABLED = [ + "en_GB", # eng enc ena enz eni ens enj enb enl ent enw + "cs", + "da", + "de", + "es", + "es_MX", # esm + "eo", + "fi", + "fr", + "hu", + "it", + "ja", # jp + "ko", + "nl", + "nb_NO", # no + "pl", + "pt", # ptg + "pt_BR", # pt + "ro", + "ru", + "sr", + "tr", +] + +# Don't add to table even if THRESHOLD is met +# If adding a language here, please add a comment why, so it can be +# re-evaluated later +DISABLED = [ + "ar", # no rtl support in uzdoom yet + "he", # no rtl support in uzdoom yet +] + +KEEP_REMARKS = False + +SCRIPT_ID = f"python {platform.python_version()} polib {polib.__version__}" +TIMESTAMP = datetime.datetime.now().astimezone().strftime("%Y-%m-%d %H:%M%z") + +DEBUG = True +try: + DEBUG = DEBUG or 'DEBUG_LANGUAGE' in os.environ +except OSError: + pass diff --git a/scripts/libs/__init__.py b/scripts/libs/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/scripts/polib.py b/scripts/libs/polib.py similarity index 100% rename from scripts/polib.py rename to scripts/libs/polib.py diff --git a/scripts/movekey.py b/scripts/movekey.py index 6a458517..0f2925f4 100755 --- a/scripts/movekey.py +++ b/scripts/movekey.py @@ -6,15 +6,13 @@ import sys import argparse -from datetime import datetime import subprocess -import platform from pathlib import Path -import polib - -SCRIPT_ID = f"python {platform.python_version()} polib {polib.__version__}" -TIMESTAMP = datetime.now().astimezone().strftime("%Y-%m-%d %H:%M%z") +from libs import polib +from config import \ + TIMESTAMP, \ + SCRIPT_ID def set_meta(key, val, *pofiles): diff --git a/scripts/pretty.py b/scripts/pretty.py new file mode 100644 index 00000000..e357edc3 --- /dev/null +++ b/scripts/pretty.py @@ -0,0 +1,32 @@ +""" +Simple pretty-printing function + +Copyright 2026 Marcus Minhorst + +SPDX-License-Identifier: 0BSD +""" + + +def pretty(data, stack=None): + """Pretty prints data in a yaml-like output""" + + if not stack: + stack = [] + + def line(data, end=""): + print(f"{''.join(stack)}{str(data)}{end}") + + def entry(value, end): + nonlocal stack + pretty(value, stack + [end]) + stack = ["\t"] * len(stack) + + if isinstance(data, list): + for value in data: + entry(value, "- ") + elif isinstance(data, dict): + for key, value in data.items(): + line(key, ":") + entry(value, "\t") + else: + line(data) diff --git a/scripts/validate.py b/scripts/validate.py new file mode 100755 index 00000000..01775481 --- /dev/null +++ b/scripts/validate.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 + +""" +Tests that everything is okay in the database +""" + +import sys +from pathlib import Path + +from pretty import pretty +from config import \ + RECIPES + + +issues = {} + + +def issue(message, **kwargs): + """Tosses stuff into the issues dict""" + for k, v in kwargs.items(): + if k not in issues: + issues[k] = {} + if v not in issues[k]: + issues[k][v] = [] + issues[k][v] += [message] + + +def main(): + """yep""" + + for component in RECIPES["ALL"]: + cpath = Path(component) + if not cpath.is_dir(): + issue("not found", component=component) + continue + + if issues: + pretty(issues) + sys.exit(1) + + print("okay") + + +if __name__ == "__main__": + main() diff --git a/scripts/validate.sh b/scripts/validate.sh index 8e1cdb4d..2438c434 100644 --- a/scripts/validate.sh +++ b/scripts/validate.sh @@ -54,7 +54,7 @@ echo phase validate python scripts ### -pyfiles=( scripts/compile.py scripts/movekey.py ) +pyfiles=( scripts/*.py ) pyversion=3.6 for pyfile in "${pyfiles[@]}"; do @@ -72,6 +72,14 @@ dirty=$(git status --porcelain) bash ./scripts/mktemplate.sh || ((error_count++)) [[ -z "$dirty" ]] && { [[ -z "$(git status --porcelain)" ]] || ((error_count++)) ; } +### +phase validate po files +### + +dirty=$(git status --porcelain) +./scripts/validate.py || ((error_count++)) +[[ -z "$dirty" ]] && { [[ -z "$(git status --porcelain)" ]] || ((error_count++)) ; } + ### phase test compile ###