#!/usr/bin/env python3 from argparse import ArgumentParser from os import path import json import struct parser = ArgumentParser(description="Creates an TRF translation for GodMode9 from a translation JSON") parser.add_argument("input", type=str, help="JSON to convert from") parser.add_argument("output", type=str, help="to output to") parser.add_argument("version", type=int, help="translation version, from language.inl") args = parser.parse_args() with open(args.input, "r") as f: # read JSON strings = json.load(f) if "GM9_LANGUAGE" not in strings: print("Fatal: Input is not a valid JSON file") exit(1) # Encode strings to UTF-8 bytestrings strings = {item: strings[item].encode("utf-8") + b"\0" for item in strings} # Remove language name from strings lang_name = strings["GM9_LANGUAGE"] del strings["GM9_LANGUAGE"] # sort map # fontMap = sorted(fontMap, key=lambda x: x["mapping"]) # write file with open(args.output, "wb") as out: out.write(b"RIFF") out.write(struct.pack("