GodMode9/utils/transcp.py
Pk11 8cde50e091
Automate translation files (#880)
* Automate language.inl file

* Move version number to JSON file

Better than being a magic number somewhere in the code, source code gets it from source.json

* Automate creation of .trf translation files
2024-11-30 08:24:15 -03:00

27 lines
829 B
Python
Executable File

#!/usr/bin/env python3
from argparse import ArgumentParser, FileType
import json
# Special keys
LANGUAGE_NAME = "GM9_LANGUAGE"
VERSION = "GM9_TRANS_VER"
parser = ArgumentParser(description="Creates the language.inl file from source.json")
parser.add_argument("source", type=FileType("r"), help="source.json")
parser.add_argument("inl", type=FileType("w"), help="language.inl")
args = parser.parse_args()
# Load the JSON and handle the meta values
source = json.load(args.source)
version = source[VERSION]
del source[VERSION]
del source[LANGUAGE_NAME]
# Create the header file
args.inl.write("#define TRANSLATION_VER %d\n\n" % version)
for key in source:
# Escape \r, \n, and quotes
val = source[key].replace("\r", "\\r").replace("\n", "\\n").replace('"', '\\"')
args.inl.write('STRING(%s, "%s")\n' % (key, val))