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 main(): | |
pages = { | |
"Configuration" : [ | |
st.Page("pages/configuration_ui_lang.py", title="Language selection"), | |
], | |
"Translator" : [ | |
st.Page("pages/main.py", title="Main page"), | |
], | |
} | |
pg = st.navigation(pages) | |
pg.run() | |
#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: | |
# st.switch_page("pages/configuration_ui_lang.py") | |
#else: | |
# st.switch_page("pages/main.py") | |
# Point d'entrรฉe de l'application | |
if __name__ == "__main__": | |
main() | |