Skip to content

Instantly share code, notes, and snippets.

@ohidurbappy
Created March 30, 2020 04:19
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 ohidurbappy/eedac5c9b2cfffb2ce74842b265fb614 to your computer and use it in GitHub Desktop.
Save ohidurbappy/eedac5c9b2cfffb2ce74842b265fb614 to your computer and use it in GitHub Desktop.
Google Translate API with python
from googletrans import Translator
translator = Translator()
# use this code for local translator service
# translator = Translator(service_urls=[
# 'translate.google.com',
# 'translate.google.co.kr',
# ])
# open the file 'google_translate_input.txt' and read line by line
fi=open('google_translate_input.txt','r',encoding='utf-8')
inputList=[line.rstrip('\n') for line in fi]
trans=translator.translate(inputList,dest='bn')
output=''
for tran in trans:
print(tran.origin+'->'+tran.text)
output+=tran.origin+'\n:'+tran.text+'\n\n'
f=open('google_translate_output.txt','w',encoding='utf-8')
f.write(output)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment