@rule(u'$nickname[,:]\\s+(?:([a-z]{2}) +)?(?:([a-z]{2}|en-raw) +)?["\u201c](.+?)["\u201d]\\? *$')
@example(u'$nickname: "mon chien"? or $nickname: fr "mon chien"?')
@priority(u'low')
def tr(bot, trigger):
 (in_lang, out_lang, phrase) = trigger.groups()
 if ((len(phrase) > 350) and (not trigger.admin)):
  return bot.reply(u'Phrase must be under 350 characters.')
 if (phrase.strip() == u''):
  return bot.reply(u'You need to specify a string for me to translate!')
 in_lang = (in_lang or u'auto')
 out_lang = (out_lang or u'en')
 if (in_lang != out_lang):
  (msg, in_lang) = translate(phrase, in_lang, out_lang, verify_ssl=bot.config.core.verify_ssl)
  if ((sys.version_info.major < 3) and isinstance(msg, str)):
   msg = msg.decode(u'utf-8')
  if msg:
   msg = web.decode(msg)
   msg = (u'"%s" (%s to %s, translate.google.com)' % (msg, in_lang, out_lang))
  else:
   msg = (u'The %s to %s translation failed, are you sure you specified valid language abbreviations?' % (in_lang, out_lang))
  bot.reply(msg)
 else:
  bot.reply(u'Language guessing failed, so try suggesting one!')

@ rule ( u'$nickname[,:]\\s+(?:([a-z]{2}) +)?(?:([a-z]{2}|en-raw) +)?["\u201c](.+?)["\u201d]\\? *$' ) @ example ( u'$nickname: "mon chien"? or $nickname: fr "mon chien"?' ) @ priority ( u'low' ) def tr ( bot , trigger ) : ( in_lang , out_lang , phrase ) = trigger . groups ( ) if ( ( len ( phrase ) > 350 ) and ( not trigger . admin ) ) : return bot . reply ( u'Phrase must be under 350 characters.' ) if ( phrase . strip ( ) == u'' ) : return bot . reply ( u'You need to specify a string for me to translate!' ) in_lang = ( in_lang or u'auto' ) out_lang = ( out_lang or u'en' ) if ( in_lang != out_lang ) : ( msg , in_lang ) = translate ( phrase , in_lang , out_lang , verify_ssl = bot . config . core . verify_ssl ) if ( ( sys . version_info . major < 3 ) and isinstance ( msg , str ) ) : msg = msg . decode ( u'utf-8' ) if msg : msg = web . decode ( msg ) msg = ( u'"%s" (%s to %s, translate.google.com)' % ( msg , in_lang , out_lang ) ) else : msg = ( u'The %s to %s translation failed, are you sure you specified valid language abbreviations?' % ( in_lang , out_lang ) ) bot . reply ( msg ) else : bot . reply ( u'Language guessing failed, so try suggesting one!' )
translates a phrase .