If prefix the call to the translate function than store the translation as an org item.
(require 'babel)
(defvar rgr/learn-first-lesson 1)
(defvar rgr/orig-text "The text we wish to translate")
(defvar rgr/trans-text "The translated text")
(setq babel-echo-area t)
(setq babel-preferred-from-language "English")
(setq babel-preferred-to-language "German")
(defun rgr/babel-language-code (lang)
(cdr (assoc lang babel-languages)))
(defun rgr/translate( &optional usedef )
(interactive)
(let* ((default (region-or-word-at-point)))
(setq default
(read-string (format "Translate \"%s\" :" default) nil nil default))
(when (length default)
(setq rgr/trans-text (babel default nil usedef))
(setq rgr/orig-text default)
(if current-prefix-arg
(progn
(org-capture nil ?v)
(org-schedule nil (time-add (current-time) (days-to-time rgr/learn-first-lesson)))))
(rgr/notify rgr/trans-text) ;; calls gnome notify function or whatever.
(message "%s" rgr/trans-text))))
(defun rgr/toggle-languages()
(interactive)
(let* ((temp babel-preferred-to-language))
(setq babel-preferred-to-language babel-preferred-from-language
babel-preferred-from-language temp))
(message "%s to %s " babel-preferred-from-language babel-preferred-to-language))
(global-set-key (kbd "<f5>")
(lambda()
(interactive)(require 'babel)(rgr/translate t)))
(global-set-key (kbd "<f6>")
'rgr/toggle-languages)
No comments:
Post a Comment