From 1e8ae27fa3fa3f041761d61b06750b89bcd5cce0 Mon Sep 17 00:00:00 2001 From: Eilles Date: Sun, 5 Feb 2023 17:45:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E7=94=A8=E4=BA=86=E7=8E=B0?= =?UTF-8?q?=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ languages/lang.py | 86 +++++++++++++++++++++++------------------------ llc_cli.py | 2 +- 3 files changed, 46 insertions(+), 44 deletions(-) diff --git a/.gitignore b/.gitignore index 609781d..2edaf21 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,8 @@ __pycache__/ *.mcpack *.bdx *.json +/Musicreater +/logs # C extensions *.so diff --git a/languages/lang.py b/languages/lang.py index 75c5d06..b0dc151 100644 --- a/languages/lang.py +++ b/languages/lang.py @@ -5,7 +5,7 @@ Copyright © 2023 all the developers of LinglunStudio """ -from ..utils.io import * +from utils.io import * DEFAULTLANGUAGE = 'ZH-CN' @@ -92,56 +92,56 @@ languages = { } } +def passbt(): - -def __loadLanguage(languageFilename: str): - with open(languageFilename, 'r', encoding='utf-8') as languageFile: - _text = {} - for line in languageFile: - if line.startswith('#'): - continue - 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: + def __loadLanguage(languageFilename: str): + with open(languageFilename, 'r', encoding='utf-8') as languageFile: + _text = {} + for line in languageFile: + if line.startswith('#'): + continue + line = line.split(' ', 1) _text[line[0]] = line[1].replace('\n', '') - logger.warning(f'丢失对于 {line[0]} 的本地化文本',) - langkeys = _text.keys() - # print(_text) - return _text + 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', '') + logger.warning(f'丢失对于 {line[0]} 的本地化文本',) + langkeys = _text.keys() + # print(_text) + return _text -if DEFAULTLANGUAGE in LANGUAGELIST.keys(): - _TEXT = __loadLanguage('./languages/' + DEFAULTLANGUAGE + '.lang') -else: - logger.error(f"无法打开当前本地化文本{DEFAULTLANGUAGE}") - raise KeyError(f'无法打开默认语言{DEFAULTLANGUAGE}') + if DEFAULTLANGUAGE in LANGUAGELIST.keys(): + _TEXT = __loadLanguage('./languages/' + DEFAULTLANGUAGE + '.lang') + else: + logger.error(f"无法打开当前本地化文本{DEFAULTLANGUAGE}") + raise KeyError(f'无法打开默认语言{DEFAULTLANGUAGE}') -def wordTranslate(singleWord: str, debug: bool = False): - try: - return \ - requests.post('https://fanyi.baidu.com/sug', data={'kw': f'{singleWord}'}).json()['data'][0]['v'].split( - '; ')[0] - except: - logger.warning(f"无法翻译文本{singleWord}",) - return None + def wordTranslate(singleWord: str, debug: bool = False): + try: + return \ + requests.post('https://fanyi.baidu.com/sug', data={'kw': f'{singleWord}'}).json()['data'][0]['v'].split( + '; ')[0] + except: + logger.warning(f"无法翻译文本{singleWord}",) + return None -def _(text: str, debug: bool = False): - try: - return _TEXT[text] - except: - if debug: - raise KeyError(f'无法找到本地化文本{text}') - else: - logger.warning(f'无法找到本地化文本{text}',) - return '' + def _(text: str, debug: bool = False): + try: + return _TEXT[text] + except: + if debug: + raise KeyError(f'无法找到本地化文本{text}') + else: + logger.warning(f'无法找到本地化文本{text}',) + return '' diff --git a/llc_cli.py b/llc_cli.py index f1510d3..09931bb 100644 --- a/llc_cli.py +++ b/llc_cli.py @@ -43,7 +43,7 @@ osc.version = __version__ 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 logger