It is quite normal for us to use Google Translation. It becomes a medium for us to understand movies, songs and well humans.
So, here is a python library which will help you do so, for using the library and translating sentences without opening google, here is straight forward help for you.
If you have python installed, go to step-2.
Steps for Translating languages:-
So, here is a python library which will help you do so, for using the library and translating sentences without opening google, here is straight forward help for you.
If you have python installed, go to step-2.
Steps for Translating languages:-
- Download latest version of Python from this website . Once download is completed and successfully installed, proceed further.
- Open command prompt on your system, for windows, click windows+R and search for cmd.
- Once command prompt is open, redirect to the python folder where you have installed python, in my case this is the command I enter: cd C:\Users\Divesh\AppData\Local\Programs\Python
- Now, redirect the command prompt to scripts folder like this:- cd Script\
Lets install Google Translator now:-
- Enter the command:- pip install googletrans
- It may take a few minutes but once the installation is completed, open your python workplace like:- python idle/ pycharm/ spider/ Jupyter Notebook.
- Here, for easy running and explanation, I will be using Jupyter Notebook, but you can follow which ever you feel better to use.
- Lets see what features can be explored from this library:-
Link for the whole code will be provided below. Follow each line of code to get clear idea of working with this library.
To use the library, add the following command in the beginning of your code:-
from googletrans import Translator
Basic Usage:-
If you don't provide the source language, google translate attempts to detect the source language by itself, but it is always advisable to provide the source language.
Full Code:-
from googletrans import Translator
translator = Translator()
a = translator.translate("शब्द")
print(a.text)
Output:-
Worked??
If yes, try the following code for more clearance,
Code:-
b = translator.translate('veritas lux mea', src='la')
print("Converted text:-",b.text)
print("Pronuce as:- ",b.pronunciation)
print("From this language:- ",b.src)
print("To this language:- ",b.dest)
Now, want to translate to your desired language, follow the provided synatx, here we are converting the sentence to hindi.
b = translator.translate('veritas lux mea', src='la',dest="hi")
print("Converted text:- ",b.text)
print("Pronuce as:- ",b.pronunciation)
print("From this language:- ",b.src)
print("To this language:- ",b.dest)
Output:-
Hope you translated easily and in case of any doubts feel free to comment below, your doubts will be cleared as soon as possible.
In case of more clearance and some additional features like converting a list of sentences, check out the documentation of the library here
Check out the full code in case of doubts here
To learn python extensively, use these books as the reference which teaches you from basic to Game Development to Machine Learning to Data Science in Python.
Hope you enjoyed learning and come back tommorow for learning about another library of Python.
Until then Good Bye!! Happy Learning!!
Good post, really helpful.
ReplyDelete