Created
March 30, 2020 04:19
-
-
Save ohidurbappy/eedac5c9b2cfffb2ce74842b265fb614 to your computer and use it in GitHub Desktop.
Google Translate API with python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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