From a19f50f08fa00bda6d0351ae9e8fb47823e01977 Mon Sep 17 00:00:00 2001 From: spaceman99 Date: Tue, 23 Jan 2024 11:17:28 +0100 Subject: [PATCH] Update utils.py - wrong translations-path when run through wsgi (#80) when run through wsgi, pathlib.Path().absolute() points to the apache-folder, not to the folder where utils.py is located. I don't know if this still works when run in docker, but i assume it does. --- src/utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/utils.py b/src/utils.py index 07fb0cf..a89038d 100644 --- a/src/utils.py +++ b/src/utils.py @@ -8,7 +8,10 @@ translations = {} try: locale = DEFAULT_LOCALE - path = pathlib.Path().absolute() / 'translations/{}.json'.format(locale) + # Get the directory of utils.py + script_directory = pathlib.Path(__file__).resolve().parent + # Adjust the path based on the script directory + path = script_directory / 'translations/{}.json'.format(locale) with open(path, 'r') as f: translations[locale] = json.load(f) except Exception as e: @@ -32,4 +35,4 @@ def i18n(value, args = [],locale = DEFAULT_LOCALE) : # return input value if not found lookup = value break - return lookup.format(*args) \ No newline at end of file + return lookup.format(*args)