mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 16:44:13 +08:00
.
This commit is contained in:
parent
bf6a098ef9
commit
2161dfb86e
@ -9,16 +9,16 @@ import gobject
|
||||
class TS(basetrans):
|
||||
def checkfilechanged(self, p1, p):
|
||||
if self.paths != (p1, p):
|
||||
self.json = {}
|
||||
self.jsons = []
|
||||
if p:
|
||||
for pp in p:
|
||||
if os.path.exists(pp):
|
||||
with open(pp, "r", encoding="utf8") as f:
|
||||
self.json.update(json.load(f))
|
||||
self.jsons.append(json.load(f))
|
||||
if p1:
|
||||
if os.path.exists(p1):
|
||||
with open(p1, "r", encoding="utf8") as f:
|
||||
self.json.update(json.load(f))
|
||||
self.jsons.append(json.load(f))
|
||||
self.paths = (p1, p)
|
||||
|
||||
def unsafegetcurrentgameconfig(self):
|
||||
@ -32,50 +32,51 @@ class TS(basetrans):
|
||||
def inittranslator(self):
|
||||
self.paths = (None, None)
|
||||
self.checkfilechanged(
|
||||
self.unsafegetcurrentgameconfig(), self.config["jsonfile"]
|
||||
self.unsafegetcurrentgameconfig(), tuple(self.config["jsonfile"])
|
||||
)
|
||||
|
||||
def translate(self, content):
|
||||
self.checkfilechanged(
|
||||
self.unsafegetcurrentgameconfig(), self.config["jsonfile"]
|
||||
self.unsafegetcurrentgameconfig(), tuple(self.config["jsonfile"])
|
||||
)
|
||||
collect = []
|
||||
if globalconfig["premtsimiuse"]:
|
||||
for _js in self.jsons:
|
||||
maxsim = 0
|
||||
savet = None
|
||||
for jc in self.json:
|
||||
for jc in _js:
|
||||
dis = winsharedutils.distance_ratio(content, jc)
|
||||
if dis > maxsim:
|
||||
maxsim = dis
|
||||
if maxsim * 100 >= globalconfig["premtsimi2"]:
|
||||
if type(self.json[jc]) == str:
|
||||
savet = self.json[jc]
|
||||
elif (
|
||||
self.json[jc]["userTrans"]
|
||||
and self.json[jc]["userTrans"] != ""
|
||||
):
|
||||
savet = self.json[jc]["userTrans"]
|
||||
if type(_js[jc]) == str:
|
||||
savet = _js[jc]
|
||||
elif _js[jc]["userTrans"] and _js[jc]["userTrans"] != "":
|
||||
savet = _js[jc]["userTrans"]
|
||||
|
||||
elif (
|
||||
self.json[jc]["machineTrans"]
|
||||
and self.json[jc]["machineTrans"] != ""
|
||||
_js[jc]["machineTrans"]
|
||||
and _js[jc]["machineTrans"] != ""
|
||||
):
|
||||
savet = self.json[jc]["machineTrans"]
|
||||
savet = _js[jc]["machineTrans"]
|
||||
if savet is None:
|
||||
raise Exception(f"can't find: {content}")
|
||||
return savet
|
||||
continue
|
||||
else:
|
||||
if content not in self.json:
|
||||
raise Exception(f"can't find: {content}")
|
||||
if type(self.json[content]) == str:
|
||||
return self.json[content]
|
||||
elif (
|
||||
self.json[content]["userTrans"]
|
||||
and self.json[content]["userTrans"] != ""
|
||||
):
|
||||
return self.json[content]["userTrans"]
|
||||
collect.append(savet)
|
||||
|
||||
else:
|
||||
for _js in self.jsons:
|
||||
if content not in _js:
|
||||
continue
|
||||
if type(_js[content]) == str:
|
||||
collect.append(_js[content])
|
||||
elif _js[content]["userTrans"] and _js[content]["userTrans"] != "":
|
||||
collect.append(_js[content]["userTrans"])
|
||||
|
||||
elif (
|
||||
self.json[content]["machineTrans"]
|
||||
and self.json[content]["machineTrans"] != ""
|
||||
_js[content]["machineTrans"] and _js[content]["machineTrans"] != ""
|
||||
):
|
||||
return self.json[content]["machineTrans"]
|
||||
collect.append(_js[content]["machineTrans"])
|
||||
if len(collect) == 0:
|
||||
raise Exception(f"can't find: {content}")
|
||||
return "\n".join(collect)
|
||||
|
Loading…
x
Reference in New Issue
Block a user