mirror of
https://github.com/TriM-Organization/Linglun-Converter.git
synced 2024-11-25 00:25:26 +08:00
可以用了现在
This commit is contained in:
parent
d95b8ad648
commit
1e8ae27fa3
2
.gitignore
vendored
2
.gitignore
vendored
@ -10,6 +10,8 @@ __pycache__/
|
|||||||
*.mcpack
|
*.mcpack
|
||||||
*.bdx
|
*.bdx
|
||||||
*.json
|
*.json
|
||||||
|
/Musicreater
|
||||||
|
/logs
|
||||||
|
|
||||||
# C extensions
|
# C extensions
|
||||||
*.so
|
*.so
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
Copyright © 2023 all the developers of LinglunStudio
|
Copyright © 2023 all the developers of LinglunStudio
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from ..utils.io import *
|
from utils.io import *
|
||||||
|
|
||||||
|
|
||||||
DEFAULTLANGUAGE = 'ZH-CN'
|
DEFAULTLANGUAGE = 'ZH-CN'
|
||||||
@ -92,56 +92,56 @@ languages = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def passbt():
|
||||||
|
|
||||||
|
def __loadLanguage(languageFilename: str):
|
||||||
def __loadLanguage(languageFilename: str):
|
with open(languageFilename, 'r', encoding='utf-8') as languageFile:
|
||||||
with open(languageFilename, 'r', encoding='utf-8') as languageFile:
|
_text = {}
|
||||||
_text = {}
|
for line in languageFile:
|
||||||
for line in languageFile:
|
if line.startswith('#'):
|
||||||
if line.startswith('#'):
|
continue
|
||||||
continue
|
line = line.split(' ', 1)
|
||||||
line = line.split(' ', 1)
|
|
||||||
_text[line[0]] = line[1].replace('\n', '')
|
|
||||||
langkeys = _text.keys()
|
|
||||||
with open(languageFilename.replace(languageFilename[-10:-5], 'ZH-CN'), 'r', encoding='utf-8') as defaultLangFile:
|
|
||||||
for line in defaultLangFile:
|
|
||||||
if line.startswith('#'):
|
|
||||||
continue
|
|
||||||
line = line.split(' ', 1)
|
|
||||||
if not line[0] in langkeys:
|
|
||||||
_text[line[0]] = line[1].replace('\n', '')
|
_text[line[0]] = line[1].replace('\n', '')
|
||||||
logger.warning(f'丢失对于 {line[0]} 的本地化文本',)
|
langkeys = _text.keys()
|
||||||
langkeys = _text.keys()
|
with open(languageFilename.replace(languageFilename[-10:-5], 'ZH-CN'), 'r', encoding='utf-8') as defaultLangFile:
|
||||||
# print(_text)
|
for line in defaultLangFile:
|
||||||
return _text
|
if line.startswith('#'):
|
||||||
|
continue
|
||||||
|
line = line.split(' ', 1)
|
||||||
|
if not line[0] in langkeys:
|
||||||
|
_text[line[0]] = line[1].replace('\n', '')
|
||||||
|
logger.warning(f'丢失对于 {line[0]} 的本地化文本',)
|
||||||
|
langkeys = _text.keys()
|
||||||
|
# print(_text)
|
||||||
|
return _text
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if DEFAULTLANGUAGE in LANGUAGELIST.keys():
|
if DEFAULTLANGUAGE in LANGUAGELIST.keys():
|
||||||
_TEXT = __loadLanguage('./languages/' + DEFAULTLANGUAGE + '.lang')
|
_TEXT = __loadLanguage('./languages/' + DEFAULTLANGUAGE + '.lang')
|
||||||
else:
|
else:
|
||||||
logger.error(f"无法打开当前本地化文本{DEFAULTLANGUAGE}")
|
logger.error(f"无法打开当前本地化文本{DEFAULTLANGUAGE}")
|
||||||
raise KeyError(f'无法打开默认语言{DEFAULTLANGUAGE}')
|
raise KeyError(f'无法打开默认语言{DEFAULTLANGUAGE}')
|
||||||
|
|
||||||
|
|
||||||
def wordTranslate(singleWord: str, debug: bool = False):
|
def wordTranslate(singleWord: str, debug: bool = False):
|
||||||
try:
|
try:
|
||||||
return \
|
return \
|
||||||
requests.post('https://fanyi.baidu.com/sug', data={'kw': f'{singleWord}'}).json()['data'][0]['v'].split(
|
requests.post('https://fanyi.baidu.com/sug', data={'kw': f'{singleWord}'}).json()['data'][0]['v'].split(
|
||||||
'; ')[0]
|
'; ')[0]
|
||||||
except:
|
except:
|
||||||
logger.warning(f"无法翻译文本{singleWord}",)
|
logger.warning(f"无法翻译文本{singleWord}",)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _(text: str, debug: bool = False):
|
def _(text: str, debug: bool = False):
|
||||||
try:
|
try:
|
||||||
return _TEXT[text]
|
return _TEXT[text]
|
||||||
except:
|
except:
|
||||||
if debug:
|
if debug:
|
||||||
raise KeyError(f'无法找到本地化文本{text}')
|
raise KeyError(f'无法找到本地化文本{text}')
|
||||||
else:
|
else:
|
||||||
logger.warning(f'无法找到本地化文本{text}',)
|
logger.warning(f'无法找到本地化文本{text}',)
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ osc.version = __version__
|
|||||||
|
|
||||||
|
|
||||||
def go_for_args(
|
def go_for_args(
|
||||||
languageChange: str = "ZH-CN", debugMode: str = False, logfile: str = True
|
languageChange: str = "ZH-CN", debugMode: str = 'False', logfile: str = 'True'
|
||||||
):
|
):
|
||||||
global currentLang
|
global currentLang
|
||||||
global logger
|
global logger
|
||||||
|
Loading…
Reference in New Issue
Block a user