File size: 905 Bytes
babcb18
74cb5f4
 
babcb18
74cb5f4
babcb18
 
74cb5f4
 
 
 
 
 
 
 
babcb18
 
 
 
 
 
 
 
 
 
74cb5f4
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import streamlit as st
# from translate import Translator
from deep_translator import GoogleTranslator

@st.cache_data(ttl="2d", show_spinner=False)
def trad(message,l):
    try:
        # Utilisation du module translate
        # translator = Translator(to_lang=l , from_lang="fr")
        # translation = translator.translate(message)

        # Utilisation du module deep_translator 
        translation = GoogleTranslator(source='fr', target=l).translate(message.replace("  \n","§§§"))
        translation = translation.replace("§§§","  \n") # .replace("  ","<br>")

        return translation
    except:
        return "Problème de traduction.."
    
def tr(message):
    if 'Language' not in st.session_state: l = 'fr'
    else: l= st.session_state['Language']
    if l == 'fr': return message
    else: message = message.replace(":red[**","").replace("**]","")
    return trad(message,l)