Moin,
Ich hab mal ein kleines Python-Skript geschrieben, welches den Inhalt aller say, say_reward, say_title und send_letter durch eine Variable ersetzt und diese dann in einer extra Datei anlegt.
Perfekt für ML-Systeme =)
Ihr müsst nur googletrans installieren:
Ich nutze Python 3.8
Viel Spaß mit dem Skript.
HINWEIS:
Quest nicht enden mit ..", wenn es keine Variable ist zb.
werden enttäuscht sein..")
Auch erstmal keine ... in den say vorkommen lassen
say("Text... Text.. Text..") ist das pure Gift für das Skript, da weiß es gar nicht, was es tun soll !! Also löschen !
gameforge["en"]. = {} -> Leere Einträge auch löschen -> Fehler (sagt euch aber auch der Root )
Fixxe ich morgen...
Optimierungen und Kritik sind gern erwünscht.
- import glob
- from googletrans import Translator
- translator = Translator()
- source="../../quest"
- questname = []
- for file in glob.glob(source+"/*.quest"):
- questname.append(file.replace(source+"\\",""))
- for file in glob.glob(source+"/*.lua"):
- questname.append(file.replace(source+"\\",""))
- for quest in questname:
- f1 = open(source+"/"+quest, "r")
- startline= f1.readline()
- startlines = []
- startlines.append(startline)
- startlines_cnt = 1
- while("--" in startline or "define" in startline or " " not in startline):
- startline= f1.readline()
- startlines.append(startline)
- startlines_cnt = startlines_cnt + 1
- start = startline.find(" ")+1
- end = startline.find("begin")
- questname = startline[start:end]
- questname = questname.replace(" ","")
- cnt=1
- f_new2 = open("output/translate_de.txt", "a")
- text = "gameforge[\"de\"]."+questname+" = {}"+"\n"
- f_new2.write(text)
- f_new2.close()
- f_new2 = open("output/translate_en.txt", "a")
- text = "gameforge[\"en\"]."+questname+" = {}"+"\n"
- f_new2.write(text)
- f_new2.close()
- f_new = open("output/"+quest, "w")
- for line in startlines:
- f_new.write(line)
- f_new.close()
- f = open(source+"/"+quest, "r")
- for line in f:
- new = None
- for i in range(startlines_cnt):
- line = f.readline()
- while line:
- substringnew = ""
- if( ("say(" in line and not "[" in line and not "(\"\")" in line ) or ( "send_letter(" in line and not "[" in line and not "(\"\")" in line ) or ( "say_title(" in line and not "[" in line and not "(\"\")" in line ) or ( "say_reward(" in line and not "[" in line and not "(\"\")" in line ) or ( "notice_all(" in line and not "[" in line and not "(\"\")" in line ) or ( "notice(" in line and not "[" in line and not "(\"\")" in line ) or ( "chat(" in line and not "[" in line and not "(\"\")" in line )):
- start2 = line.find("(\"") + len("(\"")
- end2 = line.rfind("\")")
- substring = line[start2:end2]
- if("say(\"\"" not in line or "send_letter(\"\"" not in line or "say_title(\"\"" not in line or "say_reward(\"\"" not in line or "notice_all(\"\"" not in line or "notice(\"\"" not in line or "chat(\"\"" not in line):#Filter: say("")
- if("say(\"" in line or "send_letter(\"" in line or "say_title(\"" in line or "say_reward(\"" in line or "notice_all(\"" in line or "notice(\"" in line or "chat(\"" in line):#Filter:say("teststst
- while( "\".." in substring and "..\"" in substring):#Bsp: "Du erhältst "..point.." Fertigkeitspunkte."
- start3 = substring.find("\"..")
- end3 = substring.find("..\"")+len("..\"")
- substringnew = substring[start3:end3]
- substring = substring.replace(substringnew,"%s")
- while ("\" .. " in substring and " .. \"" in substring):
- start31 = substring.find("\" .. ")
- end31 = substring.find(" .. \"")+len(" .. \"")
- substringnew = substring[start31:end31]
- substring = substring.replace(substringnew,"%s")
- while ("\".." in substring):#Bsp: say("Maximal Level: "..tbl.maxlevel)
- start4 = substring.find("\"..")
- end4 = substring.find(")")+len(")")
- substringnew = substring[start4:end4]
- substring = substring.replace(substringnew,"%s")
- if(len(substringnew)>3):
- substringnew=substringnew.replace("\"","")
- string = "gameforge[get_language()]."+questname+"_say_"+str(cnt)+","+substringnew
- substringnew = ""
- else:
- string = "gameforge[get_language()]."+questname+"_say_"+str(cnt)
- f_new2 = open("output/translate_de.txt", "a", encoding="ansi")
- text = "gameforge[\"de\"]."+questname+"_say_"+str(cnt)+" = \""+substring+"\"\n"
- text=text.replace("\t","")
- f_new2.writelines(text)
- f_new2.close()
- translated = translator.translate(substring, src='de', dest='en')
- f_new2 = open("output/translate_en.txt", "a", encoding="ansi")
- text = "gameforge[\"en\"]."+questname+"_say_"+str(cnt)+" = \""+str(translated.text)+"\"\n"
- text=text.replace("\t","")
- f_new2.writelines(text)
- f_new2.close()
- if( "\".." in line and "..\"" in line):#Bsp: "Du erhältst "..point.." Fertigkeitspunkte."
- start5 = line.find("\"..")
- end5 = line.find("..\"")+len("..\"")
- linenew = line[start5:end5]
- line = line.replace(linenew,"%s")
- elif (".." in substring):#Bsp: "Minimal Level: "..tbl.minlevel")"
- start6 = line.find("..") + len("..")
- end6 = line.find("\"")
- linenew = line[start6:end6]
- line = line.replace(linenew,"%s")
- line = line.replace(substring,string)
- f_new = open("output/"+quest, "a", encoding="ansi")
- if("say" in line or "send_letter" in line or "say_title" in line or "say_reward" in line or "notice" in line or "notice_all" in line or "chat" in line):
- if("select" not in line and "when" not in line and "timer" not in line ):
- if not( ".." in line and "gameforge" not in line):
- if("d:" not in line):
- if("string.format" not in line):
- line = line.replace("\"","")
- if("gameforge" in line and ".." in line):
- line = line.replace("..","")
- f_new.write(line)
- f_new.close()
- line = f.readline()
- cnt=cnt+1
Hier der Code, der eine translate.lua von "von" nach "nach" übersetzt. Die Variablen könnt ihr am Anfang beliebig anpassen.
@'Asasel
- import glob
- from googletrans import Translator
- translator = Translator()
- von = "de"
- nach = "en"
- f_new2 = open("translate_"+nach+".lua", "w")
- text = "gameforge[\""+nach+"\"] = {}\n"
- f_new2.writelines(text)
- f_new2.close()
- f = open("translate.lua", "r")
- for line in f:
- new = None
- line = f.readline()#skip 1 line
- line = f.readline()
- while line:
- start = line.find("].")+len("].")
- end = line.find(" = ")
- name = line[start:end]
- start2 = line.find(" = ") + len(" = ")
- end2 = line.find("\"\n")
- substring = line[start2:end2]
- f_new2 = open("translate_"+nach+".lua", "a",encoding="utf-8")
- if ("\"" in substring):#Filter beginn eines Abschnittes ("= {}")
- substring = substring.replace("\"","")
- if(len(substring)>3):#Filter nach leeren Abschnitten ("")
- translated = translator.translate(substring, src=von, dest=nach)
- text = "gameforge[\""+nach+"\"]."+name+" = \""+str(translated.text)+"\"\n"
- else:
- text = "gameforge[\""+nach+"\"]."+name+" = \"\"\n"
- else:
- text = "gameforge[\"en\"]."+name+" = {}\n"
- f_new2.writelines(text)
- f_new2.close()
- line = f.readline()