Language translation is very important for any person or organization wherein multilingual clients are coming from different countries. Many presentations, quotations, reports, etc. do come in different languages to the donor company from their respective customers and the main body must translate the same to analyze the internal meaning of the words written and then give a reply accordingly. For translating languages Google is regarded as the topmost player as it provides a feature of Google translate that can do the translation stuff for us. One just needs to feed the data that he/she wants to translate and wait for Google to do its job. People all over the world use Google Translate to get the semantic meaning of the text. But what if this translation stuff can be done with the help of coding especially through Python??
Well, it is possible because Google translate does come as an installable API for Python so that we can use it as a third party library and perform the intended task. The name of the library that is available for Python is Google Trans. This library works the same way as the actual Google translate and it is made for Python to help solve NLP related tasks.
For eg. If the dataset that we have is in Tamil language and we want to translate the same into English or Hindi then Google Trans can do the work for us with just a few lines of code. So let’s see how to install the same using Python and how to work using the same:
Using Simple Python
The installation steps are performed taking into account that Python or Anaconda is already there in your system with the
- Open Command Prompt and type Python. If it throws no error then Python is there in the system and you are good to go.
- Again in the Command Prompt just type pip and if it throws no error then pip is already there within the system.
- Now just type
pip install googletrans. Once done then open your Jupyter notebook or any other text editor and import it using
from googletrans import Translator.
- Open Command Prompt and check for the availability of Anaconda and pip by typing
pipone by one. If it throws no error then everything is working fine.
- The next step is to create a virtual environment in Anaconda where you will be storing the Google Translate API. For this, you can do
conda create –n yourenvname.
- Once the environment is created just type
yourenvnameand the environment will be activated and usable.
- Now just do
pip install googletransand wait for the download to finish.
- Now open your code IDE and type
from googletrans import Translatorand this will import the translator API for you.
The working steps are depicted using pictorial representations to give you a better idea of how to use the same for your purpose.
#!pip install googletrans
from googletrans import Translator
translated= translator.translate(sentence, dest="ta", src"en") tranlated.text
So, this is how one can use this Google Translate API to translate the language of their databases and then use it for their working purpose.