def translate(text, target_lang='<STR_LIT>', source_lang=None):
url_base = '<STR_LIT>'<EOL>params = dict(<EOL>key=translate.API_key,<EOL>q=text,<EOL>target=target_lang,<EOL>)<EOL>if source_lang:<EOL><INDENT>params['<STR_LIT:source>'] = source_lang<EOL><DEDENT>resp = requests.get(url_base, params=params)<EOL>resp.raise_for_status()<EOL>return resp.json()['<STR_LIT:data>']['<STR_LIT>'][<NUM_LIT:0>]['<STR_LIT>']<EOL>
Use the Google v2 API to translate the text. You had better have set
the API key on this function before calling it.