You've already forked wakapi-readme-stats
documentation added, black linter added
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user