fix: no language detected first launch app

This commit is contained in:
sean1832 2023-02-23 19:51:19 +11:00
parent 23843ba979
commit 4c1794da0e
2 changed files with 4 additions and 4 deletions

View File

@ -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():

View File

@ -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 {}