No more locations.locale in config
This commit is contained in:
@@ -8,15 +8,16 @@ from libbot import sync
|
||||
class BotLocale:
|
||||
"""Small addon that can be used by bot clients' classes in order to minimize I/O"""
|
||||
|
||||
def __init__(self, locales_folder: Union[str, Path, None] = None) -> None:
|
||||
if locales_folder is None:
|
||||
locales_folder = Path(sync.config_get("locale", "locations"))
|
||||
elif isinstance(locales_folder, str):
|
||||
locales_folder = Path(locales_folder)
|
||||
elif not isinstance(locales_folder, Path):
|
||||
raise TypeError("'locales_folder' must be a valid path or path-like object")
|
||||
def __init__(
|
||||
self,
|
||||
locales_root: Union[str, Path] = Path("locale"),
|
||||
) -> None:
|
||||
if isinstance(locales_root, str):
|
||||
locales_root = Path(locales_root)
|
||||
elif not isinstance(locales_root, Path):
|
||||
raise TypeError("'locales_root' must be a valid path or path-like object")
|
||||
|
||||
files_locales: list = listdir(locales_folder)
|
||||
files_locales: list = listdir(locales_root)
|
||||
|
||||
valid_locales: list = [
|
||||
".".join(entry.split(".")[:-1]) for entry in files_locales
|
||||
@@ -26,7 +27,7 @@ class BotLocale:
|
||||
self.locales: dict = {}
|
||||
|
||||
for lc in valid_locales:
|
||||
self.locales[lc] = sync.json_read(Path(f"{locales_folder}/{lc}.json"))
|
||||
self.locales[lc] = sync.json_read(Path(f"{locales_root}/{lc}.json"))
|
||||
|
||||
def _(self, key: str, *args: str, locale: Union[str, None] = None) -> Any:
|
||||
"""Get value of locale string
|
||||
|
Reference in New Issue
Block a user