Skip to content

Instantly share code, notes, and snippets.

@karronoli
Last active May 16, 2016 16:39
Show Gist options
  • Save karronoli/6307673927df7082544aa12117bcb224 to your computer and use it in GitHub Desktop.
Save karronoli/6307673927df7082544aa12117bcb224 to your computer and use it in GitHub Desktop.
The interface of "https://translate.google.com/" by MozRepl.
(require 'comint)
(require 'url-util)
(require 'moz)
(defun translate-google (&optional flag)
(interactive "P")
(let ((lang (if (null flag) "en/ja" "ja/en"))
(text
(let ((end (if (use-region-p) (region-end)
(forward-word) (point)))
(start (if (use-region-p) (region-beginning)
(backward-word) (point))))
(buffer-substring start end))))
(comint-send-string
(inferior-moz-process)
(format
"content.location.href = \"https://translate.google.com/#%s/%s\""
lang
(url-hexify-string text)))))
(global-set-key "\C-x\C-t" 'translate-google)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment