bin/translate in google-translate-0.8.5 vs bin/translate in google-translate-0.8.6

- old
+ new

@@ -1,10 +1,10 @@ #!/usr/bin/env ruby $:.unshift(File::join(File::dirname(File::dirname(__FILE__)), "lib")) -require 'rubygems' unless RUBY_VERSION =~ /1.9.*/ +require 'rubygems' unless defined?(Gem) require 'google_translate' #$KCODE='u' class Translate @@ -15,11 +15,11 @@ translate en:ru "hello world" - translates from en to ru translate ru "hello world" - translated from auto-detected language to ru TEXT def initialize - @translator = Google::Translator.new + @translator = GoogleTranslate.new end def print_languages list, title puts title puts list.join(', ') @@ -57,30 +57,26 @@ when 'list' then hash = @translator.supported_languages print_languages hash[:from_languages], "From Languages:" print_languages hash[:to_languages], "To Languages:" - #when 'detect' then - # language = @translator.detect_language(ARGV.shift) - # - # puts "Language: #{language.inspect}" when /(.*):(.*)/ then from_text = ARGV.join(' ') from = $1 to = $2 display(@translator.translate(from.to_sym, to.to_sym, from_text)) - #when /(.*)/ then - # from_text = ARGV.join(' ') - # - # from = @translator.detect_language(from_text)['language'] - # to = $1 - # - # begin - # display(@translator.translate(from.to_sym, to.to_sym, from_text)) - # rescue Exception => e - # puts "Error: " + e.message - # end + when /(.*)/ then + from_text = ARGV.join(' ') + + from = "auto" + to = $1 + + begin + display(@translator.translate(from.to_sym, to.to_sym, from_text)) + rescue Exception => e + puts "Error: " + e.message + end end end end Translate.new.run