mirror of
https://github.com/sean1832/GPT-Brain
synced 2024-11-18 21:25:53 +00:00
32 lines
999 B
Python
32 lines
999 B
Python
|
import gettext
|
||
|
import streamlit as st
|
||
|
import modules.utilities as util
|
||
|
|
||
|
languages_dict = {
|
||
|
'English': 'en_US',
|
||
|
'简体中文': 'zh_CN'
|
||
|
}
|
||
|
|
||
|
|
||
|
def select_language():
|
||
|
language_index = util.get_index(list(languages_dict.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)
|
||
|
|
||
|
selected_lang = languages_dict[language]
|
||
|
|
||
|
if st.session_state['SESSION_LANGUAGE'] != selected_lang:
|
||
|
st.session_state['SESSION_LANGUAGE'] = selected_lang
|
||
|
util.write_json({'SESSION_LANGUAGE': selected_lang}, '.user/language.json')
|
||
|
st.experimental_rerun()
|
||
|
|
||
|
|
||
|
def set_language():
|
||
|
# set current language
|
||
|
lang_translations = gettext.translation('base', localedir='.locals', languages=[st.session_state['SESSION_LANGUAGE']])
|
||
|
lang_translations.install()
|
||
|
# define _ shortcut for translations
|
||
|
_ = lang_translations.gettext
|
||
|
return _
|