Skip to content

Instantly share code, notes, and snippets.

@zmwangx
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zmwangx/b27f106a8ba47468a43d to your computer and use it in GitHub Desktop.
Save zmwangx/b27f106a8ba47468a43d to your computer and use it in GitHub Desktop.
Google Translate.dzbundle for Dropzone 3.
# Dropzone Action Info
# Name: Google Translate
# Description: Translate dropped text.
# Handles: Files, Text
# Creator: Zhiming Wang
# URL: https://github.com/zmwangx
# Events: Clicked, Dragged
# KeyModifiers: Command, Option, Control, Shift
# SkipConfig: No
# RunsSandboxed: Yes
# Version: 1.0
# MinDropzoneVersion: 3.0
# RubyPath: /usr/local/bin/ruby
def set_env
ENV['LANG'] = 'en_US.UTF-8'
ENV['PATH'] = '/usr/local/bin:' + ENV['PATH']
end
def dragged
set_env
case ENV['dragged_type']
when 'text'
original = $items[0]
when 'files'
original = ""
$items.each {|path| original += File.basename(path).encode("UTF-8", "UTF8-MAC") + "\n"}
end
translation = `trans -b "#{original}"`
$dz.alert("Google Translate", "original:\n#{original}\n\ntranslation:\n#{translation}")
end
def clicked
set_env
original = `pbpaste`
translation = `trans -b "#{original}"`
$dz.alert("Google Translate", "original:\n#{original}\n\ntranslation:\n#{translation}")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment