mirror of
https://github.com/TriM-Organization/LiteyukiBot-TriM.git
synced 2024-11-28 16:24:51 +08:00
feat: 新版本
This commit is contained in:
parent
321f19953d
commit
90e059af32
@ -103,12 +103,10 @@ def load_from_dict(data: dict, lang_code: str):
|
|||||||
|
|
||||||
class Language:
|
class Language:
|
||||||
def __init__(self, lang_code: str = None, fallback_lang_code: str = None):
|
def __init__(self, lang_code: str = None, fallback_lang_code: str = None):
|
||||||
nonebot.logger.debug(_language_data)
|
|
||||||
if lang_code is None:
|
if lang_code is None:
|
||||||
lang_code = config.get("default_language", get_default_lang())
|
lang_code = config.get("default_language", get_default_lang())
|
||||||
self.lang_code = lang_code
|
self.lang_code = lang_code
|
||||||
self.fallback_lang_code = fallback_lang_code
|
self.fallback_lang_code = fallback_lang_code
|
||||||
|
|
||||||
if self.fallback_lang_code is None:
|
if self.fallback_lang_code is None:
|
||||||
self.fallback_lang_code = config.get("default_language", get_system_lang_code())
|
self.fallback_lang_code = config.get("default_language", get_system_lang_code())
|
||||||
|
|
||||||
@ -129,8 +127,10 @@ class Language:
|
|||||||
try:
|
try:
|
||||||
if self.lang_code in _language_data and item in _language_data[self.lang_code]:
|
if self.lang_code in _language_data and item in _language_data[self.lang_code]:
|
||||||
return _language_data[self.lang_code][item].format(*args, **kwargs)
|
return _language_data[self.lang_code][item].format(*args, **kwargs)
|
||||||
|
nonebot.logger.warning(f"Language text not found: {self.lang_code}.{item}")
|
||||||
if self.fallback_lang_code in _language_data and item in _language_data[self.fallback_lang_code]:
|
if self.fallback_lang_code in _language_data and item in _language_data[self.fallback_lang_code]:
|
||||||
return _language_data[self.fallback_lang_code][item].format(*args, **kwargs)
|
return _language_data[self.fallback_lang_code][item].format(*args, **kwargs)
|
||||||
|
nonebot.logger.warning(f"Language text not found in fallback language: {self.fallback_lang_code}.{item}")
|
||||||
return default or item
|
return default or item
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
nonebot.logger.error(f"Failed to get language text or format: {e}")
|
nonebot.logger.error(f"Failed to get language text or format: {e}")
|
||||||
|
Loading…
Reference in New Issue
Block a user