Are you tired of copying and pasting text into Google Translate? With just 3 lines of Python code, you can translate any language using the translate library. In this tutorial, we’ll show you how to translate text from English to Hindi.
First, make sure you have the translate library installed by running pip install translate in your command line. Then, import the translate library into your Python
import translate
Next, create a Translator object and specify the source and target languages. In this example, we’re translating from English (en-in) to Hindi (hi).
t = translate.Translator(from_lang="en-in",to_lang="hi")
Finally, use the translate method to translate your text. Here’s an example that translates the phrase “jai shree ram” from English to Hindi:
print(t.translate("jai shree ram"))
#Output:जय श्री राम
And that’s it! With just 3 lines of code, you can easily translate any language using Python. Try it out with other languages like Gujarati, Marathi, and more!
Kindly refer to This Page for a table of supported languages. For a full detailed explanatory video in Hindi, please see the video below:
0 Comments