Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 10 additions & 71 deletions scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
82 changes: 82 additions & 0 deletions scripts/config.py
Original file line number Diff line number Diff line change
@@ -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
Empty file added scripts/libs/__init__.py
Empty file.
File renamed without changes.
10 changes: 4 additions & 6 deletions scripts/movekey.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
32 changes: 32 additions & 0 deletions scripts/pretty.py
Original file line number Diff line number Diff line change
@@ -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)
45 changes: 45 additions & 0 deletions scripts/validate.py
Original file line number Diff line number Diff line change
@@ -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()
10 changes: 9 additions & 1 deletion scripts/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
###
Expand Down