Spaces:
Paused
Paused
| # 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__ | |
| # Au dรฉbut du fichier, aprรจs les imports | |
| st.set_page_config( | |
| page_title=f"DEMORRHA - (v{__version__})", | |
| page_icon="๐น", | |
| layout="wide", | |
| initial_sidebar_state="collapsed" | |
| ) | |
| 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(): | |
| # 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') | |
| # Titre basรฉ sur la langue temporaire | |
| st.title(translations[st.session_state['temp_interface_language']].get('selection_de_la_langue', 'Language Selection')) | |
| # Sรฉlecteur de langue avec un callback pour mettre ร jour la langue temporaire | |
| selected_language = st.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 | |
| ) | |
| # Afficher les instructions basรฉes sur la langue temporaire | |
| st.write(translations[st.session_state['temp_interface_language']].get('instruction_selection_langue', 'Please select a language.')) | |
| # Bouton de confirmation avec traduction | |
| if st.button(translations[st.session_state['temp_interface_language']].get('confirmer', 'Confirm')): | |
| st.session_state.interface_language = selected_language | |
| st.session_state.init_launch_app = False | |
| st.rerun() | |
| def main(): | |
| if 'init_launch_app' not in st.session_state: | |
| st.session_state.init_launch_app = True | |
| if 'interface_language' not in st.session_state: | |
| st.session_state.interface_language = 'English' | |
| if st.session_state.init_launch_app: | |
| language_selection_page() | |
| else: | |
| st.switch_page("pages/main.py") | |
| # Point d'entrรฉe de l'application | |
| if __name__ == "__main__": | |
| main() | |