diff --git a/LunaTranslator/LunaTranslator/LunaTranslator.py b/LunaTranslator/LunaTranslator/LunaTranslator.py index 7189f633..53a031b9 100644 --- a/LunaTranslator/LunaTranslator/LunaTranslator.py +++ b/LunaTranslator/LunaTranslator/LunaTranslator.py @@ -126,6 +126,7 @@ class MAINUI: def solvebeforetrans(self, content): contexts = [] + self.zhanweifu = 0 for i in range(len(self.processmethods)): try: if self.processmethods[i].using: diff --git a/LunaTranslator/LunaTranslator/transoptimi/gongxiangcishu.py b/LunaTranslator/LunaTranslator/transoptimi/gongxiangcishu.py index 112fd235..2937e7d1 100644 --- a/LunaTranslator/LunaTranslator/transoptimi/gongxiangcishu.py +++ b/LunaTranslator/LunaTranslator/transoptimi/gongxiangcishu.py @@ -2,6 +2,8 @@ from myutils.config import globalconfig import xml.etree.ElementTree as ET import os, gobject, re +___idx = 1 + def vnrshareddict(self): @@ -102,6 +104,7 @@ class Process: vnrshareddict(self) def process_before(self, content): + ___idx = 1 self.checkchange() context = {} @@ -116,7 +119,12 @@ class Process: # if self.vnrshareddict[key]['src']==self.vnrshareddict[key]['tgt']: # content=content.replace(key,self.vnrshareddict[key]['text']) # else: - xx = "{{{}}}".format(gobject.baseobject.zhanweifu) + if ___idx == 1: + xx = "ZX{}Z".format(chr(ord("B") + gobject.baseobject.zhanweifu)) + elif ___idx == 2: + xx = "{{{}}}".format(gobject.baseobject.zhanweifu) + elif ___idx == 3: + xx = key content = content.replace(key, xx) context[xx] = key gobject.baseobject.zhanweifu += 1 diff --git a/LunaTranslator/LunaTranslator/transoptimi/noundict.py b/LunaTranslator/LunaTranslator/transoptimi/noundict.py index a597e4d0..3c415b93 100644 --- a/LunaTranslator/LunaTranslator/transoptimi/noundict.py +++ b/LunaTranslator/LunaTranslator/transoptimi/noundict.py @@ -2,44 +2,40 @@ from myutils.config import noundictconfig import gobject, re + + class Process: def process_before(self, content): - + ___idx = 1 mp1 = {} for key in noundictconfig["dict"]: - usedict = False + v = None if type(noundictconfig["dict"][key]) == str: - usedict = True + v = noundictconfig["dict"][mp1[key]] else: for i in range(len(noundictconfig["dict"][key]) // 2): if noundictconfig["dict"][key][i * 2] in [ "0", gobject.baseobject.currentmd5, ]: - usedict = True + v = noundictconfig["dict"][key][i * 2 + 1] break - if usedict and key in content: - xx = "{{{}}}".format(gobject.baseobject.zhanweifu) + if v is not None and key in content: + if ___idx == 1: + xx = "ZX{}Z".format(chr(ord("B") + gobject.baseobject.zhanweifu)) + elif ___idx == 2: + xx = "{{{}}}".format(gobject.baseobject.zhanweifu) + elif ___idx == 3: + xx = v content = content.replace(key, xx) - mp1[xx] = key + mp1[xx] = v gobject.baseobject.zhanweifu += 1 return content, mp1 def process_after(self, res, mp1): for key in mp1: reg = re.compile(re.escape(key), re.IGNORECASE) - if type(noundictconfig["dict"][mp1[key]]) == str: - v = noundictconfig["dict"][mp1[key]] - elif type(noundictconfig["dict"][mp1[key]]) == list: - v = "" - for i in range(len(noundictconfig["dict"][mp1[key]]) // 2): - if noundictconfig["dict"][mp1[key]][i * 2] in [ - "0", - gobject.baseobject.currentmd5, - ]: - v = noundictconfig["dict"][mp1[key]][i * 2 + 1] - break - res = reg.sub(v, res) + res = reg.sub(mp1[key], res) return res