Build a Translator using Python

Search for a command to run...

Copy-pasted the whole code in VS-Code and run the program, but unfortunately, it didn't worked as u can see it here .
Python is really awesome platform to perform and develop any thing !! Thanks for sharing this Ayushi!!
Thankyou
Nice topic to start coding and writing about it in this T E C H N O V E M B E R. Congrats. 👏🏼
The series content will mostly cover Technical Python tutorials and my recent learnings and experience in Python.
In this Blog article, we will learn how to Create a heart with Turtle, we will see the implementation in Python. Repository for Ultimate Resource in python. Drop a star if you find it useful! Got anything to add? Open a PR on the same! You can refer ...
All you need to know about Hacktoberfest 2021

Hello reader! Well, Hacktoberfest is something, you are gonna hear a lot about in the coming month. You can refer to my YouTube video Tutorial to see a working tutorial for better understanding and a step-by-step guide of the same. https://www.yo...

Hello reader! In this Blog post, I will share some useful code snippets and functions in Python. Give it a read. Let's get started! 1. Memory The method getsizeof can be used to retrieve the size of any object. Here's an example of the same. import...

Hello reader! Whenever a client sends a request to the server, the response always contains a status code. You might not see it always but it's returned at every client-server interaction. Well, even if you are not a programmer, you would still know...

Hello reader! Microsoft subsidiary GitHub launched Copilot to power pair programming with AI. In this blog post, I will share all you need to know about it. You can refer to my YouTube video Tutorial to see a working tutorial for better understandin...

In this Blog article, we will learn how to Create a Translator . We will see the implementation in python.
Repository for Ultimate Resource in python. Drop a star if you find it useful! Got anything to add? Open a PR on the same!
You can refer to my YouTube video tutorial for better Understanding
1. Translator Introduction
2. What is Googletrans?
3. Create a Translator with Python
The Dictionary definition:
The definition of a translator is someone who helps people who speak different languages to communicate or who takes something (such as a speech or a book) in one language and who puts it into a different language for people to understand.
If you wish to know more about it, you can refer to Translation Wikipedia Page. Use this link to navigate to the GIF's Wikipedia Page.
Googletrans is a free and unlimited python library that implemented Google Translate API. This uses the Google Translate Ajax API to make calls to such methods as detect and translate.
If you wish to know more about it, you can refer to Googletrans Documentation. Use this link to navigate to the documentation.
Now that you are aware of Translator and Googletrans basics, we can move forward to the coding section.
You can find all the code at my GitHub Repository. Drop a star if you find it useful.

Open your terminal and run the following command
pip install googletrans
Now that we have the package, we are ready to import it in our python script.
from googletrans import Translator
Let's store some text that we will use for translation. You can use any text segment of your choice. I am using of one of my favourite poem Daffodils by WILLIAM WORDSWORTH. Let's store it in text. It's the last stanza of the poem.
The language I am using is French. You can choose any language of your choice.
You can even take the text as a user input if you like, so you wont have to make changes in your program every time you wish to use the translator.
text = ''' Pour souvent, quand sur mon canapé je mens
D'humeur vacante ou songeuse,
Ils clignotent sur cet œil intérieur
Quel est le bonheur de la solitude;
Et puis mon cœur se remplit de plaisir,
Et danse avec les jonquilles. '''
Let's create an instance of Translator to use.
translator = Translator()
This uses the Google Translate Ajax API to make calls to such methods as detect and translate. Now, let's call the detect method on translator and pass in our data stored in text and store it in lang.
lang = translator.detect(text)
print(lang)
Now let's print it out.
lang=fr means the detected language is French.confidence=0.9365149 is how much percentage the translator is confident about the language detection.Detected(lang=fr, confidence=0.9365149)
Once done, let's move forward and actually translate it. I am calling the translate method here on translator and passing two parametrs.
text: our data in original languagedest: our destination languageNow, to refer the other language codes you can refer to the google language documentation
NOTE: If you do not specify any destination language, it will automatically switch to the default one i.e. English.
res = translator.translate(text, dest = 'en')
At last, let's verify it by printing our res.
Often when on my couch I lie
In a vacant or pensive mood,
They blink on that inner eye
What is the happiness of solitude;
And then my heart fills with pleasure,
And dance with the daffodils.
This is how the conversion is done. This is all about the creating a Translator with Python. That's it! simple, isn't it? Hope this tutorial has helped.
You can play around with the library and explore more features and even make use of Python GUI using Tkinter.
You can find all the code at my GitHub Repository. Drop a star if you find it useful.
Thank you for reading, I would love to connect with you at Twitter | LinkedIn. I would recommend you to Check out the YouTube video of the same and don't forget to subscribe my Channel.
Do share your valuable feedback and suggestions!
You should definitely check out my other Blogs:
https://py-googletrans.readthedocs.io/en/latest/
https://github.com/ssut/py-googletrans
https://github.com/Zulko/moviepyhttps://pypi.org/project/googletrans/
https://www.poetryfoundation.org/poems/45521/i-wandered-lonely-as-a-cloud
https://cloud.google.com/translate/docs/languages