Skip to content

Instantly share code, notes, and snippets.

@e96031413
Created January 5, 2020 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e96031413/1eac62cd26a0899ce0994653e2aec209 to your computer and use it in GitHub Desktop.
Save e96031413/1eac62cd26a0899ce0994653e2aec209 to your computer and use it in GitHub Desktop.
Use Python to Google Translate
#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.
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment