Sha256: 64d584598a336884ac3ec4731fe791873be74c9f16ad998b09c166225cb8264e

Contents?: true

Size: 1.39 KB

Versions: 17

Compression:

Stored size: 1.39 KB

Contents

# Description: Update translated tweet to (other|same) account when you're update
# Author: Sora Harakami

require 'open-uri'
require 'json'
require 'cgi'

def translate_by_google(text,o={})
  opt = {:from => "",:to => "en"}.merge(o)
  j = JSON.parse(open(
    "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=" \
   +"#{CGI.escape(text)}&langpair=#{CGI.escape("#{opt[:from]}|#{opt[:to]}")}").read)
  j["responseData"]["translatedText"] rescue nil
end

config.plugins.translate_tweet.set_default(:to,"en")
config.plugins.translate_tweet.set_default(:user_name,nil)
config.plugins.translate_tweet.set_default(:password,nil)
config.plugins.translate_tweet.set_default(:header,"")
config.plugins.translate_tweet.set_default(:footer,"")

Termtter::Client.register_hook(
  :name  => :translate_tweet,
  :point => :post_exec_update,
  :exec  => lambda do |cmd,t,result|
    tw = (config.plugins.translate_tweet.user_name.nil? || \
         config.plugins.translate_tweet.password.nil?) ?  \
           Termtter::API.twitter : \
           Rubytter.new(config.plugins.translate_tweet.user_name,  \
                        config.plugins.translate_tweet.password)
    tt = config.plugins.translate_tweet.header + \
         translate_by_google( \
           t,:to => config.plugins.translate_tweet.to) + \
         config.plugins.translate_tweet.footer
    tw.update(tt)
    puts "translated => #{tt}"
  end
)

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
termtter-2.2.9 lib/plugins/translate_tweet.rb
termtter-2.2.8 lib/plugins/translate_tweet.rb
termtter-2.2.6 lib/plugins/translate_tweet.rb
termtter-2.2.3 lib/plugins/translate_tweet.rb
termtter-2.2.2 lib/plugins/translate_tweet.rb
termtter-2.2.1 lib/plugins/translate_tweet.rb
termtter-2.2.0 lib/plugins/translate_tweet.rb
termtter-2.1.1 lib/plugins/translate_tweet.rb
termtter-2.1.0 lib/plugins/translate_tweet.rb
termtter-2.0.0 lib/plugins/translate_tweet.rb
termtter-1.11.0 lib/plugins/translate_tweet.rb
termtter-1.10.3 lib/plugins/translate_tweet.rb
termtter-1.10.2 lib/plugins/translate_tweet.rb
termtter-1.10.1 lib/plugins/translate_tweet.rb
termtter-1.10.0 lib/plugins/translate_tweet.rb
termtter-1.9.0 lib/plugins/translate_tweet.rb
termtter-1.8.0 lib/plugins/translate_tweet.rb