"""
module to manage translation message
selfmade way ! Package to manage it exists in python ;-)
"""
from json import load
from os.path import join, isfile
from tools.my_logger import main_logger
def make_translation(module_name:str,key_message:str, language:str='fr')->str:
    """
    return translation; TODO: create cache ;-)
    :param module_name: name of the file, ie, module
    :param key_message: the key message
    :param language:
    :return:
    """
    path_file = join('i18n',f"{module_name}.json")
    message = ''
    try:
        with open(path_file) as tfile:
            translations = load(tfile)
            message = translations[language][key_message]
    except Exception as error:
        main_logger.error(f"Error while translating {key_message}: {error}")
    return message





