0% found this document useful (0 votes)
4 views2 pages

Multilingual Text Translator App

This document is a Python script for a multilingual translator application built using Streamlit and the Google Translator API. It allows users to input text, select source and target languages from a predefined list, and receive translations. The application includes basic styling for the title and footer, and handles errors during the translation process.

Uploaded by

tiwarinitish960
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Multilingual Text Translator App

This document is a Python script for a multilingual translator application built using Streamlit and the Google Translator API. It allows users to input text, select source and target languages from a predefined list, and receive translations. The application includes basic styling for the title and footer, and handles errors during the translation process.

Uploaded by

tiwarinitish960
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

🌐 🔄 ⚠✍ 🌍

import streamlit as st
from deep_translator import GoogleTranslator

st.set_page_config(page_title=" Multilingual Translator",


page_icon=" ", layout="centered")

LANGUAGES = {
'Afrikaans': 'af', 'Arabic': 'ar', 'Bengali': 'bn', 'Chinese
(Simplified)': 'zh-cn',
'French': 'fr', 'German': 'de', 'Gujarati': 'gu', 'Hindi': 'hi',
'Japanese': 'ja',
'Korean': 'ko', 'Punjabi': 'pa', 'Russian': 'ru', 'Spanish':
'es',
'Tamil': 'ta', 'Telugu': 'te'
}

[Link](
"""
<style>
.title {text-align: center; font-size: 40px; font-weight:
bold; color: #4CAF50;}
.footer {text-align: center; font-size: 14px; margin-top:
30px; color: gray;}
</style>
""",
unsafe_allow_html=True
)

[Link]("<h1 class='title'> Multilingual Translator</h1>",


unsafe_allow_html=True)

text = st.text_area(" Enter text to translate:", height=150,


placeholder="Type or paste your text here...")

col1, col2 = [Link](2)


with col1:
source_lang = [Link]("Select source language", ["Auto-
detect"] + sorted([Link]()))
with col2:
target_lang = [Link]("Select target language",
sorted([Link]()))

if [Link](" Translate"):
if not [Link]():
[Link](" Please enter some text to translate.")
else:
try:
translated_text = GoogleTranslator(
source="auto" if source_lang == "Auto-detect" else
LANGUAGES[source_lang],
target=LANGUAGES[target_lang]
).translate(text)
[Link](" Translation Successful!")
st.text_area(" Translated Text:", translated_text,
height=150)

except Exception as e:
[Link](f" Translation failed: {e}")

[Link]("<p class='footer'>Made with using Streamlit &


Google Translator API</p>", unsafe_allow_html=True)

You might also like