自动翻译 emacs-china.org

我的中文够烂 (GitHub - dickmao/nndiscourse: A Gnus backend for Discourse).

autotranslate

(defun translate-emacs-china ()
  (when (equal (gnus-method-to-server-name
                (gnus-find-method-for-group gnus-newsgroup-name))
               (gnus-method-to-server-name '(nndiscourse "emacs-china.org")))
    (require 'google-translate)
    (with-current-buffer gnus-article-buffer
      (save-mark-and-excursion
        (article-goto-body)
        (cl-destructuring-bind (beg . end)
            (last (mapcar #'car (save-excursion (gnus-dissect-cited-text))) 2)
          (let ((inhibit-read-only t)
                kill-ring)
            (delete-region (point) beg)
            (save-excursion
              (set-mark (point))
              (goto-char (or (car end) (point-max)))
              (setq deactivate-mark nil)
              (let (google-translate-pop-up-buffer-set-focus
                    google-translate-show-phonetic
                    google-translate-display-translation-phonetic
                    (google-translate-output-destination 'paragraph-insert))
                (save-excursion
                  (with-silent-modifications
                    (google-translate-at-point))))
              (kill-region (point) (point-max)))
            (forward-line -1)
            (yank)))))))

(add-hook 'gnus-article-prepare-hook #'translate-emacs-china)
5 个赞