How To Google Translate With Python?
1 min readJan 5, 2020
Before we translate the text, please install googletrans withpip 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.