From 8ccd2a858af313b2f9107e376e46176f07513cbc Mon Sep 17 00:00:00 2001 From: Profitroll <47523801+profitrollgame@users.noreply.github.com> Date: Fri, 16 Dec 2022 23:25:21 +0100 Subject: [PATCH] locale() now accepts more object types --- modules/utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/utils.py b/modules/utils.py index 81c1165..c100fb0 100644 --- a/modules/utils.py +++ b/modules/utils.py @@ -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")