From c261f7e140e5f51155ac7e6e3209a6eadbcbd7b6 Mon Sep 17 00:00:00 2001 From: SantaSpeen Date: Sun, 23 Mar 2025 02:52:54 +0300 Subject: [PATCH] [^] builtins hack --- builtins.i18n.pyi.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/builtins.i18n.pyi.py b/builtins.i18n.pyi.py index 8be3dc0..1e8d392 100644 --- a/builtins.i18n.pyi.py +++ b/builtins.i18n.pyi.py @@ -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.