rick commited on
Commit
47ac2c1
·
unverified ·
1 Parent(s): 2bf2a00

update ui lang support...

Browse files
Files changed (2) hide show
  1. app.py +34 -24
  2. ui_lang_support.json +3 -2
app.py CHANGED
@@ -74,44 +74,54 @@ def load_ui_language(file_path: Optional[str] = "ui_lang_support.json") -> Dict[
74
  def get_translation(key: str) -> str:
75
  """
76
  Obtient la traduction pour une clé donnée basée sur la langue d'interface sélectionnée.
77
-
78
- Args:
79
- key (str): La clé de traduction.
80
-
81
- Returns:
82
- str: Le texte traduit.
83
  """
84
- if "interface_language" not in st.session_state:
85
- return translations[st.session_state.interface_language][key]
86
- else:
87
- return translations[st.session_state.interface_language_select][key]
88
-
89
 
90
  # Dictionary to store translations
91
  translations = load_ui_language()
92
 
93
 
94
-
95
  def language_selection_page():
96
- """Page de sélection de la langue."""
97
- st.title(f"{get_translation('selection_de_la_langue')}")
 
 
 
 
 
 
 
 
 
 
98
  selected_language = st.selectbox(
99
- f"{get_translation('choix_selection_langue')}",
100
  options=list(translations.keys()),
101
- index=list(translations.keys()).index("English"),
102
- format_func=lambda lang: f"{LANGUAGES_EMOJI.get(lang, '')} {lang}"
 
 
103
  )
104
- if st.button(f"{get_translation('continuer')}"):
105
- st.session_state.interface_language_select = selected_language
106
- st.switch_page("pages/main.py")
 
 
 
 
 
 
107
 
108
 
109
  def main():
110
- """Fonction principale pour la navigation."""
111
- if "interface_language_select" not in st.session_state:
112
- st.session_state.interface_language_select = None
 
 
113
 
114
- if st.session_state.interface_language_select is None:
115
  language_selection_page()
116
  else:
117
  st.switch_page("pages/main.py")
 
74
  def get_translation(key: str) -> str:
75
  """
76
  Obtient la traduction pour une clé donnée basée sur la langue d'interface sélectionnée.
 
 
 
 
 
 
77
  """
78
+ lang = st.session_state.get('interface_language', 'English')
79
+ return translations.get(lang, {}).get(key, key)
 
 
 
80
 
81
  # Dictionary to store translations
82
  translations = load_ui_language()
83
 
84
 
 
85
  def language_selection_page():
86
+ # Fonction de rappel pour mettre à jour la langue temporaire lorsque la sélection change
87
+ def update_temp_language():
88
+ st.session_state['temp_interface_language'] = st.session_state['language_selector']
89
+
90
+ # Initialiser la langue temporaire si elle n'existe pas
91
+ if 'temp_interface_language' not in st.session_state:
92
+ st.session_state['temp_interface_language'] = st.session_state.get('interface_language', 'English')
93
+
94
+ # Titre basé sur la langue temporaire
95
+ st.title(translations[st.session_state['temp_interface_language']].get('selection_de_la_langue', 'Language Selection'))
96
+
97
+ # Sélecteur de langue avec un callback pour mettre à jour la langue temporaire
98
  selected_language = st.selectbox(
99
+ translations[st.session_state['temp_interface_language']].get('choix_selection_langue', 'Choose the interface language'),
100
  options=list(translations.keys()),
101
+ index=list(translations.keys()).index(st.session_state['temp_interface_language']),
102
+ format_func=lambda lang: f"{LANGUAGES_EMOJI.get(lang, '')} {lang}",
103
+ key='language_selector',
104
+ on_change=update_temp_language
105
  )
106
+
107
+ # Afficher les instructions basées sur la langue temporaire
108
+ st.write(translations[st.session_state['temp_interface_language']].get('instruction_selection_langue', 'Please select a language.'))
109
+
110
+ # Bouton de confirmation avec traduction
111
+ if st.button(translations[st.session_state['temp_interface_language']].get('confirmer', 'Confirm')):
112
+ st.session_state.interface_language = selected_language
113
+ st.session_state.init_launch_app = False
114
+ st.rerun()
115
 
116
 
117
  def main():
118
+ if 'init_launch_app' not in st.session_state:
119
+ st.session_state.init_launch_app = True
120
+
121
+ if 'interface_language' not in st.session_state:
122
+ st.session_state.interface_language = 'English'
123
 
124
+ if st.session_state.init_launch_app:
125
  language_selection_page()
126
  else:
127
  st.switch_page("pages/main.py")
ui_lang_support.json CHANGED
@@ -54,7 +54,8 @@
54
  "confirmer": "Confirmer",
55
  "Annuler": "Annuler",
56
  "selection_de_la_langue": "Sélection de la langue",
57
- "choix_selection_langue": "Choisissez la langue de l'interface"
 
58
  },
59
  "Afrikaans": {
60
  "titre": "DEMORRHA APP - weergawe 1",
@@ -3248,4 +3249,4 @@
3248
  "selection_de_la_langue": "Dewis iaith",
3249
  "choix_selection_langue": "Dewiswch iaith yr rhyngwyneb"
3250
  }
3251
- }
 
54
  "confirmer": "Confirmer",
55
  "Annuler": "Annuler",
56
  "selection_de_la_langue": "Sélection de la langue",
57
+ "choix_selection_langue": "Choisissez la langue de l'interface",
58
+ "instruction_selection_langue": "Veuillez sélectionner une langue pour l'interface de l'application."
59
  },
60
  "Afrikaans": {
61
  "titre": "DEMORRHA APP - weergawe 1",
 
3249
  "selection_de_la_langue": "Dewis iaith",
3250
  "choix_selection_langue": "Dewiswch iaith yr rhyngwyneb"
3251
  }
3252
+ }