From cdbaaee4b94473dac0f3284d66e971ae70f276b7 Mon Sep 17 00:00:00 2001 From: Raine Virta Date: Thu, 30 Apr 2009 00:47:12 +0300 Subject: translator: make source language optional In which case we use Google translate's source language auto-detection feature. --- data/rbot/plugins/translator.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'data') 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 -- cgit v1.2.3