Spaces:
Paused
Paused
ImPolymath
commited on
Commit
•
5ffdde1
1
Parent(s):
c556e09
update navigation
Browse files- app.py +27 -44
- pages/configuration_ui_lang.py +115 -0
app.py
CHANGED
@@ -22,12 +22,12 @@ import streamlit as st
|
|
22 |
from var_app import __version__
|
23 |
|
24 |
# Au début du fichier, après les imports
|
25 |
-
st.set_page_config(
|
26 |
-
page_title=f"DEMORRHA - (v{__version__})",
|
27 |
-
page_icon="👹",
|
28 |
-
layout="wide",
|
29 |
-
initial_sidebar_state="collapsed"
|
30 |
-
)
|
31 |
|
32 |
|
33 |
LANGUAGES_EMOJI = {
|
@@ -81,49 +81,32 @@ def get_translation(key: str) -> str:
|
|
81 |
translations = load_ui_language()
|
82 |
|
83 |
|
84 |
-
def language_selection_page():
|
85 |
-
# Fonction de rappel pour mettre à jour la langue temporaire lorsque la sélection change
|
86 |
-
def update_temp_language():
|
87 |
-
st.session_state['temp_interface_language'] = st.session_state['language_selector']
|
88 |
-
|
89 |
-
# Initialiser la langue temporaire si elle n'existe pas
|
90 |
-
if 'temp_interface_language' not in st.session_state:
|
91 |
-
st.session_state['temp_interface_language'] = st.session_state.get('interface_language', 'English')
|
92 |
-
|
93 |
-
# Titre basé sur la langue temporaire
|
94 |
-
st.title(translations[st.session_state['temp_interface_language']].get('selection_de_la_langue', 'Language Selection'))
|
95 |
-
|
96 |
-
# Sélecteur de langue avec un callback pour mettre à jour la langue temporaire
|
97 |
-
selected_language = st.selectbox(
|
98 |
-
translations[st.session_state['temp_interface_language']].get('choix_selection_langue', 'Choose the interface language'),
|
99 |
-
options=list(translations.keys()),
|
100 |
-
index=list(translations.keys()).index(st.session_state['temp_interface_language']),
|
101 |
-
format_func=lambda lang: f"{LANGUAGES_EMOJI.get(lang, '')} {lang}",
|
102 |
-
key='language_selector',
|
103 |
-
on_change=update_temp_language
|
104 |
-
)
|
105 |
-
|
106 |
-
# Afficher les instructions basées sur la langue temporaire
|
107 |
-
st.write(translations[st.session_state['temp_interface_language']].get('instruction_selection_langue', 'Please select a language.'))
|
108 |
-
|
109 |
-
# Bouton de confirmation avec traduction
|
110 |
-
if st.button(translations[st.session_state['temp_interface_language']].get('confirmer', 'Confirm')):
|
111 |
-
st.session_state.interface_language = selected_language
|
112 |
-
st.session_state.init_launch_app = False
|
113 |
-
st.rerun()
|
114 |
|
115 |
|
116 |
def main():
|
117 |
-
if 'init_launch_app' not in st.session_state:
|
118 |
-
st.session_state.init_launch_app = True
|
119 |
|
120 |
-
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
-
if st.session_state.init_launch_app:
|
124 |
-
|
125 |
-
else:
|
126 |
-
|
127 |
|
128 |
# Point d'entrée de l'application
|
129 |
if __name__ == "__main__":
|
|
|
22 |
from var_app import __version__
|
23 |
|
24 |
# Au début du fichier, après les imports
|
25 |
+
#st.set_page_config(
|
26 |
+
# page_title=f"DEMORRHA - (v{__version__})",
|
27 |
+
# page_icon="👹",
|
28 |
+
# layout="wide",
|
29 |
+
# initial_sidebar_state="collapsed"
|
30 |
+
#)
|
31 |
|
32 |
|
33 |
LANGUAGES_EMOJI = {
|
|
|
81 |
translations = load_ui_language()
|
82 |
|
83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
|
86 |
def main():
|
|
|
|
|
87 |
|
88 |
+
pages = {
|
89 |
+
"Configuration" : [
|
90 |
+
st.Page("pages/configuration_ui_lang.py", title="Language selection"),
|
91 |
+
],
|
92 |
+
"Translator" : [
|
93 |
+
st.Page("pages/main.py", title="Main page"),
|
94 |
+
],
|
95 |
+
}
|
96 |
+
pg = st.navigation(pages)
|
97 |
+
pg.run()
|
98 |
+
|
99 |
+
|
100 |
+
#if 'init_launch_app' not in st.session_state:
|
101 |
+
# st.session_state.init_launch_app = True
|
102 |
+
|
103 |
+
#if 'interface_language' not in st.session_state:
|
104 |
+
# st.session_state.interface_language = 'English'
|
105 |
|
106 |
+
#if st.session_state.init_launch_app:
|
107 |
+
# st.switch_page("pages/configuration_ui_lang.py")
|
108 |
+
#else:
|
109 |
+
# st.switch_page("pages/main.py")
|
110 |
|
111 |
# Point d'entrée de l'application
|
112 |
if __name__ == "__main__":
|
pages/configuration_ui_lang.py
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Standard libraries
|
2 |
+
import base64
|
3 |
+
import io
|
4 |
+
import json
|
5 |
+
import os
|
6 |
+
import re
|
7 |
+
import tempfile
|
8 |
+
import time
|
9 |
+
from os import getenv
|
10 |
+
from typing import Any
|
11 |
+
from typing import Dict
|
12 |
+
from typing import IO
|
13 |
+
from typing import List
|
14 |
+
from typing import Optional
|
15 |
+
from typing import Tuple
|
16 |
+
from typing import Union
|
17 |
+
|
18 |
+
# Third-party libraries
|
19 |
+
import streamlit as st
|
20 |
+
|
21 |
+
|
22 |
+
from var_app import __version__
|
23 |
+
|
24 |
+
LANGUAGES_EMOJI = {
|
25 |
+
"Afrikaans": "🇿🇦", "Arabic": "🇸🇦", "Armenian": "🇦🇲", "Azerbaijani": "🇦🇿", "Belarusian": "🇧🇾",
|
26 |
+
"Bosnian": "🇧🇦", "Bulgarian": "🇧🇬", "Catalan": "🇪🇸", "Chinese": "🇨🇳", "Croatian": "🇭🇷",
|
27 |
+
"Czech": "🇨🇿", "Danish": "🇩🇰", "Dutch": "🇳🇱", "English": "🇬🇧", "Estonian": "🇪🇪",
|
28 |
+
"Finnish": "🇫🇮", "French": "🇫🇷", "Galician": "🇪🇸", "German": "🇩🇪", "Greek": "🇬🇷",
|
29 |
+
"Hebrew": "🇮🇱", "Hindi": "🇮🇳", "Hungarian": "🇭🇺", "Icelandic": "🇮🇸", "Indonesian": "🇮🇩",
|
30 |
+
"Italian": "🇮🇹", "Japanese": "🇯🇵", "Kannada": "🇮🇳", "Kazakh": "🇰🇿", "Korean": "🇰🇷",
|
31 |
+
"Latvian": "🇱🇻", "Lithuanian": "🇱🇹", "Macedonian": "🇲🇰", "Malay": "🇲🇾", "Marathi": "🇮🇳",
|
32 |
+
"Maori": "🇳🇿", "Nepali": "🇳🇵", "Norwegian": "🇳🇴", "Persian": "🇮🇷", "Polish": "🇵🇱",
|
33 |
+
"Portuguese": "🇵🇹", "Romanian": "🇷🇴", "Russian": "🇷🇺", "Serbian": "🇷🇸", "Slovak": "🇸🇰",
|
34 |
+
"Slovenian": "🇸🇮", "Spanish": "🇪🇸", "Swahili": "🇰🇪", "Swedish": "🇸🇪", "Tagalog": "🇵🇭",
|
35 |
+
"Tamil": "🇮🇳", "Thai": "🇹🇭", "Turkish": "🇹🇷", "Ukrainian": "🇺🇦", "Urdu": "🇵🇰",
|
36 |
+
"Vietnamese": "🇻🇳", "Welsh": "🏴"
|
37 |
+
}
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
def load_ui_language(file_path: Optional[str] = "ui_lang_support.json") -> Dict[str, Any]:
|
42 |
+
"""
|
43 |
+
Charge les traductions de l'interface utilisateur à partir d'un fichier JSON.
|
44 |
+
|
45 |
+
Args:
|
46 |
+
file_path (Optional[str]): Chemin vers le fichier JSON contenant les traductions.
|
47 |
+
|
48 |
+
Returns:
|
49 |
+
Dict[str, Any]: Un dictionnaire contenant les traductions de l'interface utilisateur.
|
50 |
+
"""
|
51 |
+
try:
|
52 |
+
with open(file_path, 'r', encoding='utf-8') as file:
|
53 |
+
return json.load(file)
|
54 |
+
except FileNotFoundError:
|
55 |
+
print(f"{get_translation('erreur_fichier_non_trouve')} {file_path}")
|
56 |
+
return {}
|
57 |
+
except json.JSONDecodeError:
|
58 |
+
print(f"{get_translation('erreur_lecture_fichier')} JSON decoding error")
|
59 |
+
return {}
|
60 |
+
except IOError as e:
|
61 |
+
print(f"{get_translation('erreur_lecture_fichier')} {e}")
|
62 |
+
return {}
|
63 |
+
|
64 |
+
|
65 |
+
def get_translation(key: str) -> str:
|
66 |
+
"""
|
67 |
+
Obtient la traduction pour une clé donnée basée sur la langue d'interface sélectionnée.
|
68 |
+
"""
|
69 |
+
lang = st.session_state.get('interface_language', 'English')
|
70 |
+
return translations.get(lang, {}).get(key, key)
|
71 |
+
|
72 |
+
# Dictionary to store translations
|
73 |
+
translations = load_ui_language()
|
74 |
+
|
75 |
+
|
76 |
+
|
77 |
+
|
78 |
+
def language_selection_page():
|
79 |
+
# Fonction de rappel pour mettre à jour la langue temporaire lorsque la sélection change
|
80 |
+
def update_temp_language():
|
81 |
+
st.session_state['temp_interface_language'] = st.session_state['language_selector']
|
82 |
+
|
83 |
+
# Initialiser la langue temporaire si elle n'existe pas
|
84 |
+
if 'temp_interface_language' not in st.session_state:
|
85 |
+
st.session_state['temp_interface_language'] = st.session_state.get('interface_language', 'English')
|
86 |
+
|
87 |
+
# Titre basé sur la langue temporaire
|
88 |
+
st.title(translations[st.session_state['temp_interface_language']].get('selection_de_la_langue', 'Language Selection'))
|
89 |
+
|
90 |
+
# Sélecteur de langue avec un callback pour mettre à jour la langue temporaire
|
91 |
+
selected_language = st.selectbox(
|
92 |
+
translations[st.session_state['temp_interface_language']].get('choix_selection_langue', 'Choose the interface language'),
|
93 |
+
options=list(translations.keys()),
|
94 |
+
index=list(translations.keys()).index(st.session_state['temp_interface_language']),
|
95 |
+
format_func=lambda lang: f"{LANGUAGES_EMOJI.get(lang, '')} {lang}",
|
96 |
+
key='language_selector',
|
97 |
+
on_change=update_temp_language
|
98 |
+
)
|
99 |
+
|
100 |
+
# Afficher les instructions basées sur la langue temporaire
|
101 |
+
st.write(translations[st.session_state['temp_interface_language']].get('instruction_selection_langue', 'Please select a language.'))
|
102 |
+
|
103 |
+
# Bouton de confirmation avec traduction
|
104 |
+
if st.button(translations[st.session_state['temp_interface_language']].get('confirmer', 'Confirm')):
|
105 |
+
st.session_state.interface_language = selected_language
|
106 |
+
st.session_state.init_launch_app = False
|
107 |
+
st.switch_page(st.Page("pages/main.py", title="Main page"))
|
108 |
+
#st.rerun()
|
109 |
+
|
110 |
+
|
111 |
+
|
112 |
+
language_selection_page()
|
113 |
+
|
114 |
+
|
115 |
+
|