condy0919 / fanyi.el

Not only English-Chinese translator for Emacs.
GNU General Public License v3.0
79 stars 7 forks source link

建议增加一个本地词典查询 #29

Open heisaari opened 2 years ago

heisaari commented 2 years ago

为了加快查询速度(在线查结果总是要等一下才能出来) 建议结合https://github.com/skywind3000/ECDICT 增加一个本地简明英汉的查询结果,这样不仅速度快,断网的时候也能用

kimim commented 1 year ago

Hello, I combined the power of sdcv with fanyi.el:

  (require 'sdcv)
  (defun kimim/sdcv-translate-result-advice (word dictionary-list)
    (let* ((arguments
            (cons word
                  (mapcan
                   (lambda (d) (list "-u" d)) dictionary-list)))
         (result (mapconcat
                  (lambda (result)
                    (let-alist result
                      (format
                       "## %s\n%s\n\n" .dict .definition)))
                  (apply #'sdcv-call-process arguments)
                  "")))
    (if (string-empty-p result)
        sdcv-fail-notify-string
      result)))

  (advice-add 'sdcv-translate-result
              :override
              #'kimim/sdcv-translate-result-advice)

  (defun kimim/fanyi-dwim-add-sdcv (word)
    (let ((buf (get-buffer fanyi-buffer-name)))
    (with-current-buffer buf
      (let ((inhibit-read-only t)
            (inhibit-point-motion-hooks t))
        ;; Clear the previous search result.
        (point-max)
        (insert "# SDCV\n\n")
        (insert
         (sdcv-search-with-dictionary
          word sdcv-dictionary-complete-list))
        (insert "\n\n")
        (beginning-of-buffer)))))

  (advice-add 'fanyi-dwim :after
              #'kimim/fanyi-dwim-add-sdcv)
condy0919 commented 1 year ago

我在 emacs-china 上看到你发的帖子了!