Files
Trans_tools/Translation merger/Translation merger.py
2022-12-29 03:36:36 -03:00

43 lines
1.8 KiB
Python

############################################################################################################################
# This script simply places the strings from files_old into files_new. This is useful if for some reason the labels in the #
# script changed and you needed to regenerate the translations, or if you already translated the game without using the #
# built-in translation system. #
# #
# Make sure that both files have the same ammount of lines. Then, simply place the old files into files_old #
# And the new files into files_new. #
############################################################################################################################
####
# This shit sucks. But it works (As long as you didn't add any extra lines to the translation file)
####
from os import listdir
nextOne = False
for file in listdir(f"files_old"):
if file.endswith(".rpy"):
with open(f"files_old/{file}",'r', encoding="utf8") as f:
linesOne = f.readlines()
with open(f"files_new/{file}",'r', encoding="utf8") as f2:
linesTwo = f2.readlines()
if len(linesOne) == len(linesTwo):
with open(f"files_out/{file}",'w', encoding="utf8") as fp:
for number,line in enumerate(linesOne):
if nextOne:
fp.write(linesOne[number])
nextOne = False
elif line.strip().startswith("old"):
nextOne = True
fp.write(linesTwo[number])
print("nuevo",number)
elif number % 6 == 0:
fp.write(linesOne[number])
else:
fp.write(linesTwo[number])
print("novo",number,linesTwo[number])
else:
print(f"ERROR processing {file}. There's a discrepancy in the lines. old: {len(linesOne)} - new: {len(linesTwo)}\n\n")
continue