documentation added, black linter added

This commit is contained in:
pseusys
2023-02-17 22:41:08 +01:00
parent b36e374320
commit 2e494aa87b
12 changed files with 230 additions and 105 deletions

View File

@@ -7,19 +7,37 @@ from manager_environment import EnvironmentManager as EM
def init_localization_manager():
"""
Initialize localization manager.
Load GUI translations JSON file.
"""
LocalizationManager.load_localization("translation.json")
class LocalizationManager:
"""
Class for handling localization (and maybe other file IO in future).
Stores localization in dictionary.
"""
_LOCALIZATION: Dict[str, str] = dict()
@staticmethod
def load_localization(file: str):
with open(join(dirname(__file__), file), encoding='utf-8') as config_file:
"""
Read localization file and store locale defined with environmental variable.
:param file: Localization file path, related to current file (in sources root).
"""
with open(join(dirname(__file__), file), encoding="utf-8") as config_file:
data = load(config_file)
LocalizationManager._LOCALIZATION = data[EM.LOCALE]
@staticmethod
def t(key: str) -> str:
"""
Translate string to current localization.
:param key: Localization key.
:returns: Translation string.
"""
return LocalizationManager._LOCALIZATION[key]