From 4c1794da0ed2f917b42ac49efbc3602831b126e7 Mon Sep 17 00:00:00 2001 From: sean1832 Date: Thu, 23 Feb 2023 19:51:19 +1100 Subject: [PATCH] fix: no language detected first launch app --- modules/language.py | 2 +- modules/utilities.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/language.py b/modules/language.py index 17e84e8..b6cf9c3 100644 --- a/modules/language.py +++ b/modules/language.py @@ -3,7 +3,7 @@ import streamlit as st import modules.utilities as util -languages = util.read_json('.locals/languages.json') +languages = util.read_json('.locals/languages.json', default_value={'SESSION_LANGUAGE': 'en_US'}) def select_language(): diff --git a/modules/utilities.py b/modules/utilities.py index 1f683b9..6b15fe0 100644 --- a/modules/utilities.py +++ b/modules/utilities.py @@ -137,12 +137,12 @@ def write_json(content, filepath, mode='w', encoding='UTF-8'): json.dump(content, file, indent=2) -def read_json(filepath): +def read_json(filepath, encoding='UTF-8', default_value={}): try: - with open(filepath, 'r', encoding='UTF-8') as file: + with open(filepath, 'r', encoding=encoding) as file: return json.load(file) except FileNotFoundError: - create_json_not_exist(filepath) + create_json_not_exist(filepath, default_value) return {}