sm64coopdx/tools/append_lang_keys.py

29 lines
1.1 KiB
Python
Raw Normal View History

2023-11-13 13:27:20 +00:00
import os
import sys
# I can't stand it anymore, editing like 9 different INI files and finding the right spot just to add 1 line and also translating them all at the same time too, I'm making a script for this!
def add_new_key(ini_path, section, search_key, new_key):
new_value = input(f"{new_key} for {os.path.basename(ini_path)}: ")
current_section = ""
out = []
with open(ini_path, "r", encoding="utf-8") as f:
lines = f.readlines()
2024-05-12 02:05:35 +00:00
added = False
2023-11-13 13:27:20 +00:00
for line in lines:
if line.startswith("["):
current_section = line.replace("[", "").replace("]", "").replace("\n", "")
2024-05-12 02:05:35 +00:00
elif line.startswith(search_key) and current_section == section and not added:
added = True
2023-11-13 13:27:20 +00:00
line += f'{new_key} = "{new_value}"\n'
out.append(line)
with open(ini_path, "w", encoding="utf-8") as f:
f.writelines(out)
2024-05-12 02:05:35 +00:00
files = os.listdir("./lang/")
files.sort()
for file in files:
2023-11-13 13:27:20 +00:00
if file.endswith(".ini"):
add_new_key("./lang/" + file, sys.argv[1], sys.argv[2], sys.argv[3])