demorrha / app.py
ImPolymath's picture
update navigation
5ffdde1
# 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()