68 lines
2.4 KiB
Python
68 lines
2.4 KiB
Python
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:
|
|
"""
|
|
Set the language and encoding for the locale file.
|
|
:param lang: Use the language file with the given language.
|
|
:param encoding: Encoding of the language file.
|
|
:return: None
|
|
"""
|
|
@staticmethod
|
|
def get_phrase(key: str, **kwargs) -> str:
|
|
"""
|
|
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 __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.
|
|
|
|
: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 __getitem__(key: str) -> str:
|
|
"""
|
|
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.
|
|
:return: The phrase from the locale file.
|
|
"""
|
|
class i10n(i18n): ...
|