mirror of
https://github.com/TriM-Organization/Linglun-Converter.git
synced 2024-11-25 00:25:26 +08:00
update 2023/2/12 bug fixed
This commit is contained in:
parent
82328efaaf
commit
a466143382
@ -1,25 +1,24 @@
|
|||||||
# -*- coding:utf-8 -*-
|
# -*- coding:utf-8 -*-
|
||||||
'''对于伶伦的语言支持兼语言文件编辑器'''
|
"""对于伶伦的语言支持兼语言文件编辑器"""
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Copyright © 2023 all the developers of LinglunStudio
|
Copyright © 2023 all the developers of LinglunStudio
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from utils.io import *
|
from utils.io import logger, requests
|
||||||
|
|
||||||
|
DEFAULTLANGUAGE = "ZH-CN"
|
||||||
DEFAULTLANGUAGE = 'ZH-CN'
|
|
||||||
|
|
||||||
LANGUAGELIST = {
|
LANGUAGELIST = {
|
||||||
# 第一个是语言的中文名称和地区
|
# 第一个是语言的中文名称和地区
|
||||||
# 第二个是语言的英文名称和地区
|
# 第二个是语言的英文名称和地区
|
||||||
# 第三个是语言的本地名称和地区
|
# 第三个是语言的本地名称和地区
|
||||||
'ZH-CN': (
|
"ZH-CN": (
|
||||||
"简体中文 中国大陆",
|
"简体中文 中国大陆",
|
||||||
"Simplified Chinese - China Mainland",
|
"Simplified Chinese - China Mainland",
|
||||||
"简体中文 中国大陆",
|
"简体中文 中国大陆",
|
||||||
),
|
),
|
||||||
'ZH-TW': (
|
"ZH-TW": (
|
||||||
"繁体中文 中国台湾省",
|
"繁体中文 中国台湾省",
|
||||||
"Traditional Chinese - Taiwan Province, China",
|
"Traditional Chinese - Taiwan Province, China",
|
||||||
"正體中文,中国台灣省",
|
"正體中文,中国台灣省",
|
||||||
@ -34,19 +33,14 @@ LANGUAGELIST = {
|
|||||||
# "Traditional Chinese - Macau SAR",
|
# "Traditional Chinese - Macau SAR",
|
||||||
# "繁體中文,澳門特別行政區",
|
# "繁體中文,澳門特別行政區",
|
||||||
# ),
|
# ),
|
||||||
'EN-GB': (
|
"EN-GB": (
|
||||||
"英语 英国",
|
"英语 英国",
|
||||||
"British English - the United Kingdom",
|
"British English - the United Kingdom",
|
||||||
"British English - the United Kingdom",
|
"British English - the United Kingdom",
|
||||||
),
|
),
|
||||||
'ZH-ME' : (
|
"ZH-ME": ("喵喵文 中国大陆", "Meow Catsnese - China Mainland" "喵喵喵~ 种花家~"),
|
||||||
"喵喵文 中国大陆",
|
|
||||||
"Meow Catsnese - China Mainland"
|
|
||||||
"喵喵喵~ 种花家~"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
languages = {
|
languages = {
|
||||||
"ZH-CN": {
|
"ZH-CN": {
|
||||||
"MSCT": "音·创",
|
"MSCT": "音·创",
|
||||||
@ -92,56 +86,64 @@ languages = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def passbt():
|
|
||||||
|
|
||||||
|
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', '')
|
_text[line[0]] = line[1].replace("\n", "")
|
||||||
langkeys = _text.keys()
|
langkeys = _text.keys()
|
||||||
with open(languageFilename.replace(languageFilename[-10:-5], 'ZH-CN'), 'r', encoding='utf-8') as defaultLangFile:
|
with open(
|
||||||
|
languageFilename.replace(languageFilename[-10:-5], "ZH-CN"),
|
||||||
|
"r",
|
||||||
|
encoding="utf-8",
|
||||||
|
) as defaultLangFile:
|
||||||
for line in defaultLangFile:
|
for line in defaultLangFile:
|
||||||
if line.startswith('#'):
|
if line.startswith("#"):
|
||||||
continue
|
continue
|
||||||
line = line.split(' ', 1)
|
line = line.split(" ", 1)
|
||||||
if not line[0] in langkeys:
|
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]} 的本地化文本',)
|
logger.warning(
|
||||||
|
f"丢失对于 {line[0]} 的本地化文本",
|
||||||
|
)
|
||||||
langkeys = _text.keys()
|
langkeys = _text.keys()
|
||||||
# print(_text)
|
# print(_text)
|
||||||
return _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(
|
||||||
'; ')[0]
|
"https://fanyi.baidu.com/sug", data={"kw": f"{singleWord}"}
|
||||||
|
)
|
||||||
|
.json()["data"][0]["v"]
|
||||||
|
.split("; ")[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(
|
||||||
return ''
|
f"无法找到本地化文本{text}",
|
||||||
|
)
|
||||||
|
return ""
|
||||||
|
@ -27,7 +27,7 @@ print("https://dislink.github.io/midi2bdx/")
|
|||||||
import Musicreater
|
import Musicreater
|
||||||
|
|
||||||
# 这一句可以不要,因为lang里面已经有了
|
# 这一句可以不要,因为lang里面已经有了
|
||||||
# from utils.io import *
|
from utils.io import *
|
||||||
from languages.lang import *
|
from languages.lang import *
|
||||||
|
|
||||||
MainConsole.print(
|
MainConsole.print(
|
||||||
|
Loading…
Reference in New Issue
Block a user