DEV Community

Wulfi
Wulfi

Posted on

Build a language translator in just 3 lines using googletrans API

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. Link

We can use Free Google Translate API in Python, which is a free of charge translator. Link

We need to install the API:

$ pip install googletrans
Enter fullscreen mode Exit fullscreen mode

Let us try to translate "Hello" to Japanese, simply say:

from googletrans import Translator
translator = Translator()
result = translator.translate("Hello", dest="ja")

print(result)
Enter fullscreen mode Exit fullscreen mode

In the above, we can specify any language code for 'dest' value. Get the supported language codes from the documentation

Discussion (1)

Collapse
jonrandy profile image
Jon Randy

Your post title is misleading. You're importing and using a library that makes use of Google's translation service. This is pretty far removed from building a language translator.

'Just 3 lines' is also misleading since the code in googletrans probably runs to many, many lines.