You've already forked wakapi-readme-stats
44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
from json import load
|
|
from os.path import join, dirname
|
|
from typing import Dict
|
|
|
|
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):
|
|
"""
|
|
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]
|