ImPolymath commited on
Commit
5ffdde1
ยท
1 Parent(s): c556e09

update navigation

Browse files
Files changed (2) hide show
  1. app.py +27 -44
  2. 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
- if 'interface_language' not in st.session_state:
121
- st.session_state.interface_language = 'English'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
 
123
- if st.session_state.init_launch_app:
124
- language_selection_page()
125
- else:
126
- st.switch_page("pages/main.py")
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
+