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.
$ pip install goslate
goslate will automatically detect your primary language of text and then translate it to secondary language you specify.
During specifying language you use ISO 639-1 codes 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"
$ pip install 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.
For instance Let’s translate “This site is awesome ” to 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'
$ pip install -U textblob $ python -m textblob.download_corpora
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.
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 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.