Last active
April 18, 2023 12:09
-
-
Save snowyegret23/12bf7e9fbe1f5d25979c72b5e94ac525 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
def export_csv(poname, csvname): | |
with open(poname, "r", encoding="utf-8") as f: | |
po_data = f.read().split("\n\n") | |
del po_data[0] | |
with open(csvname, "w", encoding="utf-8-sig", newline="") as f: | |
writer = csv.writer(f) | |
for i in po_data: | |
ar = i.strip().split("\n") | |
msgctxt = ar[0].strip()[9:-1] | |
# msgid = ar[1].strip()[7:-1] | |
msgstr = ar[2].strip()[8:-1] | |
if "DialogText" in msgctxt: | |
writer.writerow([msgctxt, msgstr]) | |
def return_text(csv_list): | |
try: | |
return csv_list[2].strip("\n") | |
except: | |
return csv_list[1].strip("\n") | |
def import_csv(csvname, poname): | |
po_reader = open(poname, "r", encoding="utf-8") | |
po_writer = open(f"{poname[:-3]}_edit.po", "w", encoding="utf-8", newline="\n") | |
with open(csvname, "r", encoding="utf-8-sig", newline="") as f: | |
csv_data = list(csv.reader(f)) | |
po_data = po_reader.read().split("\n\n") | |
header = po_data.pop(0) | |
csv_msgc = [i[0] for i in csv_data] | |
csv_msgs = [return_text(i) for i in csv_data] | |
po_writer.write(header + "\n") | |
for i in po_data: | |
ar = i.strip().split("\n") | |
msgctxt = ar[0].strip("\n")[9:-1] | |
msgid = ar[1].strip("\n") | |
msgstr = ar[2].strip("\n")[8:-1] | |
po_writer.write("\n") | |
po_writer.write('msgctxt "' + msgctxt + '"' + "\n") | |
po_writer.write(msgid + "\n") | |
if "DialogText" in msgctxt: | |
tran_index = csv_msgc.index(msgctxt) | |
po_writer.write('msgstr "' + csv_msgs[tran_index] + '"' + "\n") | |
else: | |
po_writer.write('msgstr "' + msgstr + '"' + "\n") | |
po_reader.close() | |
po_writer.close() | |
poname = "cutscene_dialog.po" | |
csvname = "cutscene_dialog.csv" | |
print(f"po: {poname} / csv:{csvname}") | |
# export_csv(poname, csvname) | |
import_csv(csvname, poname) | |
input("작업 완료! 엔터를 눌러 종료하세요.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment