3 ways to do language translation in Python

Kalebu Jordan
2 min readMay 13, 2020

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;

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.

Sign up to discover human stories that deepen your understanding of the world.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Kalebu Jordan
Kalebu Jordan

Written by Kalebu Jordan

Mechatronics Engineer by Professional || Self taught Python Developer || Passionate about open source and bringing impact to education sector

No responses yet

Write a response