简单修改国际化支持

This commit is contained in:
EillesWan 2022-03-13 22:29:57 +08:00
parent 96e6bc2f7a
commit 954a30f722
2 changed files with 49 additions and 9 deletions

View File

@ -38,14 +38,52 @@ LANGUAGELIST = {
# 重构之后将停止使用
from languages.zhCN import READABLETEXT
from msctLib.log import log
if not DEFAULTLANGUAGE == 'zh-CN':
if DEFAULTLANGUAGE in LANGUAGELIST.keys():
with open('./languages/'+DEFAULTLANGUAGE+'.lang','r',encoding='utf-8') as languageFile :
_text = []
_text = {}
for line in languageFile:
_text.append(line)
line = line.split(' ')
_text.append[line[0]] = line[1]
langkeys = _text.keys()
with open('./languages/zh-CN.lang','r',encoding='utf-8') as defaultLangFile:
for line in defaultLangFile:
line = line.split(' ')
if not line[0] in langkeys:
_text[line[0]] = line[1]
log(f'丢失对于 {line[0]} 的本地化文本','WARRING')
langkeys = _text.keys()
_TEXT = _text.copy()
else:
raise KeyError(f"无法打开默认语言{DEFAULTLANGUAGE}")
raise KeyError(f'无法打开默认语言{DEFAULTLANGUAGE}')
def wordTranslate(singleWord:str,debug: bool = False):
import requests
try:
return requests.post('https://fanyi.baidu.com/sug', data={'kw': f'{singleWord}'}).json()['data'][0]['v'].split('; ')[0]
except:
log(f"无法翻译文本{singleWord}",level='WARRING',isPrinted=debug)
return None
def _(text:str):
try:
return _TEXT[text]
except:
raise KeyError(f'无法找到翻译文本{text}')
@ -62,3 +100,5 @@ if __name__ == '__main__':

View File

@ -93,7 +93,7 @@ class report:
class version:
libraries = (
'mido', 'amulet', 'amulet-core', 'amulet-nbt', 'piano_transcription_inference', 'pypinyin',
'pyinstaller','py7zr','websockets', 'torch'
'pyinstaller','py7zr','websockets', 'torch','requests'
)
"""当前所需库,有一些是开发用的,用户不需要安装"""