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