This commit is contained in:
2022-08-10 13:08:15 +02:00
parent ac509194da
commit e03c862a35
8 changed files with 294 additions and 60 deletions

View File

@@ -3,7 +3,9 @@ try:
except ModuleNotFoundError:
import json
import os
from signal import SIGKILL
import psutil
def jsonLoad(filename):
"""Loads arg1 as json and returns its contents"""
@@ -51,4 +53,43 @@ def configGet(key: str, *args: str):
this_key = this_dict
for dict_key in args:
this_key = this_key[dict_key]
return this_key[key]
return this_key[key]
def locale(key: str, *args: list, locale=configGet("locale")):
"""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 (str): Locale to looked up in. Defaults to config's locale value.
Returns:
* any: Value of provided locale key
"""
if (locale == None):
locale = configGet("locale")
try:
this_dict = jsonLoad(f'{configGet("locale", "locations")}{os.sep}{locale}.json')
except FileNotFoundError:
try:
this_dict = jsonLoad(f'{configGet("locale", "locations")}{os.sep}{configGet("locale")}.json')
except FileNotFoundError:
try:
this_dict = jsonLoad(f'{configGet("locale_fallback", "locations")}{os.sep}{configGet("locale")}.json')
except:
return f'⚠️ Locale in config is invalid: could not get "{key}" in {str(args)} from locale "{locale}"'
this_key = this_dict
for dict_key in args:
this_key = this_key[dict_key]
try:
return this_key[key]
except KeyError:
return f'⚠️ Locale in config is invalid: could not get "{key}" in {str(args)} from locale "{locale}"'
def killProc(pid):
if os.name == "posix":
os.kill(pid, SIGKILL)
else:
p = psutil.Process(pid)
p.kill()