locale() now accepts more object types
This commit is contained in:
parent
8bb7c58c2a
commit
8ccd2a858a
@ -10,6 +10,7 @@ from sys import exit
|
|||||||
from os import kill, sep
|
from os import kill, sep
|
||||||
from os import name as osname
|
from os import name as osname
|
||||||
from traceback import print_exc
|
from traceback import print_exc
|
||||||
|
from classes.holo_user import HoloUser
|
||||||
|
|
||||||
from modules.logging import logWrite
|
from modules.logging import logWrite
|
||||||
|
|
||||||
@ -102,17 +103,19 @@ def configGet(key: str, *args: str, file: str = "config"):
|
|||||||
this_key = this_key[dict_key]
|
this_key = this_key[dict_key]
|
||||||
return this_key[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
|
"""Get value of locale string
|
||||||
### Args:
|
### Args:
|
||||||
* key (`str`): The last key of the locale's keys path.
|
* key (`str`): The last key of the locale's keys path.
|
||||||
* *args (`list`): Path to key like: dict[args][key].
|
* *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:
|
### Returns:
|
||||||
* any: Value of provided locale key. In normal case must be `str`, `dict` or `list`.
|
* any: Value of provided locale key. In normal case must be `str`, `dict` or `list`.
|
||||||
"""
|
"""
|
||||||
if isinstance(locale, User):
|
if isinstance(locale, User):
|
||||||
locale = locale.language_code
|
locale = locale.language_code
|
||||||
|
elif isinstance(locale, HoloUser):
|
||||||
|
locale = locale.locale
|
||||||
|
|
||||||
if locale is None:
|
if locale is None:
|
||||||
locale = configGet("locale")
|
locale = configGet("locale")
|
||||||
|
Reference in New Issue
Block a user