3 ways to do language translation in Python

Hi guys, in this article I’m going to share with you 3 common ways to do language translation in python using goslate,googletrans , and in python.
what will you build?
At the end of this article you will have a good grasp of language translation and how can you do it in python using its libraries.
Python-based libraries for language translation
There are several libraries in Python for performing language translation, below are some of those libraries but almost all of them are using Google Translate API.
Just check them out in detail and choose which one you like the most to use in your personal projects involving language translation.
Translating with goslate
goslate provides you free python API to google translation service by querying the google translation website.
Installation
$ pip install goslate
goslate will automatically detect your primary language of the text and then translate it to the secondary language you specify.
During specifying language you use ISO 639–1 code you can find them here
Example of Usage (gos.py)]
>>>import goslate
>>>primary_text = 'Love you a lot '
>>>gs = goslate.Goslate()
>>>gs.translate(primary_text, 'fr')
"Je t'aime beaucoup"
googletrans
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
Installation
$ pip install googletrans
For instance, Let’s translate “This site is awesome “ to the Swahili language, also here language is represented in ISO 639–1
Example of Usage
>>> text = 'This site is awesome'
>>> from googletrans import Translator
>>> translator = Translator()
>>> translator.translate(text , dest ='sw').text
'Tovuti hii ni ajabu'
TextBlob
TextBlob is a Python (2 and 3) library for processing textual data. It provides a simple API for diving into common natural language processing (NLP) tasks such as part-of-speech tagging, noun phrase extraction, sentiment analysis, classification, translation, and more
Installation
$ pip install -U textblob
$ python -m textblob.download_corpora
Example of Usage
>>> from textblob import TextBlob
>>> blob = TextBlob('comment ca va ?')
>>> blob.translate(to='en')
TextBlob("How is it going ?")
I hope you find this tutorial interesting, don’t forget to subscribe to stay updated on the upcoming Python tutorial.
I also recommend you to read this;
- Emotion detection from the text in Python
- 3 ways to convert speech to text in Python
- How to perform speech recognition in Python
- Make your own Plagiarism detector in Python
- Learn how to build your own spam filter in Python
- Make your own knowledge-based chatbot in Python
- How to perform automatic spelling correction in Python
In case of anything drop it in the comment box below, I will get back to you ASAP.
Originally published at https://kalebujordan.com on May 13, 2020.