#NEWLINE# def google_translate( text , sourceLang , destLang ) : #NEWLINE# #INDENT# if ( not app . debug ) : #NEWLINE# #INDENT# return gettext ( 'Error: translation service not available.' ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# params = urlencode ( { #NEWLINE# #INDENT# 'client' : 't' , #NEWLINE# 'text' : text . encode ( 'utf-8' ) , #NEWLINE# 'sl' : sourceLang , #NEWLINE# 'tl' : params , #NEWLINE# 'ie' : 'UTF-8' , #NEWLINE# 'oe' : 'UTF-8' , #NEWLINE# #UNINDENT# } ) #NEWLINE# conn = httplib . HTTPSConnection ( 'translate.google.com' ) #NEWLINE# conn . request ( 'GET' , ( '/translate_a/t?' + params ) , headers = { #NEWLINE# #INDENT# 'User-Agent' : 'Mozilla/5.0' , #NEWLINE# #UNINDENT# } ) #NEWLINE# httpresponse = conn . getresponse ( ) . read ( ) . replace ( ',,,' , ',"","",' ) . replace ( ',,' , ',"",' ) #NEWLINE# response = json . loads ( ( ( '{"response":' + httpresponse ) + '}' ) ) #NEWLINE# return response [ 'response' ] [ 0 ] [ 0 ] [ 0 ] #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# return gettext ( 'Error: Unexpected error.' )