All Courses

Python - Text Translation

Neha Kumawat

a year ago

 Python Text translation
             Text translation from one language to another is increasingly becoming common for various websites as they cater to an international audience. The python package which helps us do this is called translate.
This package can be installed by the following way. It provides translation for major languages.

pip install translate
Below is an example of translating a simple sentence from English to German. The default from language being English.

from translate import Translator
translator= Translator(to_lang="German")
translation = translator.translate("Good Morning!")
print translation
When we run the above program, we get the following output −

Guten Morgen!

Between Any Two Languages

      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")
translation = translator.translate("Guten Morgen")
print translation
When we run the above program, we get the following output −

Buenos días
Like the Blog, then Share it with your friends and colleagues to make this AI community stronger. 
To learn more about nuances of Artificial Intelligence, Python Programming, Deep Learning, Data Science and Machine Learning, visit our insideAIML blog page.
Keep Learning. Keep Growing

Submit Review