How to Make Google Translator Using Python

Introduction :

Hello friends! So in today’s post I am going to tell you how you can make your own Google Translator with the help of Python Programming Language. That too only in 6 lines of Python code. So if you also want to know about it, then read this post till the end and read it carefully so that you understand everything correctly.

Library Installation :

Friends, to do this project, we will need a Python library named googletrans, so first of all you have to install this library in your System (Computer), you can use pip command to install it.

pip install googletrans

Code for Making Google Translator Using Python :

from googletrans import Translator

sentence=input("Enter the Sentence:")
to_language=input("To language:")



Explanation :

1. Friends, first of all we have imported a class named Translator() from googletrans library.

2. After that we have stored the class named Translator() in a variable named translator so that we can use this class easily.

3. After that we have created a variable named sentence and inside it we will take a Sentence Input of any one language from the user, and we will translate this Sentence into another language.

4. After that we have created a variable named to_language and inside it we will ask the user that in which language the user wants to translate that sentence.

5. After that we have created a variable named output and inside it we will translate the sentence given by the user into another language and store it in the output variable. So to translate, we have written translator (which has a class Store named Translator()) and then this Translator class has a method named translate. So that’s why we have written translator.translate() and inside it we have passed 2 parameters. So, our first parameter is sentence (i.e. the sentence input by the user) and the second parameter is dest (destination). Method named translate has a built in parameter named dest. So we have written “dest=to_language” (Destination means in which language we have to translate our Sentence).

6. After that we have printed the Translated Sentence and for this we have written print(output.text) and here we have written .text because we only want the text and if you print only the output then the output will be redundant. A Sentence will come.

7. Save and Run this program

Output :

Enter the Sentence:Welcome to CodeWithShani
To language:hi

कोडविथशनि में आपका स्वागत है

Summary :

So friends, in this way you can create your own Google Translator with the help of Python Programming Language, that too in only 6 lines of Python code. If you like this project, then you must tell us by commenting and if you want to know about more similar projects, then follow us and subscribe to our YouTube Channel “CodeWithShani”.

Leave a Reply

Your email address will not be published. Required fields are marked *