feat: create languages.json for globally accessible supported language info

This commit is contained in:
sean1832 2023-02-18 21:13:31 +11:00
parent bfaa87e5b8
commit 0fc126732c
2 changed files with 8 additions and 7 deletions

4
.locals/languages.json Normal file
View File

@ -0,0 +1,4 @@
{
"English": "en_US",
"简体中文": "zh_CN"
}

View File

@ -2,19 +2,16 @@ import gettext
import streamlit as st
import modules.utilities as util
languages_dict = {
'English': 'en_US',
'简体中文': 'zh_CN'
}
languages = util.read_json('.locals/languages.json')
def select_language():
language_index = util.get_index(list(languages_dict.values()), st.session_state['SESSION_LANGUAGE'])
language_index = util.get_index(list(languages.values()), st.session_state['SESSION_LANGUAGE'])
# Add a language selector widget to the Streamlit app
language = st.sidebar.selectbox('Language', languages_dict.keys(), language_index)
language = st.sidebar.selectbox('Language', languages.keys(), language_index)
selected_lang = languages_dict[language]
selected_lang = languages[language]
if st.session_state['SESSION_LANGUAGE'] != selected_lang:
st.session_state['SESSION_LANGUAGE'] = selected_lang