summaryrefslogtreecommitdiff
path: root/data/rbot/plugins/translator.rb
diff options
context:
space:
mode:
authorRaine Virta <rane@kapsi.fi>2010-09-18 11:25:27 +0300
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2010-09-23 15:05:28 +0200
commitb218f003e2625c2b9ebc9de39886fb2f54d68aa0 (patch)
tree770d653234878043108042924b0ff82c56acec0c /data/rbot/plugins/translator.rb
parenteec6a651aa70f124e05fb3e7b7fabb5a1b3bd6b4 (diff)
translator: url translation through google
Diffstat (limited to 'data/rbot/plugins/translator.rb')
-rw-r--r--data/rbot/plugins/translator.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/data/rbot/plugins/translator.rb b/data/rbot/plugins/translator.rb
index 66b70cee..c4eaac4f 100644
--- a/data/rbot/plugins/translator.rb
+++ b/data/rbot/plugins/translator.rb
@@ -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?://.*})
+plugin.map 'translator [:from] [:to] *url',
+ :action => :cmd_translate_url, :requirements => req.merge(:url => %r{^https?://.*})
plugin.map 'translate [:from] [:to] *phrase',
:action => :cmd_translator, :thread => true, :requirements => req
plugin.map 'translator [:from] [:to] *phrase',