Tamil word translated into available Google Translate languages
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
# -*- coding: utf-8 -*- | |
# (C) 2018 Muthiah Annamalai <ezhillang@gmail.com> | |
# This code is shared under public domain. | |
from google.cloud import translate | |
import tamil | |
import codecs | |
import json | |
import sys | |
def get_translated_words(wrd,tgtLang,client): | |
if tgtLang == 'ta': | |
return wrd | |
en_wrd20 = client.translate(wrd,source_language='ta',target_language=tgtLang) | |
return en_wrd20['translatedText'] | |
def run(): | |
c = translate.Client() | |
data = {} | |
lmap = c.get_languages() | |
for lang in lmap: | |
lcode = lang['language'] | |
lname = lang['name'] | |
data[lname] = [get_translated_words(u"தமிழ்",lcode,c),lcode] | |
for lcode,word in data.items(): | |
print(u"%s %s <%s>"%(word[0],word[1],lcode)) | |
with codecs.open('tamil_2languages.json','w','utf-8') as fp: | |
fp.write( json.dumps( data ) ) | |
if __name__ == u"__main__": | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment