[^] builtins hack

This commit is contained in:
Maxim Khomutov 2025-03-23 02:52:54 +03:00
parent cf50296264
commit c261f7e140

View File

@ -1,3 +1,23 @@
class _i18_proxy:
@staticmethod
def __getattr__(item):
"""
Get the phrase from the locale file. If the phrase is not found, return the key in uppercase.
:param key: Key to search in the locale file.
:param kwargs: Arguments to format the phrase.
:return: The phrase from the locale file.
"""
@staticmethod
def __init__(**kwargs):
"""
Get the phrase from the locale file. If the phrase is not found, return the key in uppercase.
:param key: Key to search in the locale file.
:param kwargs: Arguments to format the phrase.
:return: The phrase from the locale file.
"""
class i18n:
@staticmethod
def set_lang(lang, encoding=None) -> None:
@ -17,7 +37,18 @@ class i18n:
:return: The phrase from the locale file.
"""
@staticmethod
def __call__(key: str, **kwargs) -> str:
def __getattr__(item):
"""
Get the phrase from the locale file. If the phrase is not found, return the key in uppercase.
:param key: Key to search in the locale file.
:param kwargs: Arguments to format the phrase.
:return: The phrase from the locale file.
"""
key = item.replace("_", ".") # заменяем _ на . для удобства
return _i18_proxy([key]) # Начинаем цепочку
@staticmethod
def __init__(key: str, **kwargs) -> str:
"""
Get the phrase from the locale file. If the phrase is not found, return the key in uppercase.