Spaces:
Paused
Paused
File size: 5,476 Bytes
5ffdde1 8c55a56 5ffdde1 8c55a56 5ffdde1 8c55a56 5ffdde1 8c55a56 5ffdde1 440cc04 8773eb3 5ffdde1 440cc04 5ffdde1 440cc04 7bae089 5ffdde1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# Standard libraries
#import base64
#import io
import json
#import os
#import re
#import tempfile
#import time
#from os import getenv
from typing import Any
from typing import Dict
#from typing import IO
#from typing import List
from typing import Optional
#from typing import Tuple
#from typing import Union
# Third-party libraries
import streamlit as st
from var_app import __version__
LANGUAGES_EMOJI = {
"Afrikaans": "๐ฟ๐ฆ", "Arabic": "๐ธ๐ฆ", "Armenian": "๐ฆ๐ฒ", "Azerbaijani": "๐ฆ๐ฟ", "Belarusian": "๐ง๐พ",
"Bosnian": "๐ง๐ฆ", "Bulgarian": "๐ง๐ฌ", "Catalan": "๐ช๐ธ", "Chinese": "๐จ๐ณ", "Croatian": "๐ญ๐ท",
"Czech": "๐จ๐ฟ", "Danish": "๐ฉ๐ฐ", "Dutch": "๐ณ๐ฑ", "English": "๐ฌ๐ง", "Estonian": "๐ช๐ช",
"Finnish": "๐ซ๐ฎ", "French": "๐ซ๐ท", "Galician": "๐ช๐ธ", "German": "๐ฉ๐ช", "Greek": "๐ฌ๐ท",
"Hebrew": "๐ฎ๐ฑ", "Hindi": "๐ฎ๐ณ", "Hungarian": "๐ญ๐บ", "Icelandic": "๐ฎ๐ธ", "Indonesian": "๐ฎ๐ฉ",
"Italian": "๐ฎ๐น", "Japanese": "๐ฏ๐ต", "Kannada": "๐ฎ๐ณ", "Kazakh": "๐ฐ๐ฟ", "Korean": "๐ฐ๐ท",
"Latvian": "๐ฑ๐ป", "Lithuanian": "๐ฑ๐น", "Macedonian": "๐ฒ๐ฐ", "Malay": "๐ฒ๐พ", "Marathi": "๐ฎ๐ณ",
"Maori": "๐ณ๐ฟ", "Nepali": "๐ณ๐ต", "Norwegian": "๐ณ๐ด", "Persian": "๐ฎ๐ท", "Polish": "๐ต๐ฑ",
"Portuguese": "๐ต๐น", "Romanian": "๐ท๐ด", "Russian": "๐ท๐บ", "Serbian": "๐ท๐ธ", "Slovak": "๐ธ๐ฐ",
"Slovenian": "๐ธ๐ฎ", "Spanish": "๐ช๐ธ", "Swahili": "๐ฐ๐ช", "Swedish": "๐ธ๐ช", "Tagalog": "๐ต๐ญ",
"Tamil": "๐ฎ๐ณ", "Thai": "๐น๐ญ", "Turkish": "๐น๐ท", "Ukrainian": "๐บ๐ฆ", "Urdu": "๐ต๐ฐ",
"Vietnamese": "๐ป๐ณ", "Welsh": "๐ด๓ ง๓ ข๓ ท๓ ฌ๓ ณ๓ ฟ"
}
def load_ui_language(file_path: Optional[str] = "ui_lang_support.json") -> Dict[str, Any]:
"""
Charge les traductions de l'interface utilisateur ร partir d'un fichier JSON.
Args:
file_path (Optional[str]): Chemin vers le fichier JSON contenant les traductions.
Returns:
Dict[str, Any]: Un dictionnaire contenant les traductions de l'interface utilisateur.
"""
try:
with open(file_path, 'r', encoding='utf-8') as file:
return json.load(file)
except FileNotFoundError:
print(f"{get_translation('erreur_fichier_non_trouve')} {file_path}")
return {}
except json.JSONDecodeError:
print(f"{get_translation('erreur_lecture_fichier')} JSON decoding error")
return {}
except IOError as e:
print(f"{get_translation('erreur_lecture_fichier')} {e}")
return {}
def get_translation(key: str) -> str:
"""
Obtient la traduction pour une clรฉ donnรฉe basรฉe sur la langue d'interface sรฉlectionnรฉe.
"""
lang = st.session_state.get('interface_language', 'English')
return translations.get(lang, {}).get(key, key)
# Dictionary to store translations
translations = load_ui_language()
def language_selection_page():
st.set_page_config(initial_sidebar_state="collapsed")
#st.set_page_config(page_icon="๐น")
#st.set_page_config(layout="wide")
# Fonction de rappel pour mettre ร jour la langue temporaire lorsque la sรฉlection change
def update_temp_language():
st.session_state['temp_interface_language'] = st.session_state['language_selector']
# Initialiser la langue temporaire si elle n'existe pas
if 'temp_interface_language' not in st.session_state:
st.session_state['temp_interface_language'] = st.session_state.get('interface_language', 'English')
# Sรฉlecteur de langue avec un callback pour mettre ร jour la langue temporaire
with st.container(
border=True,
key='lang_choices_container',
height=None
):
TITRE_LANGSELMENU=translations[st.session_state['temp_interface_language']].get('selection_de_la_langue', 'Language Selection')
# Titre basรฉ sur la langue temporaire
st.header(
f":blue[{TITRE_LANGSELMENU}]"
,divider=True)
selecteur_du_choix, boutton_de_validation = st.columns(2,
vertical_alignment='top',
gap="small")
selected_language = selecteur_du_choix.selectbox(
translations[st.session_state['temp_interface_language']].get('choix_selection_langue', 'Choose the interface language'),
options=list(translations.keys()),
index=list(translations.keys()).index(st.session_state['temp_interface_language']),
format_func=lambda lang: f"{LANGUAGES_EMOJI.get(lang, '')} {lang}",
key='language_selector',
on_change=update_temp_language,
label_visibility="collapsed"
)
# Bouton de confirmation avec traduction
if boutton_de_validation.button(
translations[st.session_state['temp_interface_language']].get(
'confirmer', 'Confirm'),
key='confirm_button_ui_lang_choice',
type="secondary",
use_container_width=True,
disabled = False
):
st.session_state.interface_language = selected_language
st.session_state.init_launch_app = False
st.switch_page(st.Page("pages/main.py", title="Main page"))
language_selection_page()
|