We can use a language translator to translate text from one language to another. There are various APIs and modules for this, we’ll use the Google Translate API. We will use the Goslate module to create a language translator in python.
Video Tutorial for Translating language to other languages in python
Goslate – Google’s Language Translator API for Python
Goslate is a google API module for Python that is used to translate languages in Python. It also Supports language detection, batch translation, dictionary lookup and more. in this Post We will see how to use goslate to create language translator in python.
It is
- Free: get translation through public google web site without fee
- Fast: batch, cache and concurrently fetch
- Simple: single file module, just Goslate().translate(‘Hi!’, ‘zh’)
Installation
Run pip command in your cmd/terminal/anaconda prompt to install goslate-google translate API.
pip install goslate
Code
import goslate
text = input()
gs = goslate.Goslate()
result = gs.translate(text,'ur')
print(result)
Input:
Hello World
Output:
ہیلو دنیا
translate method accepts 2 parameters, first is input text that we want to translate to other language, and second is target language in which we want our text to be converted. gaslate auto detects language of input text and translates it to given language as output. We need to give 2 character language code for conversion. e.g here i have give ‘ur’ for urdu (Pakistan) language.
You May Also Like
Text to Speech using Python
Speech to Text using Python