Tfe

Ongi etorri tfe-ren webgunera...

Blog/jokoak_euskaraz/stray/moda_kudeatu.py

(Deskargatu)
#!/usr/bin/env python3
"""
Stray euskarazko mod-a kudeatzeko tresna.

Itzulpenak `translations.json` fitxategian editatu (lerro bakoitza kate bat,
`"eu"` eremua aldatu). Gero:

  python3 moda_kudeatu.py eraiki   -> pak-a berreraiki eta instalatu
  python3 moda_kudeatu.py jokoa    -> jokoa abiarazi (Wine)

Aukerakoa:  python3 moda_kudeatu.py tsv  -> translations.tsv esportatu
            (kalkulu-orri batean editatu nahi izanez gero)
"""
import json
import os
import shutil
import subprocess
import sys

BASE = os.path.dirname(os.path.abspath(__file__))
SRC_LOCRES = os.path.join(BASE, "en", "Game.locres")
TRANSLATIONS_JSON = os.path.join(BASE, "translations.json")
TRANSLATIONS_TSV = os.path.join(BASE, "translations.tsv")
LOCRES_PY = os.path.join(BASE, "locres.py")
BUILD_MOD_PY = os.path.join(BASE, "build_mod.py")
REPAK = "/tmp/opencode/repak/repak_cli-x86_64-unknown-linux-gnu/repak"
GAME = "/home/tfe/games/Stray_game"
PAKS = os.path.join(GAME, "Data/Hk_project/Content/Paks")
OVERRIDE_PAK = os.path.join(PAKS, "Hk_project-WindowsNoEditor_Override.pak")
LAUNCHER = os.path.join(GAME, "Data/Stray.exe")


def load_entries():
    return json.load(open(TRANSLATIONS_JSON, encoding="utf-8"))


def export_tsv():
    entries = json.load(open(TRANSLATIONS_JSON, encoding="utf-8"))
    with open(TRANSLATIONS_TSV, "w", encoding="utf-8") as f:
        for e in entries:
            f.write(f"{e['ns']}\t{e['key']}\t{e['en']}\t{e['eu']}\n")
    print("Idatzita:", TRANSLATIONS_TSV)


def build_and_install():
    os.makedirs(os.path.join(BASE, "build"), exist_ok=True)
    out = os.path.join(BASE, "build", "Game_eu.locres")
    extra = os.path.join(BASE, "en_repack", "Game.locres")
    cmd = [sys.executable, BUILD_MOD_PY, SRC_LOCRES, TRANSLATIONS_JSON, out]
    if os.path.exists(extra):
        cmd.append(extra)
    subprocess.run(cmd, check=True)
    modcontent = os.path.join(BASE, "modcontent")
    en_dir = os.path.join(modcontent, "Hk_project/Content/Localization/Game/en")
    fr_dir = os.path.join(modcontent, "Hk_project/Content/Localization/Game/fr")
    os.makedirs(en_dir, exist_ok=True)
    os.makedirs(fr_dir, exist_ok=True)
    shutil.copy(out, os.path.join(en_dir, "Game.locres"))
    shutil.copy(out, os.path.join(fr_dir, "Game.locres"))
    pak = os.path.join(BASE, "build", "Hk_project-WindowsNoEditor_Override.pak")
    subprocess.run([REPAK, "pack", modcontent, pak, "-m", "../../../",
                    "--version", "V11", "-p", "397643129", "--compression", "Zlib"],
                   check=True, capture_output=True)
    shutil.copy(pak, OVERRIDE_PAK)
    print("Pak-a instalatuta:", OVERRIDE_PAK)


def launch():
    os.chdir(os.path.dirname(LAUNCHER))
    subprocess.Popen(["wine", LAUNCHER])


if __name__ == "__main__":
    cmd = sys.argv[1] if len(sys.argv) > 1 else ""
    if cmd == "tsv":
        export_tsv()
    elif cmd == "eraiki":
        load_entries()
        build_and_install()
    elif cmd == "jokoa":
        launch()
    else:
        print(__doc__)