X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Ftranslator.rb;h=933969a1a7f1aa62ffb388fefcf41f5a96443309;hb=052217de30c59206d7025b582d4604557a747470;hp=66b70cee13163712024e5777970ef63265a45de3;hpb=9eef522553cb2de99388948dedf0cf5d698b635a;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/translator.rb b/data/rbot/plugins/translator.rb index 66b70cee..933969a1 100644 --- a/data/rbot/plugins/translator.rb +++ b/data/rbot/plugins/translator.rb @@ -382,7 +382,7 @@ class TranslatorPlugin < Plugin translator = @default_translators.find {|t| @translators[t].support?(params[:from], params[:to])} if translator - cmd_translate m, params.merge({:translator => translator, :show_provider => true}) + cmd_translate m, params.merge({:translator => translator, :show_provider => false}) else # When translate command is used without source language, "auto" as source # language is assumed. It means that google translator is used and we let google @@ -433,11 +433,30 @@ class TranslatorPlugin < Plugin m.reply _('No translator called %{name}') % {:name => tname} end end + + # URL translation has nothing to do with Translators so let's make it + # separate, and Google exclusive for now + def cmd_translate_url(m, params) + params[:to] = @bot.config['translator.destination'] if params[:to].nil? + params[:from] ||= 'auto' + + translate_url = "http://translate.google.com/translate?sl=%{from}&tl=%{to}&u=%{url}" % { + :from => params[:from], + :to => params[:to], + :url => CGI.escape(params[:url].to_s) + } + + m.reply(translate_url) + end end plugin = TranslatorPlugin.new req = Hash[*%w(from to).map { |e| [e.to_sym, /#{plugin.languages.join("|")}/] }.flatten] +plugin.map 'translate [:from] [:to] :url', + :action => :cmd_translate_url, :requirements => req.merge(:url => %r{^https?://[^\s]*}) +plugin.map 'translator [:from] [:to] :url', + :action => :cmd_translate_url, :requirements => req.merge(:url => %r{^https?://[^\s]*}) plugin.map 'translate [:from] [:to] *phrase', :action => :cmd_translator, :thread => true, :requirements => req plugin.map 'translator [:from] [:to] *phrase',