All Courses

TextTranslation using python

Shashank Shanu

3 years ago

Text Translation
We all know, how important is communication in our life. If we are communicating with the same person who uses or understand the same language what we are using, then it becomes very easy for both us to communicate. But when this does not happen then this create a very big problem. As we have to communicate with the different people’s in our daily routine life. Many researchers and Scientists try to solve this so that anyone can communicate with any person from what place, city or country they belong to. With the help of the advancement in the technologies Researchers and Scientists build many applications which help us to solve this issue. So that language doesn’t become hindrance in our communication.
In this article, I will try to a brief introduction of one of the libraries used from text translation i.e., translate.
So, let’s move forward and try to see how we can use this library. Before that let's understand first.

What is Text translation?

Text translation is the process of converting one language to another language. Nowadays this is becoming common for various websites as they cater to an international audience. Python provides a package known as “translate” which helps us do this. It provides translation for major languages.
Let’s see how we can install this package:
pip install translate


We can use pip command in the command line to install translate module in our python environment.

Translating English to German

Let’s see an example, where we try to translate a simple sentence from English language to German. The default from language being English.
Below is the code to translate a sentence from English to German:
from translate import Translator
translator = Translator(to_lang="German")
translating = translator.translate("Good Morning!")
print(translating)


When we run and execute the above command, it translated the English word “Good Morning” to German word “Guten Morgen!” as shown below:
Output –
Guten Morgen!

Translating German to Spanish

Now in this example, we are trying to translate the German word “Guten Morgen!” to Spanish word.
If we have the need specify the from-language and the to-language, then we can specify it as in the below program.

from translate import Translator
translator= Translator(from_lang="german",to_lang="spanish")
translating = translator.translate("Guten Morgen")
print(translating)

When we run and execute the above command, it translated the German word “Guten Morgen!” to Spanish word “Buenos días” as shown below:
Output:
Buenos días
This is how we can translate different languages to another language. I hope after you enjoyed reading this article and finally, you came to know about Text Translation using python.
For more such blogs/courses on data science, machine learning, artificial intelligence and emerging new technologies do visit us at InsideAIML.
Thanks for reading…
Happy Programming…

Submit Review