📅  最后修改于: 2023-12-03 14:57:21.019000             🧑  作者: Mango
This is a program that translates Spanish text into English using Python. With the help of the googletrans Python library, we can easily convert Spanish language into English with just a few lines of code.
Before running this program, make sure you have the following installed:
pip install googletrans
)from googletrans import Translator
def translate_spanish_to_english(text):
translator = Translator()
translation = translator.translate(text, src='es', dest='en')
return translation.text
spanish_text = "¡Hola, cómo estás?"
english_text = translate_spanish_to_english(spanish_text)
print(english_text)
Translator
class from the googletrans library.translate_spanish_to_english
function is defined, which takes a Spanish text as input.Translator
class is created.translate
method is called on the translator object, which takes the text to be translated and the source (Spanish) and destination (English) languages as parameters. The translated text is stored in the translation
object.translate_spanish_to_english
function with that text.This program provides a simple way to translate Spanish text to English using Python. By using the googletrans library, we can effortlessly perform language translation tasks.