mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-19 09:25:39 -04:00

* 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
27 lines
829 B
Python
Executable File
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))
|