How To Google Translate With Python?

Before we translate the text, please install googletrans with
pip install googletrans

Translate Any Language to English

from googletrans import Translator
translator = Translator()
print(translator.translate('星期日').text)

// on Sunday

Translate English to Chinese

from googletrans import Translator
translator = Translator()
print(translator.translate('Sunday', dest='zh-tw').text)

// 星期日

Translate Chinese(zh-cn) to Chinese(zh-tw)

from googletrans import Translator
translator = Translator()
print(translator.translate('作业时间', dest='zh-tw').text)

Detect the Language

from googletrans import Translator
translator = Translator()
print(translator.detect('일요일'))

// Detected(lang=ko, confidence=1)

Note on library usage

DISCLAIMER: this is an unofficial library using the web API of translate.google.com and also is not associated with Google.

  • The maximum character limit on a single text is 15k.
  • Due to limitations of the web version of google translate, this API does not guarantee that the library would work properly at all times (so please use this library if you don’t care about stability).
  • Important: If you want to use a stable API, I highly recommend you to use Google’s official translate API.
  • If you get HTTP 5xx error or errors like #6, it’s probably because Google has banned your client IP address.

Written by

Machine Learning / Deep Learning / Python / Flutter cakeresume.com/yanwei-liu

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store