diff --git a/Translation merger/Merger.py b/Translation merger/Merger.py new file mode 100644 index 0000000..696046f --- /dev/null +++ b/Translation merger/Merger.py @@ -0,0 +1,92 @@ +from os import listdir +import re + +def is_menu_string(s): + # Matches strings that look like "translate * strings:" for the menus + pattern = r'translate\s+\w+\s+strings:' + return re.match(pattern, s) + + +def parse(lines,cont): + menu_line = False + temp_cont = [] + for line in lines: + if menu_line or is_menu_string(line): + menu_line = True + if len(temp_cont) != 0: + cont.append(temp_cont) + temp_cont = [] + # We reached the menu, everything below this point doesn't need change + menu_block.append(line) + elif line.startswith("translate") and not is_menu_string(line): + # We've reached a new dialogue block so we "save" the old one + if len(temp_cont) != 0: + cont.append(temp_cont) + temp_cont = [] + temp_cont.append(line) + else: + temp_cont.append(line) + + +for file in listdir(f"files_old"): + + dialogue_blocks_old = [] + dialogue_blocks_new = [] + menu_block = [] + out_lines = [] + linesNew = [] + linesOld = [] + + if file.endswith(".rpy"): + with open(f"files_old/{file}",'r', encoding="utf8") as f: + linesOld = f.readlines() + with open(f"files_new/{file}",'r', encoding="utf8") as f2: + linesNew = f2.readlines() + + parse(linesNew,dialogue_blocks_new) + parse(linesOld,dialogue_blocks_old) + print(menu_block) + + if len(dialogue_blocks_old) != len(dialogue_blocks_new): + print(f"ERROR processing {file}.\nThere's a mismatch in the dialogue blocks.\nCopy paste the missing dialogue blocks into your old translation file to properly merge them\n{len(dialogue_blocks_new)}/{len(dialogue_blocks_old)}") + else: + for num1,block in enumerate(dialogue_blocks_old): + for num2,line in enumerate(block): + if num2 == 0: + out_lines.append(dialogue_blocks_new[num1][0]) + else: + out_lines.append(line) + + out_lines = out_lines + menu_block + + with open(f"files_out/{file}",'w', encoding="utf8") as fo: + for line in out_lines: + fo.write(line) + + +############################## +""" + +Translation blocks follow this structure + +#comment +translate lang id: + #comment + "Dialogue" + +But we cannot use comments or line numbers to determine what a block is as a translator +may add internal translation notes using comments, not to mention that a translation block +can have more than one dialogue line. + +Menus or interpolated strings (Such as screens) on the other hand look like this + +translate lang strings: + + # comment + old "Untranslated text" + new "Translated text" + +Since these don't use IDs we don't care to "update" them and just pass on the old menus instead + +""" +############################## \ No newline at end of file diff --git a/Translation merger/Translation merger.py b/Translation merger/Translation merger.py deleted file mode 100644 index 3e662a1..0000000 --- a/Translation merger/Translation merger.py +++ /dev/null @@ -1,42 +0,0 @@ -############################################################################################################################ -# 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 diff --git a/Translation merger/files_new/new files go here b/Translation merger/files_new/new files go here new file mode 100644 index 0000000..e69de29 diff --git a/Translation merger/files_old/old files go here b/Translation merger/files_old/old files go here new file mode 100644 index 0000000..e69de29 diff --git a/Translation merger/files_out/output files go here b/Translation merger/files_out/output files go here new file mode 100644 index 0000000..e69de29