summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaine Virta <rane@kapsi.fi>2009-04-30 00:47:12 +0300
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2009-04-30 13:46:49 +0200
commitcdbaaee4b94473dac0f3284d66e971ae70f276b7 (patch)
treebcdcc54204e3c2bb62f236b42d7abc73429f9fd8
parent88b3cb20e4aa317cba5ea419a8d77833e76da36c (diff)
translator: make source language optional
In which case we use Google translate's source language auto-detection feature.
-rw-r--r--data/rbot/plugins/translator.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/data/rbot/plugins/translator.rb b/data/rbot/plugins/translator.rb
index a046b206..4354fdc5 100644
--- a/data/rbot/plugins/translator.rb
+++ b/data/rbot/plugins/translator.rb
@@ -325,7 +325,15 @@ class TranslatorPlugin < Plugin
def cmd_translator(m, params)
params[:to] = @bot.config['translator.destination'] if params[:to].nil?
- translator = @default_translators.find {|t| @translators[t].support?(params[:from], params[:to])}
+ # Use google translate as translator if source language has not been given
+ # and auto-detect it
+ if params[:from].nil?
+ params[:from] = "auto"
+ translator = "google_translate"
+ else
+ translator = @default_translators.find {|t| @translators[t].support?(params[:from], params[:to])}
+ end
+
if translator
cmd_translate m, params.merge({:translator => translator, :show_provider => true})
else
@@ -366,5 +374,5 @@ class TranslatorPlugin < Plugin
end
plugin = TranslatorPlugin.new
-plugin.map 'translator :from [:to] *phrase',
+plugin.map 'translator [:from] [:to] *phrase',
:action => :cmd_translator, :thread => true