some update?
This commit is contained in:
parent
c9bdaf895d
commit
9394aa62d4
@ -36,40 +36,40 @@ class Lang:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, language: str = 'zh-CN'):
|
def __init__(self, language: str = 'zh-CN'):
|
||||||
self.language = language
|
self.语言 = language
|
||||||
self.翻译结果 = tools.load_file(f'configs/lang/{language}.json5')
|
self.翻译结果 = tools.load_file(f'configs/lang/{language}.json5')
|
||||||
self.默认翻译 = tools.load_file('configs/lang/zh-CN.json5')
|
self.默认翻译 = tools.load_file('configs/lang/zh-CN.json5')
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return self.language
|
return self.语言
|
||||||
|
|
||||||
def __getitem__(self, item):
|
def __getitem__(self, item) -> Union[int, str, list, dict]:
|
||||||
try:
|
try:
|
||||||
return self.翻译结果[item]
|
return self.翻译结果[item]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
try:
|
try:
|
||||||
return self.默认翻译[item]
|
return self.默认翻译[item]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise LanguageError(f'there\'s no key {item} in both {self.language} and zh-CN')
|
raise LanguageError(f'there\'s no key {item} in both {self.语言} and zh-CN')
|
||||||
|
|
||||||
def __setitem__(self, key, value):
|
def __setitem__(self, key, value):
|
||||||
if key == 'language' or key == 'lang':
|
if key == 'language' or key == 'lang':
|
||||||
try:
|
try:
|
||||||
self.翻译结果 = tools.load_file(f'configs/lang/{value}.json5')
|
self.翻译结果 = tools.load_file(f'configs/lang/{value}.json5')
|
||||||
self.language = value
|
self.语言 = value
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
raise LanguageError(f'{value}\'s language json5 file not found')
|
raise LanguageError(f'{value}\'s language json5 file not found')
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def set_language(self, language):
|
def set_language(self, language) -> None:
|
||||||
try:
|
try:
|
||||||
self.翻译结果 = tools.load_file(f'configs/lang/{language}.json5')
|
self.翻译结果 = tools.load_file(f'configs/lang/{language}.json5')
|
||||||
self.language = language
|
self.语言 = language
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
raise LanguageError(f'{language}\'s language json5 file not found')
|
raise LanguageError(f'{language}\'s language json5 file not found')
|
||||||
|
|
||||||
def lang(self, *args) -> Union[int, str, list]:
|
def lang(self, *args) -> Union[int, str, list, dict]:
|
||||||
try:
|
try:
|
||||||
结果 = self.翻译结果
|
结果 = self.翻译结果
|
||||||
for 选项 in args:
|
for 选项 in args:
|
||||||
@ -82,10 +82,10 @@ class Lang:
|
|||||||
结果 = 结果[选项]
|
结果 = 结果[选项]
|
||||||
return 结果
|
return 结果
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise LanguageError(f'there\'s no key {args} in both {self.language} and zh-CN')
|
raise LanguageError(f'there\'s no key {args} in both {self.语言} and zh-CN')
|
||||||
|
|
||||||
def 翻译(self, *args):
|
def 翻译(self, *args) -> Union[int, str, list, dict]:
|
||||||
self.lang(args)
|
return self.lang(args)
|
||||||
|
|
||||||
|
|
||||||
tr = Lang('zh-CN')
|
tr = Lang('zh-CN')
|
||||||
|
@ -35,15 +35,15 @@
|
|||||||
},
|
},
|
||||||
'loggers': {
|
'loggers': {
|
||||||
'client': {
|
'client': {
|
||||||
// 'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
'handlers': []
|
'handlers': []
|
||||||
},
|
},
|
||||||
'server': {
|
'server': {
|
||||||
// 'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
'handlers': []
|
'handlers': []
|
||||||
},
|
},
|
||||||
'main': {
|
'main': {
|
||||||
// 'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
'handlers': []
|
'handlers': []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user