locale() now accepts more object types

This commit is contained in:
Profitroll 2022-12-16 23:25:21 +01:00
parent 8bb7c58c2a
commit 8ccd2a858a

View File

@ -10,6 +10,7 @@ from sys import exit
from os import kill, sep
from os import name as osname
from traceback import print_exc
from classes.holo_user import HoloUser
from modules.logging import logWrite
@ -102,17 +103,19 @@ def configGet(key: str, *args: str, file: str = "config"):
this_key = this_key[dict_key]
return this_key[key]
def locale(key: str, *args: str, locale: Union[str, User] = configGet("locale")) -> Any:
def locale(key: str, *args: str, locale: Union[str, User, HoloUser] = configGet("locale")) -> Any:
"""Get value of locale string
### Args:
* key (`str`): The last key of the locale's keys path.
* *args (`list`): Path to key like: dict[args][key].
* locale (`Union[str, User]`): Locale to looked up in. Provide User to get his `.language_code`. Defaults to config's locale value.
* locale (`Union[str, User, HoloUser]`): Locale to looked up in. Provide User to get his `.language_code`. Defaults to config's locale value.
### Returns:
* any: Value of provided locale key. In normal case must be `str`, `dict` or `list`.
"""
if isinstance(locale, User):
locale = locale.language_code
elif isinstance(locale, HoloUser):
locale = locale.locale
if locale is None:
locale = configGet("locale")