@pmxbot.core.command(<EOL>"<STR_LIT>",<EOL>aliases=('<STR_LIT>', '<STR_LIT>', '<STR_LIT>'))<EOL>def translate(client, event, channel, nick, rest):
try:<EOL><INDENT>set_key()<EOL><DEDENT>except Exception:<EOL><INDENT>return (<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>rest = rest.strip()<EOL>langpair, _, rest = rest.partition('<STR_LIT:U+0020>')<EOL>source_lang, _, target_lang = langpair.rpartition('<STR_LIT:|>')<EOL>try:<EOL><INDENT>return google.translate(rest.encode('<STR_LIT:utf-8>'), target_lang, source_lang)<EOL><DEDENT>except Exception:<EOL><INDENT>log.exception("<STR_LIT>")<EOL>tmpl = (<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL>return tmpl.format(**vars())<EOL><DEDENT>
Translate a phrase using Google Translate. First argument should be
the language[s]. It is a 2 letter abbreviation. It will auto detect
the orig lang if you only give one; or two languages joined by a |,
for example 'en|de' to trans from English to German. Follow this by
the phrase you want to translate.