diff --git a/LunaTranslator/LunaTranslator/gui/settingpage_cishu.py b/LunaTranslator/LunaTranslator/gui/settingpage_cishu.py index e2ce4467..d6a81430 100644 --- a/LunaTranslator/LunaTranslator/gui/settingpage_cishu.py +++ b/LunaTranslator/LunaTranslator/gui/settingpage_cishu.py @@ -25,14 +25,18 @@ def gethiragrid(self) : getsimpleswitch(globalconfig['hirasetting'][name],'use',parent=self,name=name,callback=functools.partial(yuitsu_switch,self,globalconfig['hirasetting'],'hiraswitchs',name,gobject.baseobject.starthira),pair='hiraswitchs'), ] - if 'path' in globalconfig['hirasetting'][name]: - line+=[getcolorbutton(globalconfig,'',callback=functools.partial(getsomepath1,self,globalconfig['hirasetting'][name]['name'],globalconfig['hirasetting'][name], 'path',globalconfig['hirasetting'][name]['name'],gobject.baseobject.starthira,True),icon='fa.gear',constcolor="#FF69B4")] - elif 'token' in globalconfig['hirasetting'][name] and 'token_name' in globalconfig['hirasetting'][name]: - items=[{ - 't':'lineedit','l': globalconfig['hirasetting'][name]['token_name'],'d':globalconfig['hirasetting'][name],'k':'token' - }, - {'t':'okcancel' }] - line+=[getcolorbutton(globalconfig,'',callback= functools.partial(autoinitdialog,self, globalconfig['hirasetting'][name]['name'],800,items) ,icon='fa.gear',constcolor="#FF69B4")] + items=[] + for key in globalconfig['hirasetting'][name]: + if key=='path': + items.append({'t':'file','l':globalconfig['hirasetting'][name]['name'],'d':globalconfig['hirasetting'][name],'k':'path','dir':True}) + elif key=='token': + items.append({'t':'lineedit','l': globalconfig['hirasetting'][name]['token_name'],'d':globalconfig['hirasetting'][name],'k':'token'}) + elif key=='codec': + items.append({'t':'combo','l': 'codec','d':globalconfig['hirasetting'][name],'k':'codec','list':['utf8','shiftjis']}) + if len(items): + items.append({'t':'okcancel','callback':gobject.baseobject.starthira}) + line+=[getcolorbutton(globalconfig,'',callback= functools.partial(autoinitdialog,self, globalconfig['hirasetting'][name]['name'],800,items) ,icon='fa.gear',constcolor="#FF69B4")] + else: line+=[''] if i%3==2 : diff --git a/LunaTranslator/LunaTranslator/hiraparse/mecab.py b/LunaTranslator/LunaTranslator/hiraparse/mecab.py index acf73ad4..b2937699 100644 --- a/LunaTranslator/LunaTranslator/hiraparse/mecab.py +++ b/LunaTranslator/LunaTranslator/hiraparse/mecab.py @@ -16,7 +16,8 @@ class hira: def fy(self,text): start=0 result=[] - for node,fields in self.kks.parse( text):# self.kks.parseToNodeList(text): + codec=['utf8','shiftjis'][globalconfig['hirasetting']['mecab']['codec']] + for node,fields in self.kks.parse( text,codec):# self.kks.parseToNodeList(text): if len(fields): pos1=fields[0] if len(fields)>29: @@ -27,6 +28,8 @@ class hira: kana=fields[17] elif len(fields)>9: kana=fields[9] #无kana,用lform代替 + elif len(fields)==9: + kana=fields[8]#7/8均可,issues/514 else: kana='' else: diff --git a/LunaTranslator/LunaTranslator/winsharedutils.py b/LunaTranslator/LunaTranslator/winsharedutils.py index 25e74a44..56f8b82a 100644 --- a/LunaTranslator/LunaTranslator/winsharedutils.py +++ b/LunaTranslator/LunaTranslator/winsharedutils.py @@ -76,16 +76,16 @@ class mecabwrap: self.kks=_mecab_init(mecabpath.encode('utf8'),gobject.GetDllpath('libmecab.dll') ) def __del__(self): _mecab_end(self.kks) - def parse(self,text): + def parse(self,text,codec): surface=POINTER(c_char_p)() feature=POINTER(c_char_p)() num=c_uint() - _mecab_parse(self.kks,text.encode('utf8'),pointer(surface),pointer(feature),pointer(num)) + _mecab_parse(self.kks,text.encode(codec),pointer(surface),pointer(feature),pointer(num)) res=[] for i in range(num.value): f=feature[i] - fields=f.decode('utf8').split(',') - res.append((surface[i].decode('utf8'),fields)) + fields=f.decode(codec).split(',') + res.append((surface[i].decode(codec),fields)) _freestringlist(feature,num.value) _freestringlist(surface,num.value) return res diff --git a/LunaTranslator/files/defaultconfig/config.json b/LunaTranslator/files/defaultconfig/config.json index cdba7509..78d4f384 100644 --- a/LunaTranslator/files/defaultconfig/config.json +++ b/LunaTranslator/files/defaultconfig/config.json @@ -656,7 +656,8 @@ "mecab": { "use": false, "path": "", - "name": "MeCab" + "name": "MeCab", + "codec":0 }, "mojinlt": { "use": false,