mirror of
https://github.com/sean1832/GPT-Brain
synced 2024-11-18 21:25:53 +00:00
29 lines
964 B
Python
29 lines
964 B
Python
import gettext
|
|
import streamlit as st
|
|
import modules.utilities as util
|
|
|
|
languages = util.read_json('.locals/languages.json')
|
|
|
|
|
|
def select_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.keys(), language_index)
|
|
|
|
selected_lang = languages[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 _
|